--- a/project/scipycon/talk/views.py Tue Jul 20 19:27:16 2010 +0530
+++ b/project/scipycon/talk/views.py Tue Jul 20 19:27:51 2010 +0530
@@ -1,46 +1,34 @@
-# -*- coding: utf-8 -*-
-from __future__ import absolute_import
-
-# python imports
-from urlparse import urlparse
-
-# django
-from django.conf import settings
+from django.core.urlresolvers import reverse
+from django.contrib.auth.decorators import login_required
+from django.contrib.auth.forms import AuthenticationForm
+from django.contrib.auth.models import User
from django.shortcuts import render_to_response
from django.template import RequestContext
-from django.core.urlresolvers import reverse
from django.views.generic.list_detail import object_list
from django.views.generic.list_detail import object_detail
-from django.contrib.auth.decorators import login_required
-from django.contrib.auth.forms import AuthenticationForm
-from django.contrib.auth.models import User
-
-# PIL
from PIL import Image
-# tagging
from tagging.models import Tag
-#scipycon
+from project.scipycon.talk.models import Talk
+from project.scipycon.talk.forms import TalkSubmitForm
+from project.scipycon.talk.forms import TalkEditForm
+from project.scipycon.talk.models import DURATION_CHOICES
+from project.scipycon.talk.models import AUDIENCE_CHOICES
from project.scipycon.utils import set_message_cookie
from project.scipycon.utils import slugify
from project.scipycon.user.models import UserProfile
from project.scipycon.user.forms import RegisterForm
from project.scipycon.user.utils import scipycon_createuser
-from .models import Talk
-from .forms import TalkSubmitForm
-from .forms import TalkEditForm
-from .models import DURATION_CHOICES
-from .models import AUDIENCE_CHOICES
-def list_talks(request):
+def list_talks(request, scope):
objects = Talk.objects.filter(approved=True)
extra_context = dict(count=objects.count())
return object_list(request, objects, extra_context=extra_context)
-def talk(request, id):
+def talk(request, scope, id):
objects = Talk.objects.filter(approved=True)
audience = {}
for choice in AUDIENCE_CHOICES:
@@ -49,18 +37,20 @@
return object_detail(request, objects, id, extra_context=extra_context)
@login_required
-def edit_talk(request, id, template_name='talk/edit-talk.html'):
- '''Allows users that submitted a talk to edit it until the talk is approved.
- '''
+def edit_talk(request, scope, id, template_name='talk/edit-talk.html'):
+ """Allows users that submitted a talk to edit it until the talk is approved.
+ """
+
talk = Talk.objects.get(pk=id)
if talk.approved == True:
- redirect_to = reverse('scipycon_account')
+ redirect_to = reverse('scipycon_account', kwargs={'scope': scope})
return set_message_cookie(redirect_to,
msg = u'Sorry but you cannot edit the talk once'\
+ ' it has been accepted.')
+
if talk.speaker != request.user:
- redirect_to = reverse('scipycon_account')
+ redirect_to = reverse('scipycon_account', kwargs={'scope': scope})
return set_message_cookie(redirect_to,
msg = u'Redirected to account because the talk you selected' \
+ ' is not your own.')
@@ -82,7 +72,7 @@
# talk.tags = form.data.get('tags')
talk.save()
# Saved.. redirect
- redirect_to = reverse('scipycon_account')
+ redirect_to = reverse('scipycon_account', kwargs={'scope': scope})
return set_message_cookie(redirect_to,
msg = u'Your changes have been saved.')
else:
@@ -104,24 +94,30 @@
return render_to_response(template_name, RequestContext(request, locals()))
@login_required()
-def submit_talk(request, template_name='talk/submit-talk.html'):
- '''Allows user to edit profile
- '''
+def submit_talk(request, scope, template_name='talk/submit-talk.html'):
+ """Allows user to edit profile
+ """
+
+ from project.scipycon.base.models import Event
+
user = request.user
if user.is_authenticated():
try:
profile = user.get_profile()
except:
- profile, new = UserProfile.objects.get_or_create(user=user)
+ scope_entity = Event.objects.get(scope=scope)
+
+ profile, new = UserProfile.objects.get_or_create(
+ user=user, scope=scope_entity)
if new:
profile.save()
+
message = None
if request.method == 'POST':
talk_form = TalkSubmitForm(data=request.POST)
- register_form = RegisterForm(data=request.POST,
- files=request.FILES)
+ register_form = RegisterForm(data=request.POST, files=request.FILES)
if request.POST.get('action', None) == 'login':
login_form = AuthenticationForm(data=request.POST)
@@ -130,7 +126,8 @@
from django.contrib.auth import login
login(request, login_form.get_user())
- redirect_to = reverse('scipycon_submit_talk')
+ redirect_to = reverse('scipycon_submit_talk',
+ kwargs={'scope': scope})
return set_message_cookie(redirect_to,
msg = u'You have been logged in.')
@@ -150,22 +147,21 @@
contact = talk_form.data.get('contact'),
title = talk_form.data.get('title'),
abstract = talk_form.data.get('abstract'),
-# outline = talk_form.data.get('outline'),
topic = talk_form.data.get('topic'),
-# topic_other = talk_form.data.get('topic_other'),
duration = talk_form.data.get('duration'),
audience = talk_form.data.get('audience'),
-# audience_other = talk_form.data.get('audience_other'),
approved = False,
# tags = talk_form.data.get('tags')
)
talk.save()
# Saved, ... redirect back to account
- redirect_to = reverse('scipycon_account')
+ redirect_to = reverse('scipycon_account',
+ kwargs={'scope': scope})
return set_message_cookie(redirect_to,
msg = u'Thanks, your talk has been submitted.')
else:
- redirect_to = reverse('scipycon_submit_talk')
+ redirect_to = reverse('scipycon_submit_talk',
+ kwargs={'scope': scope})
return set_message_cookie(redirect_to,
msg = u'Something is wrong here.')
@@ -182,9 +178,9 @@
'login_form' : login_form
}))
-def list_talks(request, template_name='talk/list-all-talks.html'):
- '''List all the tasks submitted by a user.
- '''
+def list_talks(request, scope, template_name='talk/list-all-talks.html'):
+ """List all the tasks submitted by a user.
+ """
talks = Talk.objects.filter(approved=True)