Skip to content

Instantly share code, notes, and snippets.

View svschannak's full-sized avatar

Sven Schannak svschannak

View GitHub Profile
class CORSResource(object):
"""
Adds CORS headers to resources that subclass this.
"""
def create_response(self, *args, **kwargs):
response = super(CORSResource, self).create_response(*args, **kwargs)
response['Access-Control-Allow-Origin'] = '*'
response['Access-Control-Allow-Headers'] = 'Content-Type'
return response
{{gravatar-image email="[email protected]"}}
from tastypie import fields
from tastypie.authentication import Authentication
from tastypie.authorization import Authorization
from tastypie.bundle import Bundle
from tastypie.exceptions import NotFound
from tastypie.resources import Resource
# a dummy class representing a row of data
class Row(object):
@svschannak
svschannak / rgb-cmyk-rgb-conversion
Created February 4, 2014 10:10
convert rgb to cmyk to rgb
def rgb_to_cmyk(r,g,b):
cmyk_scale = 100
if (r == 0) and (g == 0) and (b == 0):
# black
return 0, 0, 0, cmyk_scale
# rgb [0,255] -> cmy [0,1]
c = 1 - r / 255.
@svschannak
svschannak / create_password_for_nginx_auth.sh
Created January 27, 2014 10:35
create password for nginx_auth
printf "username:$(openssl passwd -crypt password)\n" >> htpasswd
def product_list(self):
products = self.products.all()
product_list = []
for product in products:
for product_store in product.stores_for_product.all():
product_list.append(product_store)
for cat in self.child_categories.all():
for product in cat.product_list():
product_list.append(product)
{{ reservation.datetime|date:'Y-m-d\TH:i:s' }}
@svschannak
svschannak / add_days.py
Created January 24, 2014 10:32
add days to datetime-object
self.datetime + datetime.timedelta(days=3)
from tastypie import fields
from tastypie.authentication import Authentication
from tastypie.authorization import Authorization
from tastypie.bundle import Bundle
from tastypie.exceptions import NotFound
from tastypie.resources import Resource
# a dummy class representing a row of data
class Row(object):
@svschannak
svschannak / api.py
Last active January 4, 2016 02:39 — forked from marteinn/api.py
from tastypie.exceptions import NotFound
from tastypie.resources import ModelResource
from tastypie.authentication import BasicAuthentication, ApiKeyAuthentication
from tastypie.models import ApiKey
from django.contrib.auth.models import User
__author__ = 'martinsandstrom'
class ApiTokenResource(ModelResource):