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
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] }); | |
} | |
} |
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 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) |
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.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 |
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 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)) |