Django hstore and south

If someone has a more elegant way , feel free to send me a message, thanks.

1. pip install djorm-ext-hstore

2. Import the following in your models.py file:

from djorm_hstore.fields import DictionaryField
from djorm_hstore.models import HStoreManager

3. Modify your model as such:

data = DictionaryField(db_index=True,default='')
objects = HStoreManager()

4.  Run south:

python manage.py  schemamigration YOURAPP –auto

python manage.py migrate YOURAPP

5. Modify column null field in your database:

ALTER TABLE test alter column features set DEFAULT hstore(array[]::varchar[]); 

* alter table solution was picked up from stackoverflow, credits to the user for posting it.

 

 

Django CheckBoxSelectMultiple multiple columns filter

Simple filter written for my needs to return multiple column html ouput, filter is used like so:

{% autoescape off %}

{{field.field.choices|checkboxcolumns:”3″}}

{% endautoescape %}

 

Replace the html content with your own, this was specific for my project:

checkboxcolumn

 

 

 

 

Linux 3.8.2 hangs hibernation

Just wanted to put this out there, seems like there is a bug in the 3.8.2 kernel.  System hangs randomly after waking up from hibernation, there is no set time as to when it hangs but I have to hard boot it to run the system again.

Command: echo -n “mem” > /sys/power/state

Hopefully this gets resolved in the next stable kernel release, apparently it is in the current 3.9 rc as well.

 

Django form custom error messages

Rather simple setup to modify default form error messages with custom ones, I use a base form class which I use in all my forms.  This is for post related errors, for client side js errors I have another function which I call that prints out all the necessary js code as a string which I call from the template.

 

 

 

Nginx not logging

Had to fix a small Freebsd vm today or patch rather, it seems nginx was not logging properly or logging at all.

1. Reconfigure nginx without syslog.

2. Make sure your log paths are proper and have the correct permissions.

3. error_log /var/log/nginx/error.log info; <— make sure you imply what type of logging detail you want at the end.

 

That should be it, other apparent issues will most likely pop up when you start nginx.

Django form validation with jquery validate

I’ve been waiting to write this up for quite some time, now due to a high number forms I have to write in the near future the wait was over.   I was pretty tired of specifying form constraints on both the server and client side, ie max_length , min , etc etc.   The solution was rather simple first create a base class with a wrapper placed in __init__ as shown below:

This loops over the form fields and specifies the validation rules along with the messages.  I made an extra dictionary to store the messages , it seemed easier this way when looping over them in the template instead of using field.error_messages.  Disregard the get_error_tags method thats just for myself , you can use any message you’d like.

 

Continue reading

Slackware current and ati woessssss (why didnt i buy nvidia)

Update 06/30/2012:  Ati released new drivers that work fine with current , I will leave the post below for future reference.

 

As we all know Linux support with ati = 0, anyhow if you are in the same boat as myself and have upgrade to the latest Slackware x server updated on 5-07-2012.  You are most likely stuck with a black screen, first things first the current proprietary ati does NOT work with current x server.  So before you start wailing your fists in the air, there is a nice write up in Indonesian that fixes the issue at http://www.walecha.net/content/mengembalikan-konfigurasi-driver-opensource-ati-radeon , unfortunately there are typos and unclear steps, which I will describe below, feel free to thank the original author.

 

First you will need to uninstall the proprietary ati package, after that run X without any xorg.conf.  Now reinstall the proprietary package , you will need some of the libs to do the following:

Note change lib64 with lib , if you are on a 32 bit system, now to the steps:

1. aticonfig –initial

2. cd /usr/lib64/fglrx ; cp fglrx-libGL.so.1.2  fglrx-libGL.so.1.2.backup

3. cd /usr/lib64/fglrx# cd /usr/lib64/xorg/modules/extensions/fglrx/ ; cp fglrx-libglx.so fglrx-libglx.so.backup

4. Now uninstall the ati package.

5. cd /usr/lib64/ ; rm libGL.so* ; cp fglrx/fglrx-libGL.so.1.2.backup libGL.so.1.2 ; ln -s libGL.so.1.2 libGL.so.1 ; ln -s libGL.so.1.2 libGL.so

6. cd /usr/lib64/xorg/modules/extensions ; rm libglx.so ; cp fglrx/fglrx-libglx.so.backup libglx.so

