Month: January 2015

Jquery Datatables modify fnserverData and pagination

Jquery Datatables modify fnserverData and pagination

Here is a quick snippet for custom AJAX data for Jquery datatables : 1234567891011121314151617181920212223242526272829303132 var table = $(‘#table-index’).dataTable({                 "serverSide": true,                 "searching": false,                 "ordering": false,                 …

+ Read More

Using format instead of %s for string replacement

Using format instead of %s for string replacement

Usually we use “%s” for string replacement in Python: 1"asddas %s" % (‘hello’,) There is better way to do it: 123"hello {a} {b} {c}".format(a=’error’, b=’hello’, c=’world’) "hello {0} {1} {2}".format("hello", "world", "fine") "hello {}".format("hello")

Your branch and ‘origin/master’ have diverged, and have 1 and 1 different commit each, respectively.

Your branch and ‘origin/master’ have diverged, and have 1 and 1 different commit each, respectively.

I got this problem: 123456λ git status On branch master Your branch and ‘origin/master’ have diverged, and have 1 and 1 different commit each, respectively.   (use "git pull" to merge the remote branch into yours) nothing to commit, working directory clean Solution 12λ git reset –hard origin/master HEAD is now at 63813ef fix localdb

Git checkout track from remote branch

Git checkout track from remote branch

Let’s say somebody already push their branch in remote called “finances”. We want to fetch and working on this branch from our local. So, the solution : 12345git fetch –all Fetching origin From github.com:polatic/vasham-erp  * [new branch]      finance    -> origin/finance Then, we checkout with tracking 123git checkout -t origin/finance Branch finance set …

+ Read More

Accelerate django development server with django-devserver

Accelerate django development server with django-devserver

As we know what django development server running on single thread. This is make development a bit slow. There is some alternative, by using django-devserver Here is the quickstep: 1. Install the app 1pip install git+git://github.com/nealtodd/django-devserver 2. Edit your local_settings.py 12345INSTALLED_APPS =  (‘devserver’,) + INSTALLED_APPS MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + (    ‘devserver.middleware.DevServerMiddleware’, ) 3. Then …

+ Read More

Solve Django Filter queryset result duplicates with Pagination

Solve Django Filter queryset result duplicates with Pagination

When we filter using multiple filter and mixed with django pagination, somehow the results are duplicates. This is incorrect. Apparently, looking at the source code https://github.com/alex/django-filter/blob/master/django_filters/filters.py#L105, I found this line: 1234q = Q() for v in value:     q |= Q(**{self.name: v}) return qs.filter(q).distinct() By default, django-filter not using “AND” condition and that’s why …

+ Read More

Setup Django and Timezone follow server datetime (Ubuntu)

Setup Django and Timezone follow server datetime (Ubuntu)

Here is quickfix to setup Django working with server timezone. 1. Set Server Timezone Check by : 12date Mon Jan  5 10:54:38 WIB 2015 If this not correct or you want to change server timezone, then edit “/etc/timezone” 1Asia/Jakarta Then do : 12sudo dpkg-reconfigure –frontend noninteractive tzdata date Now you should see the updated server …

+ Read More