Skip to content

Instantly share code, notes, and snippets.

@jeanphix
jeanphix / gist:1408574
Created November 30, 2011 10:14
Django global user
# middlewares.py
import threading
_thread_locals = threading.local()
def get_current_user():
"""Returns the current user."""
return getattr(_thread_locals, 'user', None)
@jeanphix
jeanphix / gist:1406053
Created November 29, 2011 19:20
django testing with ghost.py
import unittest
import os
import django.core.handlers.wsgi
from ghost import GhostTestCase
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
app = django.core.handlers.wsgi.WSGIHandler()
@jeanphix
jeanphix / WTForms CountrySelectField
Created November 3, 2011 13:03
WTForms CountrySelectField
import pycountry
class CountrySelectField(SelectField):
def __init__(self, *args, **kwargs):
super(CountrySelectField, self).__init__(*args, **kwargs)
self.choices = [(c.alpha3, c.name) for c in pycountry.countries]