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
| #!/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 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
| #!/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 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 import template | |
| from django.utils.safestring import mark_safe | |
| register = template.Library() | |
| @register.filter(name='highlight') | |
| def highlight(text, word): | |
| return mark_safe(text.replace(word, "<span class='highlight'>%s</span>" % word)) | |
| """ |
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 logging | |
| logging.basicConfig(filename='db.log') | |
| logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) |
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
| <IfModule mod_rewrite.c> | |
| RewriteEngine on | |
| RewriteCond %{HTTP_USER_AGENT} "MSIE [6-8]" [NC] | |
| # RewriteRule (.*)\.html index.IE.html | |
| RewriteRule index\.html index.IE.html | |
| DirectoryIndex index.html | |
| </IfModule> |
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
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import re | |
| from django.utils.safestring import mark_safe | |
| from django import template | |
| register = template.Library() | |
| @register.filter(name='twitter_tags') |
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
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import json | |
| from functools import wraps | |
| from django.http import HttpResponse | |
| def render_to_json(**jsonargs): | |
| """ | |
| Renders a JSON response with a given returned instance. Assumes json.dumps() can |
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
| class BaseObject(models.Model): | |
| id = models.AutoField(primary_key=True) | |
| creation_datetime = models.DateTimeField(auto_now_add=True) | |
| update_datetime = models.DateTimeField(auto_now=True) | |
| class News(BaseObject): | |
| class Meta: | |
| managed = True | |
| db_table = 'news' |
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
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| from django.conf import settings | |
| from django.core.cache import cache | |
| from django.core.management.base import BaseCommand, CommandError | |
| class Command(BaseCommand): | |
| help = 'Fully clear your site-wide cache.' |
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
| class MyForm(forms.Form): | |
| """ | |
| Extend from this form so your widgets have an 'error' class if there's | |
| an error on the field. | |
| """ | |
| def __init__(self, *args, **kwargs): | |
| super(MyForm, self).__init__(*args, **kwargs) | |
| if self.errors: | |
| for f_name in self.fields: | |
| if f_name in self.errors: |