Skip to content

Instantly share code, notes, and snippets.

import re
from django.utils.cache import patch_vary_headers
from django.utils import translation
from django.conf import settings
from cms.utils.i18n import get_default_language
class StripGoogleAnalyticsCookieMiddleware(object):
"""
This middleware class is there to make sure that the cookies from
Google Analitics does not force django to recompute this page.
@yml
yml / usd_rates.py
Created April 25, 2011 09:08
This gist use the Yahoo web services to extract the currency rate for 1 USD.
#!/usr/bin/env python
from datetime import datetime
import json
from urllib import urlopen
YAHOO_CURRENCY_CONVERTER = 'http://finance.yahoo.com/connection/currency-converter-cache?date='
class CurrencyCoverterException(Exception):
def __init__(self, value):
@yml
yml / tasks.py
Created July 26, 2012 13:17
Background tasks to be run either by uwsgi, or directly if on dev server.
"""Background tasks to be run either by uwsgi, or directly if on dev server.
"""
import cPickle as pickle
import logging
from django.core.mail import send_mail
LOG = logging.getLogger(__name__)
HAS_UWSGI = False
from picocms.models import CMSModel, CMSCategory, ActiveModelManager
from picocms import fields
ARTICLES_ROOT = 'Publications'
class Article(CMSModel):
""" Defines an article for the CMS """
date_display = models.DateTimeField(default=datetime.datetime.now()) #:
highlight = models.BooleanField(default=False, verbose_name=u'Highlight') #:
from picocms.models import CMSModel, CMSCategory, ActiveModelManager
from picocms import fields
ARTICLES_ROOT = 'Publications'
class Article(CMSModel):
""" Defines an article for the CMS """
date_display = models.DateTimeField(default=datetime.datetime.now()) #:
highlight = models.BooleanField(default=False, verbose_name=u'Highlight') #:
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>RSS Example</title>
<description>This is an example of an RSS feed</description>
<link>http://www.domain.com/link.htm</link>
<lastBuildDate>Mon, 28 Aug 2006 11:12:55 -0400 </lastBuildDate>
<pubDate>Tue, 29 Aug 2006 09:00:00 -0400</pubDate>
import json
from logging import Formatter
class JSONStreamFormatter(Formatter):
def format(self, record):
"""
Format the specified record as text.
The record's attribute dictionary is used as the operand to a
string formatting operation which yields the returned string.