7. update xorg.conf to use radeon driver instead of fglrx.

 

 

 

 

 

 

Freebsd 7.4 ezjail create fail

It seems ezjail version 3.2.1_1 on Freebsd 7.4 has a small bug with creating new jails, I filed a bug already but if you are getting the following error:

jls -n illegal option

 

Edit /usr/local/bin/ezjail-admin with your editor and edit lines 730 & 731 , change jls -n from jls -a , done.

From core i7 860 to core i5 2500k to core i7 2700k to amd fx 8120 all in 1 week wth ?

Ok so it has been awhile since I updated my desktop, I remember purchasing my core i7 860 system back in 2010 ..i think. Anyhow I stayed out of the loop just saw the usual new chip , new this or that released but never really paid attention to it because I was more than content with my current setup. Then came ssd drives and sata 3 speeds were just begging me to try them, me being a big speed freak I couldn’t resist. I ebay’d my system which went for a really high price, which I thought was odd at the beginning only later to realize why. I assumed 2+ years is more than enough time for technology to be 10x faster than my current setup. I mean we did that back in the Pentium/K6 days, knowing that if you upgraded after 2 years the old system would be faaaaaaaaaar behind current technological performance capabilities. Well as I started down this road , I soon found out I was quite wrong.

First system I got was an i5 2500k, i7 seemed a bit pricey and there was a great deal for an i5 2500k with motherboard being sold for $400 out the door, So I said why not. After running it for a week, I felt a sad taste in my mouth, a taste known as regret. Because at this current point that i5 was not too far away from my 860 and sometimes in some tasks it was rather slow. Aside from the usual gaming once a week, I mainly use my desktop for developing on linux and indexing search engines and basic compiles seemed a bit slower due to the lack of threads. So I did the next logical thing, I went and replaced the i5 with an i7 2700k. Spending a $100 dollars more and walking away wondering how did this turn into a $500 dollar fiasco but who cares lets fly. Ran home to setup the system , overclocked it on air at 4.8 with no heat issues. The system was flying but not really flying you know what I mean. Kinda like yeah its fast but was it worth blowing $500 dollars to get that extra 17% percent faster feel …yeah that type. Plus getting vcore warnings from the board wasn’t a nice feeling, I mean come on whats the point.

After deciding to dump everything and wait for Ivy bridge, I was curious and said to myself I went for the hot girl and she wasn’t all that..why not try her ugly friend everyone keeps walking away from. I mean I’ve gone through hell already why not try all the flavors so I purchased a 8120 along with sabertooth am3+ 990fx board. Ah amd the apple of my eye back in the days and somehow I wish I would have left you in memory lane, you guys truly failed this time. I can see this chip being great if the price was less than an i5 but it should not be priced at the same price as an i5, thats just madness. I’ve run almost all my process from A-Z on linux and windows and this thing by far sucks compared to the i5, even the extra cores do not help this thing. The temperature is rather ridiculous with a stock cooler, if you have this chip use an after market cooler. I would recommend this chip if it was worth $120-$140, aside from that no thanks and just maybe AMD might be smart enough to do that around ivy’s release. So ebay it is!, I put up the system and sold it for the exact price I got it for. Now I patiently wait for Ivy bridge to come out and finally picking a cpu setup that wont have me feeling like I got ripped off. Amd needs to get its act together and stop smoking whatever they are in r&d. Intel needs to get checked they have 2500k -> 2600k -> 2700k , price difference are huge for a small performance increases, this is what happens when you have no competition. Will Ivy be all that great, not really but it will drop current Sandy bridge/e prices down, enough to pick up a nice system.

 

Update 5/1/2012

I ended up purchasing an ivy bridge 3770k with an asus z77 maximus motherboard and couldnt be happier, using an antec water cooler I get about 28-30 idle and 50-58 at full load with the cpu overclocked to 4.5ghz.  Room temps can range 70-85 depending on time of the day so overall happy with my current setup, now to catch up on 2 weeks of not working.

 

 

Django close colorbox popup

Ok I had a ton of popups with forms using colorbox and django but on successful submission they needed to be closed instead of standing around. So after some tests and trials the best way to tackle this is to create a template called closed_pop.html or something and have the view render that after a successful submission. In the template closed_pop.html have the following code:

<script language=”javascript” type=”text/javascript”>
parent.$.fn.colorbox.close();
</script>

Done !