Saturday, August 30, 2014

Settings split

We are splitting the settings between live and local environments for takeaway app.
Followed the instructions given here to achieve that.
https://coderwall.com/p/v1sjsw

With this new change you need some modifications on your local env for this to work


  1. Set DJANGO_SETTINGS_MODULE env variable on your local to "settings".
  2. set DJANGO_ENVIRONMENT to "local"
this will load the local.py file from the settings folder.
So any settings you want to  change between local and prod, the entry needs to be put in both local.py and live.py with corresponding value.
For example, DEBUG is True in local.py and False in prod.
same goes for SESSION_TIMEOUT, if you want a longer timeout set it in local.py but dont check it in.


Sunday, August 24, 2014

Custom registration in Django

The Django-registration is a powerful plugin but you need to be careful as to how you handle it.
If you add custom fields to it make sure you do it the right way.
Sometimes the registration can fail silently when the validation of its fields fail and you will not be explicitly notified about it.
So whenever you see POST on registration yielding 200OK and simply returning the form again
you can check the below

  1. that all user specific fields are being sent (username, email, pwd1, pwd2)
  2. that none of the custom fields validation is failing (i tested it by extending ChoiceField with a NoValidationChoiceField and my registration seems to be passing)

Friday, August 8, 2014

Django Related setup


Ubuntu comes with default python 2.7

install pip using sudo apt-get install python-pip 


Create a virtualenv so that all you various versions of installations are localized to just that env.

For example : If you are working on 2 applications , one requiring 1.4 DJango and another one 1.6 Django
You do not want both of them to overlap. This is where virtualenv will come in handy.

use linux command sudo pip install virtualenv

Once you have the virtual env

create a virtual env  $virtualenv renv (renv can be any name you want)

before activating the virtual env set these variables up

edit your activate file inside renv/bin/ to include these exports
export DJANGO_SETTINGS_MODULE=settings
 export DJANGO_ENVIRONMENT=local

activate this virtualenv by issuing the command $ cd renv

followed by $ source/bin/activate  

This would save you the time in setting these values every time.

Once inside the virtual env and activated start installing the required software by using PIP.

Get the requirements.txt for your project.

But before installing the packages install psycopg libraries to avoid failure.
sudo apt-get install libpq-dev python-dev

now run

$ sudo pip install -r requirements.txt

This will install all the softwares listed in the file. At this point all of these softwares are only visible if the virtualenv (in this case renv) is activated.

You should have a clean build. If not document the errors here so that future Bolgians can seek help.

In order to install psycopg libraries use this
http://stackoverflow.com/questions/5420789/how-to-install-psycopg2-with-pip-on-python


Once you have the code from GIT and have installed all the python dependencies run the below commands to set up the data needed for logging in


  1. python manage.py syncdb
  2. create admin user so that you can log into admin screen
  3. python manage.py migrate takeaway
  4. python manage.py migrate notifications
  5. go to this link localhost:8000/takeaway/initload to load data
  6. now login with ravi/abc123 or atluri/abc123 to enter the app
  7. have fun


Getting started

This is an internal document for setting up development environment. May not necessarily make sense to everyone.

Brief explanation of the setup to get up and running
  1. Use a linux environment to start with. Windows works too as long as you can make it work.
  2. Install GIT, python 2.7.2, Django 1.6.5 and postgres (if possible)
  3. We use Django rest api for backend and backbone + HTML5 + CSS3 for front-end.
  4. We currently use sublime text for our development and chrome developer tools for debugging front end code. 
  5. We deploy to Heroku using git push.