Skip to content

Instantly share code, notes, and snippets.

View samirbr's full-sized avatar

Sam Aouar samirbr

View GitHub Profile
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
def update_plans(apps, schema_editor):
# free to Free
for user in User.objects.filter(plan='free'):
user.plan = 'Free'
user.save()
def remove_keys(d, keys):
for key in keys:
d.pop(key)
return d
for consistency in Consistency.objects.filter(question__parent_id=form_to_copy.id):
c_dict = generic_as_dict(consistency)
c_dict = remove_keys(c_dict, ['id', 'condition', 'question'])
cond_dict = generic_as_dict(consistency.condition)
<div ng-controller="UploadOptionController">
<!-- $scope must have a method fromFile that receives the content -->
<!-- $scope.fromFile = function(content) { ... }
<div>
<label>Separator</label>
<input type="text" ng-model="upload.needle" name="needle">
<div>
<input class="hide" type="file" ng-model="upload.file" name="file"
onchange="angular.element(this).scope().upload.load().then(angular.element(this).scope().fromFile)">
def copy(o, replacements, exclude):
d = model_to_dict(o)
for key in exclude:
d.pop(key)
for key in replacements.keys():
d[key] = replacements[key]
obj = o.__class__.objects.create(**d)
@samirbr
samirbr / coalesce.py
Last active March 21, 2022 15:52
django coalesce
"""
Classes that represent database functions.
"""
from django.db.models import IntegerField
from django.db.models.expressions import Func, Value
class Coalesce(Func):
"""
Chooses, from left to right, the first non-null expression and returns it.
"""
@samirbr
samirbr / cf.py
Created July 30, 2015 17:16
COALESCE
from django.db.models.expressions import F
def __floordiv__(self, other):
return self._combine(other, '||', False)
F.__floordiv__ = __floordiv__
class CF(F):
"""
A coalesced expression representing the value of the given field.
"""
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
nggettext_compile: {
all: {
options: {
format: "json"
},
files: [
<!DOCTYPE html>
<html>
<head>
<!-- http://jsfiddle.net/p7snevh1/81/ by myself -->
<style>
html, body { height: 100%; }
#list { height: 100%; }
#list>.item {
height: 18px; padding: 2px 0; border-bottom: solid 1px gray; overflow: hidden;
}
angular.module('myApp')
.factory('Harvest', [
'$resource',
function ($resource) {
return $resource('/viewver/api/harvest_viewver/?id', {'id': '@id'}, {
create: { method: 'POST' }
update: { method: 'PUT' }
});
}
]);
Array.prototype.forEach(document.querySelectorAll('[bind]'), function (bindable) {
this.value = application[this.attribues.get('bind')];
bindable.addEventListener('keyup', (function (event) {
application[this.attribues.get('bind')] = this.value;
}).bind(bindable));
});