Skip to content

Instantly share code, notes, and snippets.

View joshourisman's full-sized avatar

Josh Ourisman joshourisman

View GitHub Profile
import requests
import json
from django.http import HttpResponse
from django.views.generic import View
from disco_utils.views import JSONResponseMixin
class GetAlbumsView(JSONResponseMixin, View):
def dispatch(self, *args, **kwargs):
class FBObjectView(JSONResponseMixin, View):
BASE_URL = 'https://graph.facebook.com'
def dispatch(self, *args, **kwargs):
request = args[0]
self.profile = request.user.get_profile()
return super(FBObjectView, self).dispatch(*args, **kwargs)
def get(self, *args, **kwargs):
self.object = kwargs['id']
import json
from django.core.cache import get_cache
from django.utils import unittest
class CacheTestCase(unittest.TestCase):
def setUp(self):
self.cache = get_cache('default')
@joshourisman
joshourisman / models.py
Created January 31, 2012 20:34
I am a trained professional, don't try this at home!
class WeekDependentManager(models.Manager):
def get_filters(self, prefix=None):
if prefix is not None and prefix != '':
prefix = '%s__' % prefix
else:
prefix = ''
# All participating
filters = {
'%sweek__id' % prefix: settings.WEEK_ID,
from cachebuster.detectors import git
from django.template.loader import add_to_builtins
add_to_builtins('cachebuster.templatetags.cachebuster')
CACHEBUSTER_UNIQUE_STRING = git.unique_string(__file__)
CACHEBUSTER_PREPEND_STATIC = True
import random, string
from django.contrib.contenttypes.models import ContentType
def get_path(instance, filename):
ctype = ContentType.objects.get_for_model(instance)
model = ctype.model
app = ctype.app_label
extension = filename.split('.')[-1]
dir = "site"
if model == "job":
@joshourisman
joshourisman / gist:1918906
Created February 26, 2012 20:45 — forked from gsiegman/gist:1918836
Rounding with string homework
#Given a variable, x, that stores
#the value of any decimal number,
#write Python code that prints out
#the nearest whole number to x.
#You can assume x is not negative.
# x = 3.14159 -> 3 (not 3.0)
# x = 27.63 -> 28 (not 28.0)
filters = reduce(lambda x, y: x | y,
[Q(**{'account_name__istartswith': letter}) for
letter in letter_range])
return self.object.get_children().filter(filters)
<form method="POST" action="{% url accounts_admin_bulk_upload account.pk %}" enctype="multipart/form-data">
<input type="file" name="bulk" />
<input class="button" type="submit" name="" value="Bulk Upload Sub-accounts" />
</form>
>>> from django.conf import settings
>>> settings.DATABASES
{'default': {'ENGINE': 'django.db.backends.postgresql_psycopg2', 'TEST_MIRROR': None, 'NAME': '', 'TEST_CHARSET': None, 'TIME_ZONE': 'UTC', 'TEST_COLLATION': None, 'OPTIONS': {}, 'HOST': 'localhost', 'USER': None, 'TEST_NAME': None, 'PASSWORD': None, 'PORT': None}}