Self-testing fabfile using docker

By : Javed Khan

In my last blog post, I discussed deploying django on docker. This is a blog post on a related note and we'll be looking at using docker to test a fabfile. Note that docker is still under development and not ready for use in production.

Fabfile and testing:

Fabric is a great tool for automating deployments. Unfortunately, the docs on testing fabfiles are a bit scarce.

With good tests, you can be sure that your fabfile works out of the box and be prepared for server migrations or upgrades.

One apporach to testing complex fabfiles is using vagrant or ...

more info..
Topics : deploy docker fabfile

Deploying django using docker

By : Javed Khan

In this blog post we'll take a look at Docker and discuss ways to deploy django using docker.

About Docker:

Docker is a tool that helps you manage lxc containers and images. You can create an image, launch container from the existing image, attach to a running container, and generally play around with the containers.

The most important benefit of using docker and containers in general is that you have a clean, hygeinic and portable runtime enivorment for your app. This means you don't have to worry about missing dependecies, packages and other pain points during subsequent deployments ...

more info..
Topics : django deploy docker

Common testing scenarios for Django app.

By : Akshar Raaj

People are often confused regarding what tests to write. Let's look into some scenarios for which tests can be written.

Setting up the project

We start a Django project inside a virtual environment. In this post we would be using django 1.4.

(dj)~/play/dj$ django-admin.py startproject testcases

Let's start an app named blog.

(dj)~/play/dj/testcases$ python manage.py startapp blog

We will have the following model in blog/models.py:

class BlogEntry(models.Model):
    title = models.CharField(max_length=100)
    text = models.TextField()
    is_published = models.BooleanField(default=True)
    user = models.ForeignKey(User)

We ...

more info..
Topics : django testing

Serving static files in Django

By : Akshar Raaj

Serving static files, especially during development, is frequently a pain point. In this post, we will discuss the various settings and directory structure and how they interact with each other. Let's start with development when you have DEBUG = True.

We will create a Django project from scratch so that we are fully aware about what file in what directory we are talking about. So, this blog post will be a little longer than it should be. We will try these things with Django 1.4, but these will work on Django 1.3 as well. I have not tested ...

more info..
Topics : django static

Two Scoops of Django: Review

By : Shabda Raaj

Django best practices

Two scoops of Django is the new book on Django best practices by Daniel Greenfeld and Audrey Roy. I just finished reading it and found it extremely useful.

