project/scipycon/talk/views.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Mon, 27 Dec 2010 03:51:41 +0530
changeset 369 7ea06f159d15
parent 156 fdbefef52e1c
child 371 f2b47f5dac06
permissions -rw-r--r--
Add the slides from the Conference and Tutorials to the new section.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
127
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
     1
from django.core.urlresolvers import reverse
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
     2
from django.contrib.auth.decorators import login_required
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
     3
from django.contrib.auth.forms import AuthenticationForm
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
     4
from django.contrib.auth.models import User
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
from django.shortcuts import render_to_response
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
from django.template import RequestContext
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
from django.views.generic.list_detail import object_list
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
from django.views.generic.list_detail import object_detail
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
from PIL import Image
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    12
from tagging.models import Tag
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
156
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    14
from project.scipycon.base.models import Event
127
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    15
from project.scipycon.talk.models import Talk
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    16
from project.scipycon.talk.forms import TalkSubmitForm
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    17
from project.scipycon.talk.forms import TalkEditForm
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    18
from project.scipycon.talk.models import DURATION_CHOICES
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    19
from project.scipycon.talk.models import AUDIENCE_CHOICES
96
178b89a3ca4f Removed unwanted files and made more changes to make SciPyCon a clean app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 94
diff changeset
    20
from project.scipycon.utils import set_message_cookie
178b89a3ca4f Removed unwanted files and made more changes to make SciPyCon a clean app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 94
diff changeset
    21
from project.scipycon.utils import slugify
178b89a3ca4f Removed unwanted files and made more changes to make SciPyCon a clean app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 94
diff changeset
    22
from project.scipycon.user.models import UserProfile
178b89a3ca4f Removed unwanted files and made more changes to make SciPyCon a clean app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 94
diff changeset
    23
from project.scipycon.user.forms import RegisterForm
178b89a3ca4f Removed unwanted files and made more changes to make SciPyCon a clean app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 94
diff changeset
    24
from project.scipycon.user.utils import scipycon_createuser
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
156
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    27
@login_required
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    28
def list_my_talks(request, scope, template_name='talk/list-talks.html'):
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    29
    """Lists all the talks for the user.
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    30
    """
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    31
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    32
    scope_entity = Event.objects.get(scope=scope)
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    33
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    34
    user = request.user
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    35
    if user.is_authenticated():
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    36
        try:
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    37
            profile = user.get_profile()
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    38
        except:
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    39
            profile, new = UserProfile.objects.get_or_create(
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    40
                user=user, scope=scope_entity)
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    41
            if new:
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    42
                profile.save()
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    43
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    44
    my_talks = user.talk_set.all()
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    45
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    46
    return render_to_response(template_name, RequestContext(request, {
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    47
        'params': {'scope': scope},
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    48
        'talk_list': my_talks,
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    49
    }))
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    50
127
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    51
def talk(request, scope, id):
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    52
    objects = Talk.objects.filter(approved=True)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    53
    audience = {}
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    54
    for choice in AUDIENCE_CHOICES:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    55
        audience[choice[0]] = choice[1]
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    56
    extra_context = dict(choices=audience)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    57
    return object_detail(request, objects, id, extra_context=extra_context)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    58
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    59
@login_required
127
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    60
def edit_talk(request, scope, id, template_name='talk/edit-talk.html'):
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    61
    """Allows users that submitted a talk to edit it until the talk is approved.
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    62
    """
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    63
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    64
    talk = Talk.objects.get(pk=id)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    65
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    66
    if talk.approved == True:
127
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    67
        redirect_to = reverse('scipycon_account', kwargs={'scope': scope})
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    68
        return set_message_cookie(redirect_to,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    69
                msg = u'Sorry but you cannot edit the talk once'\
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    70
                      + ' it has been accepted.')
127
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    71
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    72
    if talk.speaker != request.user:
127
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
    73
        redirect_to = reverse('scipycon_account', kwargs={'scope': scope})
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    74
        return set_message_cookie(redirect_to,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    75
                msg = u'Redirected to account because the talk you selected' \
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    76
                      + ' is not your own.')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    77
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    78
    if request.method == 'POST':
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    79
        form = TalkEditForm(data=request.POST)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    80
        if form.is_valid():
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    81
            talk.slug = slugify(form.data.get('title'))
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    82
            talk.authors_bio = form.data.get('authors_bio')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    83
            talk.contact = form.data.get('contact')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    84
            talk.title = form.data.get('title')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    85
            talk.abstract = form.data.get('abstract')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    86
            talk.topic = form.data.get('topic')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    87
            talk.duration = form.data.get('duration')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    88
            talk.audience = form.data.get('audience')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    89
            talk.save()
156
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    90
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    91
            # Saved.. redirect
156
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    92
            redirect_to = reverse('scipycon_edit_talk', 
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    93
                                  kwargs={'scope': scope, 'id': talk.id})
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    94
            return set_message_cookie(redirect_to,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    95
                    msg = u'Your changes have been saved.')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    96
    else:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    97
        form = TalkEditForm(initial={
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    98
                                    'id' : id,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    99
                                    'authors_bio' : talk.authors_bio,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   100
                                    'contact' : talk.contact,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   101
                                    'title' : talk.title,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   102
                                    'abstract' : talk.abstract,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   103
                                    'topic' : talk.topic,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   104
                                    'duration' : talk.duration,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   105
                                    'audience' : talk.audience,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   106
            })
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   107
156
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
   108
    context = locals()
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
   109
    context['params'] = {'scope': scope}
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
   110
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
   111
    return render_to_response(template_name, RequestContext(request, context))
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   112
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   113
@login_required()
127
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   114
def submit_talk(request, scope, template_name='talk/submit-talk.html'):
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   115
    """Allows user to edit profile
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   116
    """
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   117
156
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
   118
    scope_entity = Event.objects.get(scope=scope)
