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
--- misc.py~ 2010-10-25 14:07:30.000000000 +0300 | |
+++ misc.py 2010-10-25 14:13:56.000000000 +0300 | |
@@ -1,5 +1,6 @@ | |
from coffin import template | |
-from jinja2 import Markup | |
+from jinja2 import Markup, nodes | |
+from jinja2.ext import Extension | |
register = template.Library() | |
@register.filter(jinja2_only=True) |
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 coffin.template import Template as JTemplate | |
from django.template.loaders import app_directories, filesystem | |
from django.template import TemplateDoesNotExist | |
# integrate jinja instead of django template language to take advantage of | |
# all django helper function like direct_to_template | |
def _render_or_die(source, origin): | |
"""helper function for loaders below. Makes a simple check if | |
passed template seems to be jinja one and raising exception otherwise""" |
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.db.models.query import QuerySet | |
old_get = QuerySet.get | |
def new_get(self, *args, **kwargs): | |
if len(kwargs) == 1: | |
for field_name in kwargs: | |
if "__" in field_name: | |
field_name, kind = field_name.split("__") | |
if kind != 'exact': | |
continue |
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 amazonproduct import API | |
import os | |
from hashlib import md5 | |
old_fetch = API._fetch | |
old_build_url = API._build_url | |
old_init = API.__init__ | |
def new_fetch(self, url): |
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 os | |
from django.template.defaultfilters import slugify | |
try: # make it python2.4 compatible! | |
from hashlib import md5 | |
except: | |
import md5 | |
def picture_filename(path, field_name, field_to_slug = None): | |
def upload_to(instance, filename): |
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
old_iterator = QuerySet.iterator | |
def new_iterator(self): | |
def drilldown(node, negated): | |
NEGATE_TABLE = { | |
'exact': 'nexact', # bogus, I know | |
'lt': 'gte', | |
'lte': 'gt', | |
'gte': 'lt', | |
'gt': 'lte', |
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
{% macro render_pagination(pages) -%} | |
{% if pages.is_paginated %} | |
<div class="pagination"> | |
{% if pages.page_obj.has_previous() %} | |
<a href="?page={{ pages.page_obj.previous_page_number() }}{{ pages.getvars }}{{ pages.hashtag }}" class="prev">‹‹ previous</a> | |
{% else %} | |
<span class="disabled prev">‹‹ previous</span> | |
{% endif %} | |
{% for page in pages.pages %} | |
{% if 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
class FoobarManager(models.Manager): | |
def latest(self, limit=10): | |
""" more effecient version of query to avoid filesort """ | |
ids = list(self.values_list('id', flat=True).order_by('-created')[:limit]) | |
return self.filter(id__in=ids).extra( | |
select={'manual': 'FIELD(id,%s)' % ','.join(map(str, ids))}, | |
order_by=['manual']) |
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 | |
from MySQLdb import connect | |
from pyhs.manager import Manager | |
from hashlib import md5 | |
from datetime import datetime | |
DB_NAME = 'simple_test' | |
DB_USER = 'root' | |
DB_PASSWORD = '' |
OlderNewer