Skip to content

Instantly share code, notes, and snippets.

View joshourisman's full-sized avatar

Josh Ourisman joshourisman

View GitHub Profile
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":
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
@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,
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')
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 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):
import djcelery
djcelery.setup_loader()
import redis
import tweepy
from twitpop.tasks import score_tweet
db = redis.Redis(host='localhost', port=6379, db=0)
import os
import sublime
import sublime_plugin
class Pep8CheckCommand(sublime_plugin.EventListener):
def on_post_save(self, view):
if view.file_name().endswith('.py'):
folder_name, file_name = os.path.split(view.file_name())
view.window().run_command('exec', {'cmd': ['flake8',
class RingtoneDetailView(SingleObjectTemplateResponseMixin, ChooseTemplateMixin, SingleObjectMixin, FormMixin, TemplateResponseMixin, ProcessFormView):
model = Ringtone
form_class = RingtoneForm
def dispatch(self, *args, **kwargs):
request = args[0]
device_info = choose_site(request)
self.site_type = device_info['site_type']
self.device = device_info['device']
return super(RingtoneDetailView, self).dispatch(*args, **kwargs)
from django.conf.urls.defaults import *
from views import ApprovedStoryList, CreateStory
urlpatterns = patterns(
'',
(r'^$', ApprovedStoryList.as_view()),
(r'^share/$', CreateStory.as_view()),
)