Skip to content

Instantly share code, notes, and snippets.

class InterfaceError(Exception):
pass
def Implements(*interfaces):
methods = [a for interface in interfaces for a in dir(interface) if not a.startswith('__')]
def _implements(original_class):
for method in methods:
if method not in dir(original_class):
raise InterfaceError("Class %s failed to implement %s" % (original_class, method))
@joelsemar
joelsemar / response.py
Created January 14, 2012 06:54
Response Object
from django.core import serializers
import simplejson
from django import dispatch
from django.core.serializers.json import DateTimeAwareJSONEncoder
from django.http import HttpResponse
from django.db import models
import utils
from xml.dom import minidom
from django.conf import settings
@joelsemar
joelsemar / decorators.py
Created January 16, 2012 07:27
auth decorator
def login_required(fn):
fn.authentication_required = True
@wraps(fn)
def inner(*args, **kwargs):
from webservice_tools.response_util import ResponseObject
response = ResponseObject()
try:
request = [a for a in args if hasattr(a, 'user')][0]
except IndexError:
return response.send(errors="Login required method called without request object", status=500)
function Template(string){
this.string = string;
this.render = function(){
var args = Array.prototype.slice.call(arguments);
if(args.length === 1 && typeof args[0] === 'object'){
return this.string.replace(/{([^}]*)}/gm, function(match,key) { return args[0][key] });
}
return this.string.replace(/\{(\d+)\}/g, function(match, idx){ return args[idx] });
}
}