Uwsgi on ubuntu 14.04 not working solution

Uwsgi on ubuntu 14.04 not working solution

In Ubuntu 14.04, uwsgi that installed via apt-get will not working. To make it working, please use this steps: 12sudo apt-get remove –purge uwsgi uwsgi-plugin-python sudo apt-get install uwsgi uwsgi-plugin-python Then follow this steps: 1234sudo pip install uwsgi cd /usr/bin sudo mv uwsgi uwsgi-old sudo ln -s /usr/local/bin/uwsgi uwsgi If still failed, follow this : …

+ Read More

Setup Ubuntu Server in Softlayer for Django

Setup Ubuntu Server in Softlayer for Django

Here are a quick step to setup Ubuntu server in Softlayer for Django 1. Install depedencies 1234apt-get install python-software-properties software-properties-common add-apt-repository ppa:webupd8team/java apt-get update sudo apt-get install oracle-java7-installer 2. Install UWSGI, Python, PostgreSQL and other modules 1sudo apt-get install libpq-dev python-dev python-software-properties postgresql postgresql-contrib nginx git zip unzip build-essential python nmap libxslt1-dev python-pip imagemagick uwsgi …

+ Read More

Becareful using int() or Decimal() for validation storing in Charfield Django

Becareful using int() or Decimal() for validation storing in Charfield Django

So, we have CharField() as model field in Django. Then we want to validate input into number only. Usually, we using obj.is_digit() to validate. Common mistake happen when we using int() to convert string input. 12value = "0123123123" int(value) Will return 1"123123123" So becareful when using int() or Decimal() for converting value with leading zero

Update parent after children new windows closed

Update parent after children new windows closed

Here is a snippet to update parent after new window getting closed : 12345678910111213141516171819// Start trigger pop-up new window var createUrl = $(this).data(‘url’) + selectedUUID; newwindow = window.open(createUrl, ‘Some Page, ‘scrollbars=yes,resizable=yes,height=600,width=’+screen.width/2); // Set focus on windows if (window.focus) {     newwindow.focus(); } // Update parent once children window already closed // Reload jqgrid table …

+ Read More

JqGrid inline editing integration with DJango send csrf token

JqGrid inline editing integration with DJango send csrf token

