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.template.defaultfilters import pluralize | |
| from datetime import datetime | |
| from dateutil import parser # http://labix.org/python-dateutil | |
| from pytz import timezone # http://pytz.sourceforge.net/ | |
| from math import floor | |
| register = template.Library() |
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 InactivityLogout(object): | |
| def process_request( self, request ): | |
| from datetime import datetime, timedelta | |
| from django.conf import settings | |
| COOKIE_AGE = getattr(settings, 'SESSION_COOKIE_AGE', 7200) | |
| if datetime.now() – request.session.get_expiry_date() < timedelta(seconds = COOKIE_AGE): | |
| request.session.set_expiry(datetime.now() + timedelta(seconds = COOKIE_AGE)) | |
| return None # pass through |
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
| # Requires BeautifulSoup | |
| class Ampersands(object): | |
| from BeautifulSoup import BeautifulSoup | |
| import re | |
| def process_response( self, request, response ): | |
| if response.has_header('Content-Type') and response['Content-Type'].startswith('text/html') and request.META['PATH_INFO'][0:7] != '/admin/': | |
| content = BeautifulSoup(response.content) | |
| try: | |
| for t in content.body.findAll(text = re.compile( r'.*&.*' )): |
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
| # for determining current file path in python | |
| import os | |
| here = lambda x: os.path.join(os.path.abspath(os.path.dirname(__file__)), x) |
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 | |
| # requires optipng library | |
| import os,optparse | |
| parser = optparse.OptionParser() | |
| parser.add_option('--file', '-f', default=False, help="The file to optimize. Omit to optimize all pngs in the current directory.") | |
| parser.add_option('--optimization', '-o', default=7, help="The optimatization level to run. Defaults to 7.") | |
| options,args = parser.parse_args() |
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 ErrorHandler(object): | |
| def process_response(self, request, response): | |
| status = response.status_code | |
| if status == 200: | |
| return response | |
| else: | |
| from django.http import HttpResponse | |
| from django.template import RequestContext, loader | |
| try: | |
| t = loader.get_template( u'%d.html' % status ) |
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.core.management import setup_environ | |
| import settings | |
| setup_environ(settings) | |
| # database backup routine | |
| def database_backup(): | |
| import tarfile,subprocess,tempfile,os,S3 | |
| from datetime import datetime |
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
| /* Convert Selection to Entities */ | |
| #!/usr/bin/env ruby | |
| $KCODE = 'U' | |
| $char_to_entity = { } | |
| File.open("#{ENV['TM_BUNDLE_SUPPORT']}/entities.txt").read.scan(/^(\d+)\t(.+)$/) do |key, value| | |
| $char_to_entity[[key.to_i].pack('U')] = value | |
| end | |
| def encode (text) | |
| text.gsub(/[^\x00-\x7F]|["'<>&]/) do |ch| |
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 Library | |
| from django.conf import settings | |
| from django.template.defaultfilters import slugify | |
| register = Library() | |
| def input_class(input): | |
| try: | |
| slug = slugify(input.field.widget.__class__.__name__.replace('Input','')) | |
| if hasattr(input.field.widget, 'attrs') and 'class' in input.field.widget.attrs: |
NewerOlder