This file contains hidden or 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 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): |
This file contains hidden or 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 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'] |
This file contains hidden or 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 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') |
This file contains hidden or 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 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, |
This file contains hidden or 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 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 |
This file contains hidden or 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 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": |
This file contains hidden or 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
#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) |
This file contains hidden or 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
filters = reduce(lambda x, y: x | y, | |
[Q(**{'account_name__istartswith': letter}) for | |
letter in letter_range]) | |
return self.object.get_children().filter(filters) |
This file contains hidden or 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
<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> |
This file contains hidden or 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.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}} |