Tuesday, December 27, 2011

Autoselection of checkboxes in a table

The code doing selection
$(function () {
    "use strict";
    var toggleSelect = $("#all"),
        checkboxes = $("#table").find("tbody input[type=checkbox]");
    toggleSelect.click(function () {
        checkboxes.attr('checked', $(this).is(":checked"));
    });
    checkboxes.click(function () {
        toggleSelect.attr('checked', checkboxes.length === checkboxes.filter(':checked').length);
    });
});
A sample table
Username Phone Number
User 1 0123456789
User 2 0133456789

Tuesday, December 6, 2011

Activate VE from Django's manage.py

To transparently activate virtual environment from project's manage.py insert the code below right after #!/usr/bin/env python
activate_this = '/ABSOLUTE/PATH/TO/ENVIRONMENT/FILES/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))