This file contains 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 teste(nome, idade): | |
... print nome, idade | |
... | |
>>> teste('andrews', 26) | |
andrews 26 | |
>>> teste(nome='andrews', idade=26) | |
andrews 26 | |
>>> lista = ['pacote', 200] | |
>>> teste(*lista) | |
pacote 200 |
This file contains 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
test: | |
clear | |
nosetests --with-coverage --cover-package slugfy test_slugfy.py | |
clean: | |
find -regex '.*\.pyc' -exec rm {} \; | |
find -regex '.*~' -exec rm {} \; | |
.PHONY: test clean |
This file contains 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.views.generic import View | |
from django.utils import simplejson | |
class JSONResponseView(View): | |
def render_to_response(self, data, **httpresponse_kwargs): | |
"Retuns a json response based on the context" | |
json_data = simplejson.dumps(data) | |
return HttpResponse(json_data, content_type="application/json", **httpresponse_kwargs) |
This file contains 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
#!/usr/bin/env python | |
import sys | |
import urllib2 | |
import json | |
from collections import defaultdict | |
from nltk import word_tokenize | |
IGNORED_WORDS = ["!", ".", ",", "(", ")", "'s", ":", "?", "...", "$", |
This file contains 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: utf8 -*- | |
from django.views.generic.edit import FormView | |
from django.core.urlresolvers import reverse | |
class FooFormView(FormView): | |
template_name = 'foo/foo_form.html' | |
form_class = FooForm |
This file contains 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.core.urlresolvers import reverse as r | |
# ... | |
class SubscribeViewTest(TestCase): | |
def setUp(self): | |
self.resp = self.client.get(r('subscriptions:subscribe')) | |
def test_get(self): | |
'Ao visitar /inscricao/ a página de inscrição é exibida' |
This file contains 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: utf8 -*- | |
from django import forms | |
from .models import Foo, Bar, FooBar | |
class FooModelForm(forms.ModelForm): | |
# Essa classe vai usar a instrospecção para gerar o formulário | |
# baseado nos atributos da classe Foo | |
class Meta: |
This file contains 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: utf8 -*- | |
import time, datetime | |
from datetime import date | |
from django import forms | |
from django.contrib.auth.models import User | |
from django.conf import settings | |
from bootstrap_toolkit.widgets import BootstrapDateInput |
This file contains 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
import requests | |
from lxml.html import fromstring | |
import os | |
def connect(url): | |
return requests.get(url) | |
def parser(page): |
This file contains 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.views.generic import ListView | |
from django.views.generic.edit import FormMixin | |
from django.db.models import Q | |
class SearchView(FormMixin, ListView): | |
template_name_suffix = '_search' | |
filter_operator = 'contains' | |
allow_or_operator = False | |
def get_filter_operator(self): |
OlderNewer