Skip to content

Instantly share code, notes, and snippets.

View edgabaldi's full-sized avatar

Edgar Gabaldi edgabaldi

View GitHub Profile
@edgabaldi
edgabaldi / readonly.py
Created July 16, 2015 02:31
ReadOnlyFieldsMixin
from django.utils import six
from django.utils.encoding import force_str
class ReadOnlyFieldsMixin(object):
readonly_fields = ()
def __init__(self, *args, **kwargs):
super(ReadOnlyFieldsMixin, self).__init__(*args, **kwargs)
self.define_readonly_fields(self.fields)
@edgabaldi
edgabaldi / round_decimal.py
Last active August 29, 2015 14:23
Round Decimal
>>> from decimal import Decimal
>>> Decimal('2.14999').quantize(Decimal('0.00'))
Decimal('2.15')
@edgabaldi
edgabaldi / capacidadecategoria_form.html
Created June 23, 2015 18:18
Custom template example of ModelFormSetView (django-extra-views)
{% extends 'agendamento/base_comitente.html' %}
{% load bootstrap %}
{% block extra_css %}
<style>
.form-actions{
padding:10px;
background-color:#EEE;
border-top:1px solid #CCC;
}
select.form-control + .chosen-container.chosen-container-single .chosen-single {
display: block;
width: 100%;
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.428571429;
color: #555;
vertical-align: middle;
background-color: #fff;
@edgabaldi
edgabaldi / example.py
Created April 30, 2015 18:24
mocking queryset example
from django.db.models import Count
from .models import DummyModel
class ExampleClass(object):
def get_queryset(self)
filter = {
'foo': 'bar',
'baz': True
@edgabaldi
edgabaldi / gist:8d1290041ed16a304853
Created April 5, 2015 17:57
bid history demonstration
$ cat dados.csv | wc -l
26934
$ cat dados.csv | head
user_id,marca,modelo,ano,estado_geral
14840,Honda,CG 150 Titan ES,2006/2007,Veículo irrecuperável sem motor
56762,Honda,CG 150 Titan ES,2006/2007,Veículo irrecuperável sem motor
14840,Honda,CG 150 Titan ES,2006/2007,Veículo irrecuperável sem motor
53398,Honda,CG 150 Titan ES,2006/2007,Veículo irrecuperável sem motor
56434,Honda,CG 150 Titan ES,2006/2007,Veículo irrecuperável sem motor
from unittest import TestCase
from mock import patch, Mock
from matriz import Matriz
class MatrizTest(TestCase):
@patch('matriz.Matriz.inicializar_matriz')
def test_intancia_matriz(self, method):
method.return_value = 'matriz'
@edgabaldi
edgabaldi / nginx_site_conf
Created February 3, 2015 12:46
serving static files on nginx and django
server {
...
location /static/ {
alias /opt/myenv/static/;
}
location / {
...
}
@edgabaldi
edgabaldi / app.js
Created January 27, 2015 20:00
angular charts example
var widget = angular.module('Widget', ['angularCharts']);
widget.controller('WidgetCtrl', ['$scope', function($scope){
$scope.config = {
title: 'Products',
tooltips: true,
labels: false,
mouseover: function() {},
mouseout: function() {},
click: function() {},
class MyForm(forms.Form):
name = 'My Form Name'