Here is a quick snippet to send csrf_token in POST data from inline edit JqGrid to Django: 12345678910111213141516var tableGrid = $(selector).jqGrid({    ….    onSelectRow: function(id){          if(id && id!==lastSel){             $(selector).restoreRow(lastSel);             lastSel=id;          }       …

+ Read More

Example Jquery Plugin to filtering input value real-time with Regex validation

Example Jquery Plugin to filtering input value real-time with Regex validation

We try to add real-time input validation for dynamic element with some regex. Let say, user allowed only to type “numeric” and disallow any others alphabet and symbols. Then, we can write a small plugin, at this example, i use https://github.com/akzhan/jquery-keyfilter for Regex validation. Then, we just need to write this simple and easy plugin …

+ Read More

Handle error form.save() with model validation

Handle error form.save() with model validation

Here is a quick snippet to avoid form.save() error because model validation : 12345678# handle form save with model validationerror # http://stackoverflow.com/questions/8771029/django-raise-a-validation-error-in-a-models-save-method try:     form.save() except ValidationError, e:     form._errors = {}     for _, v in e.message_dict.items():         form._errors.setdefault(NON_FIELD_ERRORS, []).extend(v)

Inline edit jqgrid with select2

Inline edit jqgrid with select2

Here is a quick snippet for inline edit JqGrid with Select2 First, we need to bind colModel with select2 in dataInit : 1234567891011121314var colModel = [      // always put uuid and id      {name:’id’, hidden: true},      {name:’uuid’, hidden: true},      {name:’youroption’, label:’yourlabel’,editable: true,       edittype: "select", editrules: …

+ Read More

Jqgrid for Dummies

Jqgrid for Dummies

Here is a quick snippet of how to using JqGrid for dummies, like get data, delete data, access data or data manipulation. Setup JQGrid: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970$(document).ready(function() {     // Enable tooltips $("body").tooltip({     selector : ‘[data-toggle="tooltip"]’ }); $(".chosen").chosen(); var permission = $(‘.permission’); // Define ID for table var selector = "#table-index"; var pager = …

+ Read More

JqGrid save inline editing callback

JqGrid save inline editing callback

Here is a quick snippet for callback when saving inline editing in JqGrid: 123456789101112// http://stackoverflow.com/questions/13303698/total-of-amount-in-jqgrid ondblClickRow: function (rowid, name, val, iRow, iCol) {     $(selector).jqGrid("editRow", rowid, {         keys: true,         aftersavefunc: function (rowid) {             var $grid = $(selector);       …

+ Read More

JqGrid delete multiple select rows

JqGrid delete multiple select rows

There is an issue if we delete rows using : 12345678910// Get all selected row var rows = $(selector).jqGrid("getGridParam", "selarrrow"); console.log(rows); // Iterate and delete for (var i in rows) {       console.log(i);       console.log(rows[i]);       $(selector).jqGrid(‘delRowData’, rows[i]); } Only a few records will deleted. The solution : 12345678910111213/** …

+ Read More

Save django model with dictionaries

Save django model with dictionaries

Beware when queryset filter update() because it will pass model validation. Here is some example save model with dictionaries : 12345678910for k, v in account.items():     setattr(instance, k, v) try:     instance.save() except Exception, e:     raise ValidationError(e) else:     updated += 1     # print account

Modify object data by write Custom Renderer in Django Rest Framework

Modify object data by write Custom Renderer in Django Rest Framework

When we need to modify object or results from DRF / Django Rest Framework, all we need just write a custom JSON Renderer like below : 1234567891011121314class JGridJSONRenderer(renderers.JSONRenderer):     def render(self, data, accepted_media_type=None, renderer_context=None):         new_rows = []         # Name the object list         …

+ Read More

Solve issue Fullcalendar count two day as one day

Solve issue Fullcalendar count two day as one day

This is not bug. When we try to add day in March with start 10-03-2015T10:00:00 and end 11-03-2015T02:00:00, then it will showing one day instead of two day. To solve this issue, we need to put nextDayThreshold: 1nextDayThreshold: "00:00" To make the next day threshold every 00:00

Counting number contain 14 on n-digit number in less than 1 second

Counting number contain 14 on n-digit number in less than 1 second

My fellow Adiyat in our company POLATIC bug me with this question “How to counting number contain 14 in 10 millions numbers less than 1 second?”. Then I thought, it’s easy, let give python a shot! 1print len([x for x in range(0, 10000000) if str(x).find(’14’) > -1]) With result “590040” it’s takes 9.6s based on …

+ Read More

Django unit test formset

Django unit test formset

When testing page that contains formset in Django using unit test, we may encounter : 1ValidationError: [u’ManagementForm data is missing or has been tampered with’] This is happend because we POST data without required FORMSET hidden value in form. To solve this issue, inspect element on your formset and insert hidden value in payload data. …

+ Read More

Example make reusable javascript app for modal progress bootstrap

Example make reusable javascript app for modal progress bootstrap

This is example build reusable app in Javascript for modal progress in Boostrap: 123456789101112131415/**  * Re-usable app for modal box progress  */ var progressBox; progressBox = progressBox || (function() {     var pleaseWaitDiv =  $(‘<div class="modal hide" id="pleaseWaitDialog" data-backdrop="static" data-keyboard="false"><div class="modal-header"><h1>Processing…</h1></div><div class="modal-body"><div class="progress progress-striped active"><div class="bar" style="width: 100%;"></div></div></div></div>’);     return {     …

+ Read More

How to hide search toolbar in Datatables

How to hide search toolbar in Datatables

Here is a quick snippet to hide search toolbar in datatables and working along with Bootstrap 1234var settings = {             sDom: ‘lrt<"col-sm-6"i><"col-sm-6"p>’,             serverSide : true, …

Set bootstrap datetimepicker input value date

Set bootstrap datetimepicker input value date

Here is a quick way to set value bootstrap datetimepicker input with date object: 123456$("#id_start_date, #id_end_date").datetimepicker({     format: "DD-MM-YYYY hh:mm" }); $(‘#id_start_date’).data("DateTimePicker").setDate(start); $(‘#id_end_date’).data("DateTimePicker").setDate(end);

Datatables make link in row records

Datatables make link in row records

Here is a quick snippet to make record as links in Datatables : 12345678columns : [               {                 "mRender": function ( data, type, full ) {                  // ‘full’ is the row’s data object, …

+ Read More

Change / Reset / Update Key Pem Amazon EC2 Simple

Change / Reset / Update Key Pem Amazon EC2 Simple

Here are simple tricks to change or update key PEM in Amazon EC2. At this example, I’m using Ubuntu. To reset or change key pem, all you need just follow this simple steps: Let say, currently we have SERVER_01 and KEYPEM_01. 1234561. Launch a new instances using "launch more like this" (right-click on instances) 2. …

+ Read More

Django check related model and check field if exists in model

Django check related model and check field if exists in model

We can check if the field is related model in Model by : 1model._meta.get_field("name_of_field").get_internal_type() == "ForeignKey" Then we can check if the field name is exists in model by : 1model._meta.get_field_by_name(_name) Some example code: 123456789101112131415if self.model._meta.get_field(field_name).get_internal_type() == "ForeignKey":     # get related model     # http://stackoverflow.com/questions/10347210/django-foreign-key-get-related-model     related_model = self.model._meta.get_field(field_name).rel.to     …

+ Read More

Mapping Ajax Filter and Search Datatables to Django with Rest Framework

Mapping Ajax Filter and Search Datatables to Django with Rest Framework

Datatables sending ajax parameter for filtering and search in very complicated way. Which we need to mapping and parse based on each column. Some example request : 1http://localhost:8000/api/somemodel/?format=json&sEcho=4&iColumns=7&sColumns=%2C%2C%2C%2C%2C%2C&iDisplayStart=0&iDisplayLength=10&mDataProp_0=&sSearch_0=&bRegex_0=false&bSearchable_0=true&mDataProp_1=cif&sSearch_1=22222&bRegex_1=false&bSearchable_1=true&mDataProp_2=name&sSearch_2=&bRegex_2=false&bSearchable_2=true&mDataProp_3=gender&sSearch_3=&bRegex_3=false&bSearchable_3=true&mDataProp_4=ktp&sSearch_4=&bRegex_4=false&bSearchable_4=true&mDataProp_5=location&sSearch_5=&bRegex_5=false&bSearchable_5=true&mDataProp_6=&sSearch_6=&bRegex_6=false&bSearchable_6=true&sSearch=&bRegex=false I have no idea about where the filtering and search query come from in this request. Therefore, we need to auto-mapping it by : 123456789101112131415161718import re from …

+ Read More

Disable sort on first column in Jquery Datatables

Disable sort on first column in Jquery Datatables

Dunno if this is bug or not, but disable sort in HTML nor Javascript will not affect for first column sorting in Datatables. The solution just define bSort = false 123456var table = $(‘#table-index’).dataTable({             serverSide : true,             sAjaxSource : url,       …

+ Read More

Solve ScrollTop Jquery not working in Boostrap because overflow:auto

Solve ScrollTop Jquery not working in Boostrap because overflow:auto

Yes, ScrollTop Jquery not working in Boostrap because overflow:auto. To solve this, we need to use div that using “overflow:auto” and solve by : 123456789101112<script type="text/javascript">            $(document).ready(function() {                                 /* smooth scrolling for scroll to …

+ Read More