Monday 27 October 2014

create thumbnail on image upload in django

Standard
Django does not provide any standard way of organizing thumbnails.
Even though community has some applications to work with thumbnails, they are usually over kill if You only want to create a thumbnail for an ImageField. So here is my solution to handle thumbnails.

To hande thumbnails I over-wrote my model's save method to read original image field into a StringIO, manipulate the image and save it into a thumbnail image.
first of you need a python PIL library so first install it :

sudo apt-get install libjpeg libjpeg-dev libfreetype6 libfreetype6-dev zlib1g-dev
pip install PIL 

Here is the code.

Monday 6 October 2014

x-mvc form validation

Standard
in new x-mvc i have added form validation it is so simple and usable

reference link : https://www.npmjs.org/package/x-mvc

How to use

Install from npm
npm install x-mvc
 
Instantiate a new form_validation object

req.library.load('form_validation');

/** construct a new form_validation object passing the data array to validate
  * date array should contain a set of objects formatted as following
  * {fieldName: value}
 */ 
var data = {
    name: 'foo bar',
    email: 'foo@bar.com'
}
var form_validation = new req.library.form_validation(data);