Skip to main content

Posts

Showing posts with the label plugin

Django CMS custom Plugin ManyToMany fields problems.

Developing a website for Django CMS I have done a plugin. This plugin however have had a problem. It had an m2m field. While selecting images there (It was a gallery plugin). It was not saving it to production. This way main problem with this field was that plugin have displayed m2m choices on a draft page and while storing it to live it fails. Django CMS Pages is built like so it has multiple versions of pages. Each Page model that is changed is stored under new revision. And so plugin is copied and relinked to that page too. So plugin revisions multiply to. For e.g. in case you have a Draft page with two plugins that have model primary key number (pk in future) 12 and 14 accordingly. Say you hit publish changes. Not only PK of Page model rises and data are copypasted into new empty Page model instance. Those plugins are copied to. So mentioned plugins PK would change to 15 and 16 accordingly, assuming 14 is the latest plugin pk. New copied plugins will be linked to new page. Tha...

AJAX form in Django with jQuery.form plugin

Here I will describe an example form using jQuery Form  plugin. It will provide a good frontend, while Django serving a simple backend. I made this AJAX form using unobtrusive javascript. With human language it means the form will function with JavaScript disabled. And so jQuery.form plugin will work as an AJAX speedup addition and not as a major requirement. Features: * Works both with JavaScript  and without. * Uses standard Django ideology/hooks. * Uses the most known jQuery plugin for forms AJAX handling. Theory: Main idea that Django supports both normal and AJAX request in a standard view. And has a handy request.is_ajax() request method. It returns True/False depending on if request search has HTTP_X_REQUESTED_WITH header for the string 'XMLHttpRequest' . jQuery.form plugin sure does have that. Backend Django. We will create an app called 'contact' for our task and place it in the example django project. Urls from the project will redirect to ...

JavaScript: validate date field in form

You may often require serialization of a form in JS and parsing of it's data. Here is a nice recipe to validate date with browser default methods. I like it because of relative simplicity. It works on a principle of parsing date's components. We will create a JavaScript Date object from it and check if it is the same as a parsed date string. Date components that are wrong will go out of rage. SO we will have them different from the existing strings. This method is based on that hack. I use this only to validate the string itself. I am specifying a placeholder of an input field to minimise user possibility to make a mistake. And I usually force user to enter date in my format with this tool. Anyway it's a good idea to put any datepicker component also. function validate_date ( value ) { /**********************************************     * Validating date in format dd/mm/yyyy     ************************************...

Django: Creating multi upload form without using Flash

Hi there! Today I want to tell you about my experience of adding Multiple files upload form to my  Django project Photoblog.  I searched google for lots of plugins, but found only Flash usage examples. I dislike Flash technology, as for my personal usage, and want to build some more quickly working UI. Personally I have flash blocker installed on my browser. So that's main ideas pf my jQuery plugin selection. I found IMHO the best for my case plugin by  Sebastian Tschan . It had only one problem - No available Django examples. Let's try to fill the gap here... So my experience on befriending  Sebastian Tschan's jQuery File Upload Plugin  with Django is the topic of this article. Let's finally get started. :) Sebastian has built an important plugin IMHO. I want to thank him for his noble work of helping people with their tasks. It uses only jQuery UI and no flash, making it work more programmers way... So enough with the lyrics. Let's try to adapt his example...

Django: Installing Eclipse and PyDev for django

In most common cases of programming Django with Eclipse are that Django is installed in system, like Python. I dislike this method, because it makes confusions for beginners. What Django version I'm in. Why did I download an app "X" and added an Eclipse project. Everything seems to be fine, but I cant install proper dependencies... So it's not a secret. Managing Django distributions is a hard work for junior developer. Let's try to make their work simpler, by this article. I'll try to show you the right way to install Django environment on Eclipse. 1. First of all let's install Eclipse from official site . I chose "Eclipse IDE for JavaScript Web Developers". Mac 32bit version, because I'm using this OS type. Any other distributive will work just fine, I think. 2. Unpack downloaded archive into some dir. It will be installation directory of the eclipse. Usually it doesn't mater where it is stored. So I used "/Users/garmoncheg/De...