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.contrib.auth.tests.custom_user import ExtensionUser | |
| from django.contrib.auth.forms import UserCreationForm | |
| from django.test import TestCase | |
| from django.test.utils import override_settings | |
| class CustomUserCreationForm(UserCreationForm): | |
| class Meta(UserCreationForm.Meta): | |
| model = ExtensionUser |
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
| # found by frequant on #django | |
| class BaseRatingModel(models.Model): | |
| """ | |
| Base rating model | |
| """ | |
| content_type = models.ForeignKey(ContentType) | |
| object_id = models.PositiveIntegerField() | |
| content_object = generic.GenericForeignKey() | |
| user = models.ForeignKey(settings.AUTH_USER_MODEL) |
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
| Ingredients (~50 cookies): | |
| * 200g flour | |
| * 100g sugar | |
| * 100g butter | |
| * 1 egg | |
| * baking powder | |
| * Various fillings (chocolate chips, dried fruits, nuts, caramel, ...) | |
| Mix egg+sugar. Add flour+baking powder. Add melted butter. Add fillings. |
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
| # http://balettcipo.hu/hu/napi-menu | |
| from lxml import html | |
| from textwrap import dedent | |
| import sys | |
| from base import get_weekday | |
| URL = 'http://balettcipo.hu/hu/napi-menu' | |
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
| # models.py | |
| from django.db import models | |
| class Foo(models.Model): | |
| pass | |
| class Bar(models.Model): | |
| foo = models.ForeignKey(Foo) |
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
| import re | |
| from django import template | |
| register = template.Library() | |
| UNICODE_ESCAPE_SEQ = re.compile(r'\\x([0-9a-f]{2}) | |
| @register.filter |
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 collections import namedtuple | |
| FrenchSSNTuple = namedtuple('FrenchSSNTuple', [ | |
| 'sex', | |
| 'year', | |
| 'month', | |
| 'departement', | |
| 'city', | |
| 'country', | |
| 'id_month_city', |
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 get_identifiers(tpl): | |
| identifiers = [] | |
| for match in tpl.pattern.finditer(tpl.template): | |
| d = match.groupdict() | |
| identifier = d['named'] or d['braced'] | |
| if identifier: | |
| identifiers.append(identifier) | |
| return identifiers |
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
| import itertools | |
| from string import ascii_letters | |
| import sys | |
| def collisions(alphabet=ascii_letters, n=6): | |
| d = {} | |
| for i in range(2, n): | |
| for comb in itertools.combinations_with_replacement(alphabet, i): | |
| w = ''.join(comb) |
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.template import Template, Context | |
| CONTEXT = Context({ | |
| 's': '', | |
| }) | |
| for tpl in [ | |
| '{% for x in s|add:"a b c" %}-{{ x }}{% endfor %}', # Doesn't work | |
| '{% with v=s|add:"a b c" %}{% for x in v %}-{{ x }}{% endfor %}{% endwith %}', | |
| '{% with v="a b c" %}{% for x in s|add:v %}-{{ x }}{% endfor %}{% endwith %}' |