author | Madhusudan.C.S <madhusudancs@gmail.com> |
Tue, 11 May 2010 03:48:47 +0530 | |
changeset 96 | 3ece0de11641 |
parent 94 | e86755df35da |
child 101 | fb27be005a5c |
permissions | -rw-r--r-- |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
2 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
3 |
import os |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
4 |
|
87
1ec579a679e4
Added two models, Paper and Attachments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
84
diff
changeset
|
5 |
from django.contrib.auth import login |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
6 |
from django.contrib.auth.decorators import login_required |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
7 |
from django.contrib.auth.forms import AuthenticationForm |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
8 |
from django.contrib.auth.models import User |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
9 |
from django.core.urlresolvers import reverse |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
10 |
from django.shortcuts import render_to_response |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
11 |
from django.template import RequestContext |
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
12 |
from django.utils import simplejson as json |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
13 |
|
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
14 |
from project.kiwipycon.proceedings.booklet import mk_scipy_paper |
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
15 |
from project.kiwipycon.proceedings.forms import ProceedingsForm |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
16 |
from project.kiwipycon.proceedings.models import Paper |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
17 |
from project.kiwipycon.user.forms import RegisterForm |
90
587e9c025c73
Added UserProfile import which was missing to Proceedings views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
87
diff
changeset
|
18 |
from project.kiwipycon.user.models import UserProfile |
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
19 |
from project.kiwipycon.user.utils import kiwipycon_createuser |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
20 |
from project.kiwipycon.utils import set_message_cookie |
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
21 |
from project import settings |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
22 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
23 |
|
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
24 |
def handleUploadedFile(proceedings_form_data, rst_file): |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
25 |
"""Handles the uploaded file content and process the form |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
26 |
""" |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
27 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
28 |
title = proceedings_form_data.get('title') |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
29 |
abstract = proceedings_form_data.get('abstract') |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
30 |
body = proceedings_form_data.get('body') |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
31 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
32 |
if rst_file: |
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
33 |
# TODO: using stating only for testing purposes. |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
34 |
destination = open('some/file/name.txt', 'wb+') |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
35 |
for chunk in rst_file.chunks(): |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
36 |
destination.write(chunk) |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
37 |
destination.close() |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
38 |
|
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
39 |
return title, abstract, body |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
40 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
41 |
|
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
42 |
@login_required |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
43 |
def submit(request, id=None, template='proceedings/submit.html'): |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
44 |
"""View to submit the proceedings paper. |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
45 |
""" |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
46 |
|
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
47 |
context = RequestContext(request, {}) |
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
48 |
|
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
49 |
user = request.user |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
50 |
if user.is_authenticated(): |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
51 |
try: |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
52 |
profile = user.get_profile() |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
53 |
except: |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
54 |
profile, new = UserProfile.objects.get_or_create(user=user) |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
55 |
if new: |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
56 |
profile.save() |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
57 |
message = None |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
58 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
59 |
if request.method == 'POST': |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
60 |
register_form = RegisterForm(data=request.POST) |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
61 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
62 |
if request.POST.get('action', None) == 'login': |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
63 |
login_form = AuthenticationForm(data=request.POST) |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
64 |
if login_form.is_valid(): |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
65 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
66 |
login(request, login_form.get_user()) |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
67 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
68 |
redirect_to = reverse('kiwipycon_submit_proceedings') |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
69 |
return set_message_cookie(redirect_to, |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
70 |
msg = u'You have been logged in.') |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
71 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
72 |
if request.POST.get('action', None) == 'register': |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
73 |
# add the new user |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
74 |
if register_form.is_valid(): |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
75 |
user = kiwipycon_createuser(request, register_form.data) |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
76 |
|
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
77 |
proceedings_form = ProceedingsForm(data=request.POST, |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
78 |
files=request.FILES) |
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
79 |
|
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
80 |
if proceedings_form.is_valid(): |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
81 |
if user.is_authenticated(): |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
82 |
# Data from reSt file is appended to the data in fields |
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
83 |
title, abstract, body = handleUploadedFile( |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
84 |
proceedings_form.cleaned_data, request.FILES.get('file')) |
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
85 |
authors = request.POST.get('as_values_authors') |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
86 |
|
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
87 |
paper = edit(id, title=title, |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
88 |
abstract=abstract, body=body, |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
89 |
authors=authors) if id else create(title=title, |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
90 |
abstract=abstract, body=body, |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
91 |
authors=authors) |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
92 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
93 |
# Successfully saved. So get back to the edit page. |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
94 |
redirect_to = reverse('kiwipycon_submit_proceedings', |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
95 |
args=[paper.id]) |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
96 |
return set_message_cookie( |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
97 |
redirect_to, msg = u'Thanks, your paper has been submitted.') |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
98 |
else: |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
99 |
# This is impossible. Something was wrong so return back |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
100 |
# to submit page |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
101 |
redirect_to = reverse('kiwipycon_submit_proceedings') |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
102 |
return set_message_cookie( |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
103 |
redirect_to, msg = u'Something is wrong here.') |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
104 |
else: |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
105 |
if id: |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
106 |
# If id exists initialize the form with old values |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
107 |
paper = Paper.objects.get(id=id) |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
108 |
proceedings_form = ProceedingsForm( |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
109 |
initial={'title': paper.title, |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
110 |
'abstract': paper.abstract, |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
111 |
'body': paper.body, |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
112 |
}) |
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
113 |
context['initial_authors'] = json.dumps([ |
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
114 |
{'name': str(author.username), |
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
115 |
'value': '%s (%s)' % (author.get_full_name(), author.username) |
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
116 |
} for author in paper.authors.all()]) |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
117 |
else: |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
118 |
# Otherwise create a new form |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
119 |
proceedings_form = ProceedingsForm() |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
120 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
121 |
register_form = RegisterForm() |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
122 |
login_form = AuthenticationForm() |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
123 |
|
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
124 |
context['proceedings_form'] = proceedings_form |
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
125 |
context['register_form'] = register_form |
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
126 |
context['message'] = message |
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
127 |
context['login_form'] = login_form |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
128 |
context['id'] = id if id else None |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
129 |
|
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
130 |
return render_to_response(template, context) |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
131 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
132 |
|
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
133 |
def create(**kwargs): |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
134 |
"""View to create a new proceedings. |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
135 |
""" |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
136 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
137 |
title = kwargs.get('title') |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
138 |
abstract = kwargs.get('abstract') |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
139 |
body = kwargs.get('body') |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
140 |
authors = kwargs.get('authors') |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
141 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
142 |
paper = Paper(title=title, abstract=abstract, body=body) |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
143 |
paper.save() |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
144 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
145 |
if authors: |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
146 |
authors = authors.split(',') |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
147 |
for author in authors: |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
148 |
user = User.objects.get(username=author.strip()) |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
149 |
paper.authors.add(user) |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
150 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
151 |
return paper |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
152 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
153 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
154 |
def edit(id, **kwargs): |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
155 |
"""View to edit the proceedings paper. |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
156 |
""" |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
157 |
|
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
158 |
paper = Paper.objects.get(id=id) |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
159 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
160 |
paper.title = kwargs.get('title') |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
161 |
paper.abstract = kwargs.get('abstract') |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
162 |
paper.body = kwargs.get('body') |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
163 |
authors = kwargs.get('authors') |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
164 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
165 |
if authors: |
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
166 |
authors = authors.strip(' ,').split(',') |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
167 |
for author in authors: |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
168 |
user = User.objects.get(username=author.strip()) |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
169 |
paper.authors.add(user) |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
170 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
171 |
paper.save() |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
172 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
173 |
return paper |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
174 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
175 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
176 |
def show_paper(request, id): |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
177 |
"""Display the thumbnail of the rendered paper for download |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
178 |
""" |
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
179 |
|
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
180 |
paper = Paper.objects.get(id=id) |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
181 |
|
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
182 |
# TODO: Address and country should be required field in the user forms |
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
183 |
# henceforth. Also contact numbers. |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
184 |
paper_data = { |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
185 |
'paper_abstract': paper.abstract, |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
186 |
'authors': [ |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
187 |
{'first_names': author.first_name, |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
188 |
'surname': author.last_name, |
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
189 |
'address': 'None', |
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
190 |
'country': 'India', |
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
191 |
'email_address': author.email, |
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
192 |
'institution': author.registration_set.get().organisation, |
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
193 |
'city': author.registration_set.get().city |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
194 |
} for author in paper.authors.all()], |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
195 |
'title': paper.title |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
196 |
} |
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
197 |
|
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
198 |
abstract = mk_scipy_paper.Bunch(**paper_data) |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
199 |
abstract.authors = [mk_scipy_paper.Bunch(**a) for a in abstract.authors] |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
200 |
|
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
201 |
abstract['paper_text'] = paper.body |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
202 |
|
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
203 |
out_dir = attach_dir = os.path.join(settings.STATIC_ROOT, |
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
204 |
'proceedings', 'output') |
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
205 |
outfilename = os.path.join(out_dir, 'paper%d.pdf' % (paper.id)) |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
206 |
mk_scipy_paper.mk_abstract_preview(abstract, outfilename, attach_dir) |
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
207 |
|
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
208 |
context = {'paper_id': paper.id, |
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
209 |
'out_path': '/static/proceedings/output' } |
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
210 |
template = 'proceedings/show_paper_preview.html' |
94
e86755df35da
Add admin interface and views for proceedings. Booklet is also setup to generate paper.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
90
diff
changeset
|
211 |
|
96
3ece0de11641
Modify views and templates for proceedings to work.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
94
diff
changeset
|
212 |
return render_to_response(template, context) |