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 | |
# -*- coding: utf-8 -*- | |
# This I found years ago, floating around django snippets. | |
# If anyone knows the proper attribution, please email me | |
# at steven@agoodclooud.com, and I'll update t! | |
# | |
import re | |
from types import UnicodeType |
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 | |
# -*- coding: utf-8 -*- | |
from django.views.generic import TemplateView | |
urlpatterns += patterns('', | |
url(r'^robots\.txt$', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')), | |
) |
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 | |
# -*- coding: utf-8 -*- | |
from django.core.exceptions import ObjectDoesNotExist | |
from django.http import Http404 | |
class DoesNotExistTo404Middleware(object): | |
def process_exception(self, request, exception): | |
if isinstance(exception,ObjectDoesNotExist): | |
raise Http404(exception.message) |
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 datetime import date | |
def calculate_age(born): | |
today = date.today() | |
try: | |
birthday = born.replace(year=today.year) | |
except ValueError: # raised when birth date is February 29 and the current year is not a leap year | |
birthday = born.replace(year=today.year, day=born.day-1) | |
if birthday > today: | |
return today.year - born.year - 1 |
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 | |
# -*- coding: utf-8 -*- | |
from django import template | |
register = template.Library() | |
from django.utils.encoding import smart_unicode | |
def _verifier(rut): | |
rut = smart_unicode(rut).replace(' ', '').replace('.', '').replace('-', '') |
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
# Download Command Line Tools (OS X Mavericks) for Xcode | |
# https://developer.apple.com/downloads/index.action | |
# You can setting the following environment variables prior compilation (.bash_profile or .bashrc): | |
export CFLAGS=-Qunused-arguments | |
export CPPFLAGS=-Qunused-arguments | |
pip install psycopg2 |
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 | |
# -*- coding: utf-8 -*- | |
from django import template | |
register = template.Library() | |
@register.filter(name='round_step') | |
def round_step(x, base=5): | |
return int(base * round(float(x)/base)) |
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
ssh-keygen -b 4096 -t rsa | |
ssh-copy-id user@server |
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 validators import MimetypeValidator | |
class MyForm(forms.Form): | |
file = forms.FileField( | |
allow_empty_file=False, | |
validators=[MimetypeValidator('application/pdf')], | |
help_text="Upload a PDF file" | |
) |
OlderNewer