This file contains 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
def sort_by_keylist(objects, attr, keylist): | |
indexes = dict([(x, i) for i, x in enumerate(keylist)]) | |
return sorted(objects, key=lambda x: indexes.get(getattr(x, attr))) |
This file contains 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 TagCloser(HTMLParser): | |
""" | |
HTMLParser that closes open tags. Call close_tags with a HTML | |
string arg which returns it with any required closing tags | |
appended. | |
""" | |
def __init__(self): | |
HTMLParser.__init__(self) | |
self.tags = [] |
This file contains 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
#!/usr/bin/env python | |
import os | |
cwd = os.path.abspath(os.getcwd()) | |
for project in os.listdir("."): | |
path = os.path.join(cwd, project) | |
if not os.path.isdir(path): |
This file contains 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 collections import namedtuple | |
from django.test import TestCase | |
from requests.auth import HTTPBasicAuth | |
import slumber | |
class SlumberTestClientAPI(slumber.API): | |
""" | |
Subclass of ``slumber.API`` that patches ``requests.request`` |
This file contains 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
#!/usr/bin/env python | |
""" | |
Given the current directory contains multiple repositories, each with a | |
requirements/project.txt file, build a report of all requirements. | |
""" | |
import os | |
reqs = {} |
This file contains 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 os | |
translators = [] | |
languages = [] | |
for root, dirs, files in os.walk("mezz_current/mezzanine"): | |
if root.endswith("locale"): | |
languages.extend(dirs) | |
for name in files: | |
if name == "django.po": |
This file contains 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
#!/usr/bin/env python | |
import os | |
import sys | |
import urllib | |
name, url, num = sys.argv[1:] | |
print name, url, num | |
first = not os.path.exists("output.csv") | |
f = open("output.csv", "a") |
This file contains 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.utils.encoding import force_unicode | |
from django.utils.functional import Promise | |
def deep_force_unicode(value): | |
""" | |
Recursively call force_unicode on value. | |
""" | |
if isinstance(value (list, tuple, set)): | |
value = type(value)(map(deep_force_unicode, value)) | |
elif isinstance(value, dict): |
This file contains 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 cgi | |
import getpass | |
import mechanize | |
import json | |
import SimpleHTTPServer | |
import SocketServer | |
import uuid | |
This file contains 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 unicodedata import bidirectional | |
from django.template.defaultfilters import striptags | |
from rest_framework import serializers | |
class RTLField(serializers.BooleanField): | |
def __init__(self, *args, **kwargs): | |
kwargs.setdefault("read_only", True) | |
super(RTLField, self).__init__(*args, **kwargs) |