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 / forms.py
Created July 17, 2012 18:41 — forked from douglasmiranda/forms.py
Implementando form de filtro numa ListView (Resposta para um tópico na Django Brasil)
# https://groups.google.com/forum/?fromgroups#!topic/django-brasil/d6gV1V9qrgU
from django.forms import ModelForm
from minha_app.models import MeuModel
class MeuForm(ModelForm):
class Meta:
model = MeuModel
@gladson
gladson / gist:3140945
Created July 19, 2012 05:25
using Class Based Generic ListView to seach forms and List
....
from django.views.generic import ListView
from sgf.utils.decorators import page, permission_required_sgf
from sgf.administrativo.models import ComiteRegional
from sgf.administrativo.forms import FormComiteRegionalBusca
......
class SearchListView(ListView):
@gladson
gladson / gist:3141041
Created July 19, 2012 05:51 — forked from idan/gist:3135754
A Sample Post

Hello there! This is a sample post for gist.io, a super-lightweight writing soapbox for hackers.

Now look up. Further. Above the post title. See that grey text with the gist ID?

Now back to me. That grey text is a link! Open that sucker in a new tab to see the source for this post. Also, I'm on a horse.

This is a major heading

If you peek at it with a web inspector, you'll see that it is a second-level heading. You can use first level headings, but they'll look just like the second level ones, and the gods of the HTML5 outlining algorithm will frown upon you.

@gladson
gladson / gist:3184030
Created July 26, 2012 19:31 — forked from fmobus/gist:1141019
class para comunicação com impressoras térmicas protocolo PPLA
DEVICE = "/dev/lp0";
STX = chr(2);
CR = chr(13);
LF = chr(10);
DEFAULTS = {
'ori': 4,
'font': 2,
'mh': 2,
'mv': 2,
@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)
@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 / 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 / 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 / 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 / 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)