127
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   119
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   120
    user = request.user
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   121
    if user.is_authenticated():
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   122
        try:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   123
            profile = user.get_profile()
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   124
        except:
127
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   125
            profile, new = UserProfile.objects.get_or_create(
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   126
                user=user, scope=scope_entity)
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   127
            if new:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   128
                profile.save()
127
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   129
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   130
    message = None
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   131
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   132
    if request.method == 'POST':
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   133
        talk_form = TalkSubmitForm(data=request.POST)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   134
127
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   135
        register_form = RegisterForm(data=request.POST, files=request.FILES)
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   136
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   137
        if request.POST.get('action', None) == 'login':
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   138
            login_form = AuthenticationForm(data=request.POST)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   139
            if login_form.is_valid():
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   140
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   141
                from django.contrib.auth import login
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   142
                login(request, login_form.get_user())
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   143
127
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   144
                redirect_to = reverse('scipycon_submit_talk',
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   145
                                      kwargs={'scope': scope})
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   146
                return set_message_cookie(redirect_to,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   147
                        msg = u'You have been logged in.')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   148
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   149
        if request.POST.get('action', None) == 'register':
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   150
            # add the new user
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   151
            if register_form.is_valid():
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   152
96
178b89a3ca4f Removed unwanted files and made more changes to make SciPyCon a clean app.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 94
diff changeset
   153
                user = scipycon_createuser(request, register_form.data)
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   154
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   155
        if talk_form.is_valid():
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   156
            if user.is_authenticated():
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   157
                title = talk_form.data.get('title')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   158
                talk = Talk.objects.create(
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   159
                    slug = slugify(title),
156
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
   160
                    scope = scope_entity,
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   161
                    speaker = User.objects.get(pk=user.id),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   162
                    authors_bio = talk_form.data.get('authors_bio'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   163
                    contact = talk_form.data.get('contact'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   164
                    title = talk_form.data.get('title'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   165
                    abstract = talk_form.data.get('abstract'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   166
                    topic = talk_form.data.get('topic'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   167
                    duration = talk_form.data.get('duration'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   168
                    audience = talk_form.data.get('audience'),
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   169
                    approved = False,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   170
#                    tags = talk_form.data.get('tags')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   171
                    )
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   172
                talk.save()
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   173
                # Saved, ... redirect back to account
156
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
   174
                redirect_to = reverse('scipycon_edit_talk', 
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
   175
                                      kwargs={'scope': scope, 'id': talk.id})
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   176
                return set_message_cookie(redirect_to,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   177
                        msg = u'Thanks, your talk has been submitted.')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   178
            else:
127
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   179
                redirect_to = reverse('scipycon_submit_talk',
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   180
                                      kwargs={'scope': scope})
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   181
                return set_message_cookie(redirect_to,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   182
                        msg = u'Something is wrong here.')
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   183
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   184
    else:
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   185
        talk_form = TalkSubmitForm()
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   186
        register_form = RegisterForm()
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   187
    login_form = AuthenticationForm()
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   188
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   189
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   190
    return render_to_response(template_name, RequestContext(request, {
156
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
   191
        'params': {'scope': scope},
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   192
        'talk_form': talk_form,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   193
        'register_form' : register_form,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   194
        'message' : message,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   195
        'login_form' : login_form
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   196
    }))
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   197
127
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   198
def list_talks(request, scope, template_name='talk/list-all-talks.html'):
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   199
    """List all the tasks submitted by a user.
328b5244aa1c Add scope as a parameter to all view functions for talks app and adjusted the URLs to accommodate scope.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 96
diff changeset
   200
    """
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   201
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   202
    talks = Talk.objects.filter(approved=True)
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   203
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   204
    return render_to_response(template_name, RequestContext(request, {
156
fdbefef52e1c Add scope to context params and list my talks method.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
   205
        'params': {'scope': scope},
94
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   206
        'talk_list': talks,
87e77aa18610 Moved the files to new Django app named scipycon and modified settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   207
    }))
369
7ea06f159d15 Add the slides from the Conference and Tutorials to the new section.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 156
diff changeset
   208
7ea06f159d15 Add the slides from the Conference and Tutorials to the new section.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 156
diff changeset
   209
def download_slides(request, scope):
7ea06f159d15 Add the slides from the Conference and Tutorials to the new section.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 156
diff changeset
   210
    """View that lets users allow to download the slides they want.
7ea06f159d15 Add the slides from the Conference and Tutorials to the new section.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 156
diff changeset
   211
    """
7ea06f159d15 Add the slides from the Conference and Tutorials to the new section.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 156
diff changeset
   212
7ea06f159d15 Add the slides from the Conference and Tutorials to the new section.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 156
diff changeset
   213
    template_name = 'talk/download-slides.html'
7ea06f159d15 Add the slides from the Conference and Tutorials to the new section.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 156
diff changeset
   214
    return render_to_response(template_name, RequestContext(request, {
7ea06f159d15 Add the slides from the Conference and Tutorials to the new section.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 156
diff changeset
   215
        'params': {'scope': scope},
7ea06f159d15 Add the slides from the Conference and Tutorials to the new section.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 156
diff changeset
   216
    }))