Skip to content

Instantly share code, notes, and snippets.

@mitgr81
Created May 10, 2013 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitgr81/5556319 to your computer and use it in GitHub Desktop.
Save mitgr81/5556319 to your computer and use it in GitHub Desktop.
Drupal authorization in django-tastypie
from django.db import models
class Sessions(models.Model):
id = models.IntegerField(primary_key=True, db_column='uid')
session_id = models.CharField(max_length=64, db_column='sid')
class Meta:
db_table = u'sessions'
managed = False # Don't let Django create the tables for this model.
from tastypie.authorization import Authorization
from drupal_models import Sessions
class HackyDrupalAuthorization(Authorization):
def __get_uid(self, bundle):
for name, cookie in bundle.request.COOKIES.items():
if "SESS" not in name:
continue
sess = Sessions.objects.using('__name_of_your_drupal_database_in_settings__').filter(sid=cookie)
if sess:
uid = sess[0].uid
break
else:
uid = 0
return uid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment