Skip to content

Instantly share code, notes, and snippets.

View gladson's full-sized avatar
😎
Vá lutar pelo que você acredita.

Gladson gladson

😎
Vá lutar pelo que você acredita.
View GitHub Profile
@gladson
gladson / gist:3906042
Created October 17, 2012 15:06 — forked from rafaelchagasb/gist:3845490
Filtro de municípios por estados - Django 1.3
/* >>>>>>>>>>>>>>> models.py <<<<<<<<<<<<< */
from django.db import models
class MeuModelo(models.Model):
estado = models.ForeignKey('Estado')
cidade = models.ForeignKey('Cidade')
class Pais(models.Model):
@gladson
gladson / forms.py
Created October 2, 2012 15:44 — forked from macndesign/forms.py
Validação e formatação para campo localidade com cidade e estado juntos (Fortaleza - CE).
from core.validators import format_locality, validate_locality
class ClientForm(forms.ModelForm):
...
...
locality = forms.CharField(
help_text=u'Local da sede principal do cliente. Ex: São Paulo - SP',
validators=[validate_locality],
)
...
@gladson
gladson / bootstrap-recaptcha.css
Created October 1, 2012 15:46 — forked from boh1996/bootstrap-recaptcha.css
Twitter Bootstrap reCAPTCHA
.input-recaptcha {
width:172px;
}
@gladson
gladson / date_range.py
Created September 27, 2012 00:24 — forked from felipe-prenholato/date_range.py
Date Range widget and field.
# -*- coding: utf-8 -*-
#
# This code have contributions of Augusto Men (https://github.com/augustomen)
# and Nando Florestan (https://github.com/nandoflorestan)
#
from __future__ import (absolute_import, division, unicode_literals)
from datetime import date
@gladson
gladson / api_urls.py
Created August 31, 2012 03:59
Test: Making a CRUD using django + tastypie
from tastypie.api import Api
from basic.api.resources import NoteResource, UserResource
api = Api(api_name='v1')
api.register(NoteResource(), canonical=True)
api.register(UserResource(), canonical=True)
@gladson
gladson / models.py
Created August 23, 2012 22:27 — forked from gilsondev/models.py
Alterando atributos de certos fields da classe Pai
class User(models.Model):
"""
Users within the Django authentication system are represented by this
model.
Username and password are required. Other fields are optional.
"""
username = models.CharField(_('username'), max_length=30, unique=True,
help_text=_('Required. 30 characters or fewer. Letters, numbers and '
'@/./+/-/_ characters'))
@gladson
gladson / cnpj_field.py
Created August 15, 2012 22:33
Exemplo CNPJ
from django.forms import ModelForm, TextInput
from app.models import Exemplo
class ExemploForm(ModelForm):
cnpj = CharField(max_length=18)
class Meta:
model = Exemplo
widgets = {
'cnpj': TextInput(attrs={'mask': 'cnpj'}),
@gladson
gladson / api_urls.py
Created August 8, 2012 15:21 — forked from macndesign/api_urls.py
Test: Making a CRUD using django + tastypie
from tastypie.api import Api
from basic.api.resources import NoteResource, UserResource
api = Api(api_name='v1')
api.register(NoteResource(), canonical=True)
api.register(UserResource(), canonical=True)
@gladson
gladson / json_response.py
Created August 7, 2012 00:23 — forked from macndesign/json_response.py
Serializar detalhamento ou listagem de dados customizados em json com CBV
# API JSON
from django.http import HttpResponse
from django.utils import simplejson
from django.views.generic.detail import BaseDetailView
from django.views.generic.list import BaseListView
from django.db.models.query import QuerySet
class JSONResponseMixin(object):
def render_to_response(self, context):
return self.get_json_response(self.convert_context_to_json(context))
@gladson
gladson / gist:3228674
Created August 1, 2012 16:48 — forked from gmorada/gist:3228519
Helper para gerar relatório em pdf a partir de um html
from django.template.loader import get_template
from django.template import Context
import cStringIO as StringIO
import cgi
import ho.pisa as pisa
def render_to_pdf(template_src, context_dict):
template = get_template(template_src)
context = Context(context_dict)
html = template.render(context)