The book is a collection of tips, their justification and code organized in logical areas. I have been using Django since 2008, but I still found a few tips which were new to me and many which served as good reminder. At about 200 pages, its comprehensive but not overwhelming. If you are an advanced Djangonaut, you can read it in a weekend (And you probably are using all its recommendations anyway ...

more info..

Introduction to Python Workshop on February 15th, 2013

By : Thejaswi Puthraya

We are conducting an "Introduction to Python" workshop at our office on February 15th, 2013 (Friday) between 5-8PM IST. This workshop is geared towards those who are planning to learn python.

Topics:

  • Language features
  • Variables
  • Built in data structures
  • Functions
  • Object Oriented Programming
  • Demo writing a simple program

Prerequisites to attend this session:

  • A laptop with any linux flavour (OR) a laptop with Python installed in it.

Register for the workshop by filling up the form.

more info..
Topics : python training

Easy client side form validations for Django: Django Parsley

By : Shabda Raaj

Parsleyjs is a JavaScript library to do client side data validations. It does this in a non-intrusive way via adding a data-* attributes to form fields. Check it out, it's really slick.

Django forms do a great job of server side data validations. By integrating Parsley with Django form, you get good client side data validations as well. Get the app here.

Some design considerations

When I started writing this app I wanted to make it really easy to use. My first thought was to make this a filter or a template tag which would have allowed you to ...

more info..
Topics : django

MoreApps - Android Library Project: Open Sourced

By : Shabda Raaj

If you have a portfolio of apps, you probably want to cross promote them.

We are open sourcing an Android Library Project to make this possible. Get the code. This provides an Activity which you can show with a Grid of your apps.

How to use it

Add this MoreAppsLibrary project(library) as a dependency in the Android Application project you are implementing.
Add the following code in your AndroidManifest.xml:

<activity android:name="com.agiliq.android.moreappslib.MoreAppsActivity"
          android:label="More Apps">
</activity>

Perform an Intent to start the MoreAppsActivity; make sure to putExtra("package", getPackageName());, this ensures that ...

more info..
Topics : android open-source

Tutorial: Building a Chrome app

By : bhaskar

This is a hands on tutorial about How to build chrome apps, with examples of two Chrome apps we published recently. Lets get started.

Chrome apps are of two types:

  • Extensions : They extend the functionality of Google chrome and the websites. They have little or no UI. Ex:Password Generator . Source code : Github
  • Apps: These are separate apps and appear just like any other website. Ex: To Do List. Source Code : Github

Depending on our requirement, we need to decide what kind of app we need to build.

Extension: Password Generator

Installation :

Visit the link Password Generator using google-chrome browser ...

more info..

Password Generator App: Open Sourced

By : Shabda Raaj

Announcement:

We are open sourcing a few tools we developed recently. Here is the second one.

Password Generator Chrome Extension

Install it from chrome webstore
Here are the docs

Summary

A completely client side password generator.

What is it

Its a chrome app to generate unique passwords for each site. Depending upon the domain and a master password a unique password is generated. It doesn't need any server and everything happens on the client side.

Why?

I want to use a unique password for each website. However, I don't want to use lastpass/1password as I find their ...

more info..

Android Fragments 101

By : ikram - Programmer, Web Hacker, App Developer, Techie & Geek.

Prerequisite: You are already aware of the basics of building a HelloWorld in Android and know how to use the APIs provided in the support library.

The code example is available on github.


Ever wanted a code snippet from an Activity to be available to other activities? Perhaps a Button or a ListView, maybe a Layout or any View/ViewGroup for that matter? Fragments let us do just that.

Necessity is the mother of invention.
Before understanding what Fragments are and how they work, we must first realize their existence in the first place.

The Problem

Suppose we have an ...

more info..

Understanding decorators

By : Akshar Raaj

Understanding decorators in Python

We will divide this post into two topics

  1. Functions are objects and they can be passed around.
  2. Writing few decorators

As usual, I will be trying out the code in ipython and I suggest you to do the same.

Functions can be passed around similar to any other object in Python.

If you are already familiar with this, you can skip to next section.

Let's first write a class.

>>> class A(object):
...     def __init__(self, a):
...         self.a = a
...

Let's create an instance of this class.

>>> obj = A(5)    
>>> print obj.a
5                 #output ...

more info..

Not exactly, not exactly tim the enchanter

By : Javed Khan

I've been putting off writing about my experience with django form wizard for some time now. I came across this blog post by Kenneth Love which finally compelled me to write this down.

About Django Form Wizard:

Form Wizard can be handy when you have a huge form, and you want to make it less intimidating to the user by splitting it into multiple steps.

If you have glued multiple forms together with sessions or whatnot and it turned out to be a mess, you now what I'm talking about :)

Think surveys, checkouts, lengthy registrations etc.

The class ...

more info..
Topics : django forms wizard

The missing documentation for django.utils.datastructures

By : Thejaswi Puthraya

Note

django.utils.datastructures is intentionally not documented by the django core devs because it is an internal API and is liable to change without any notice. This file is not governed by django's lenient backwards-compatible policy. You have been sufficiently warned!

With the note out of the way, let's look at the interesting datastructures in this file. You may ask why we should learn about those when we shouldn't be using them? Reading code is the best way of learning and this file has some beautiful code.

MergeDict is the first of the datastructures in the ...

more info..
Topics : django internals

Dissecting Phonegap's architecture

By : Thejaswi Puthraya

Apache Cordova is a open source cross-platform framework for building native mobile applications using HTML, CSS and JavaScript. It started off as Phonegap, a project of Nitobi Software before it was acquired by Adobe Systems. The code for the platform was donated to the Apache Software foundation and is currently being incubated as "Apache Cordova".

Phonegap is now a distribution of Apache Cordova (analogous to Ubuntu being a Linux distribution) brought to you by Adobe. Since Apache Cordova is licensed under the permissive Apache Software License, Adobe Phonegap may technically be integrated with proprietary software (though there's no evidence ...

more info..

Dropbox file upload handler for django

By : Thejaswi Puthraya

Dropbox announced new pro plans last week and some accounts have had their storage size doubled. Wouldn't it be wonderful if we could upload all our files to dropbox from our django webapp?

In this post, I write a custom file upload handler that will upload files from our application to dropbox.

Let us see how to use the custom file upload handler.

Install the Dropbox Python SDK before you setup your django app to handle the file uploads.

In your settings.py, add the following attributes (with the values filled):

DROPBOX_APP_KEY = ""
DROPBOX_APP_SECRET_KEY = ""
DROPBOX_APP_ACCESS_TOKEN = ""
DROPBOX_APP_ACCESS_TOKEN_SECRET = ""

# Optional values below

# The ...

more info..

Using Ubuntu cloud images in KVM

By : Thejaswi Puthraya

Quite a few of our clients are powered by Amazon EC2 or Rackspace and we use Ubuntu LTS releases for our servers. Canonical provides EC2 AMIs and Openstack images for all their releases. By using these JeOS images on the server as well as on the development platform reduces the dev/prod parity which we discussed in a previous post.

In this post, we'll see how to setup the Ubuntu cloud images in the local KVM hypervisor. Unlike the previous post, we'll use only the virt-manager to do the initial provisioning but you can be assured that there ...

more info..

Metaclass in Python

By : Akshar Raaj

In this post we will be talking about Metaclass in python. If you are reading some code which uses metaclass, you will probably come across __new__. If you are not familiar with what __new__ does, i suggest you first read about __new__.

You can read about __new__ in our last to last post

Throughout this post we will be talking about new style classes. Things might differ in old-style classes.

As we go, i will be trying everything on IPython and suggest you as well to try everything on IPython.

Let's see a little bit about normal Objects in ...

more info..

Libvirt and KVM

By : Thejaswi Puthraya

"But it works on my local setup!" We have heard or probably said this tens of times after something that we deployed to the production server breaks. After fire fighting for hours we learn that a particular package's version varies from the local setup. This is a fairly common problem that plagues every developer. Off late, quite a lot of interest and work is going into maximizing the dev/prod parity to prevent such problems.

Software like virtualenv help a great deal in compartmentalizing python dependencies but most web applications nowadays have to deal with loads of other dependencies ...

more info..

__new__() in python

By : Akshar Raaj

Lately I started looking into Django code and wish to write about internals of Django. I started with Django models and will be writing about it soon. For understanding how Django models work, I had to understand what metaclasses are and how metaclasses work. Metaclasses use method "__new__" and so I looked at what "__new__" does.

As __new__ is a static method, we will see a lttle bit about static methods and then __new__ in detail.

  1. Understanding static methods.

  2. Understanding method "__new__" of any class. We will see how to override method __new__ in a class.

Also, I will be ...

more info..

Understanding '*', '*args', '**' and '**kwargs'

By : Akshar Raaj

When i started learning Python, i was very confused regarding what args, kwargs, * and ** does. And i feel there are few like me who had this confusion and problem. With this post, i intend to reduce (hopefully i can eliminate) that confusion.

Throughout this post, i will be using ipython and i suggest you to try everything on ipython as well. We will intentionally make some mistakes along the way, so that we can understand this topic better.

Let's divide our work under five sections:

  1. Understanding what '*' does from inside a function call.
  2. Understanding what '*args' mean inside a ...

more info..
Topics : python args kwargs

Provisioning Made Easy With Chef

By : Saket Bhushan

Managing Servers and scaling at will is hard. The bigger web players have put in years of effort, brute-forcing at times and re-iterating their methodologies, have come up with the secret sauce which they use to keep their cloud cool. The article is meant to be introductory rather than comprehensive. Chef has a steep learning curve, and in this post I wish to simplify few of the basic concepts. So, instead of going to the Chef Docs, finding searching, reading and re-reading, few of the beginner concepts are put at one place, which will help you get started on your ...

more info..
© Agiliq, 2009-2012