This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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. | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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)"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def do_update(self, obj, request): | |
obj.user = request.user.get_root() | |
serializer = DeviceSerializer(obj, data=request.data, partial=True) | |
is_create = obj.pk is None | |
if serializer.is_valid(): | |
serializer.save() | |
if is_create: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.factory('Client', function() { | |
function Client(obj) { | |
obj.created = new Date(obj.created); | |
angular.extend(this, obj); | |
} | |
return Client; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.questionnaires = []; | |
$scope.selectAll = function() { | |
$scope.selected = $scope.questionnaires.map(function(q) { | |
return q.id; | |
}); | |
}; | |
$scope.clear = function() { | |
$scope.selected = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
moment.locale('pt-BR'); | |
$scope.months = []; | |
$scope.series = []; | |
$scope.data = []; | |
$http.get('/nodes') | |
.then(function(response) { | |
var months = {}; | |