simplify creation of SecurityTokens
authorStefan Koegl <stefan@skoegl.net>
Sat, 18 Sep 2010 15:45:05 +0000 (18 18:45 +0300)
committerStefan Koegl <stefan@skoegl.net>
Sun, 19 Sep 2010 06:06:07 +0000 (19 09:06 +0300)
mygpo/decorators.py
mygpo/web/views/episode.py

index 3c9530e..c5b8c0f 100644 (file)
@@ -22,8 +22,6 @@ from django.template import RequestContext
 from mygpo.web.models import SecurityToken
 from django.contrib.auth.models import User
 from django.http import HttpResponseForbidden, HttpResponseNotAllowed
-import random
-import string
 import gc
 
 def requires_token(object, action, denied_template=None):
@@ -45,8 +43,7 @@ def requires_token(object, action, denied_template=None):
         def tmp(request, username, *args, **kwargs):
 
             user = get_object_or_404(User, username=username)
-            token, c = SecurityToken.objects.get_or_create(user=user, object=object, action=action,
-                        defaults = {'token': "".join(random.sample(string.letters+string.digits, 32))})
+            token, c = SecurityToken.objects.get_or_create(user=user, object=object, action=action)
 
             u_token = request.GET.get('token', '')
 
index b944849..224a604 100644 (file)
@@ -28,8 +28,6 @@ from mygpo.utils import parse_time
 from django.contrib.auth.decorators import login_required
 from django.shortcuts import get_object_or_404
 from django.contrib.sites.models import Site
-import random
-import string
 
 @manual_gc
 def episode(request, id):
@@ -114,8 +112,7 @@ def list_favorites(request):
     site = Site.objects.get_current()
     episodes = [x.episode for x in EpisodeFavorite.objects.filter(user=request.user).order_by('-created')]
 
-    token, c = SecurityToken.objects.get_or_create(user=request.user, object='fav-feed', action='r', \
-        defaults={'token': "".join(random.sample(string.letters+string.digits, 8))})
+    token, c = SecurityToken.objects.get_or_create(user=request.user, object='fav-feed', action='r')
 
     from django.core.urlresolvers import reverse
     feed_url = 'http://%s/%s' % (site.domain, reverse('favorites-feed', args=[request.user.username]))