summaryrefslogtreecommitdiff
path: root/website/views.py
blob: e684d95b28c6799430ecfd895854686a1b6c0d6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
# -*- coding: utf-8 -*-

from django.shortcuts import render
from django.utils.encoding import force_text
from django.contrib.contenttypes.models import ContentType
from django.template.context import RequestContext
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response, redirect
from django.views.decorators.csrf import csrf_exempt
from django.core.context_processors import csrf
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import User
from django.contrib.admin.models import CHANGE
from django.contrib.auth.decorators import login_required
from django.core.mail import send_mail
from django.db.models import F
import csv
from django.core.mail import EmailMultiAlternatives
import os

from website.forms import ProposalForm, UserRegisterForm, UserLoginForm, WorkshopForm, ContactForm
from website.models import Proposal, Comments, Ratings
from social.apps.django_app.default.models import UserSocialAuth
import random
import string


def userregister(request):
    context = {}
    context.update(csrf(request))
    registered_emails = []
    users = User.objects.all()
    for user in users:
        registered_emails.append(user.email)
    if request.user.is_anonymous():
        if request.method == 'POST':
            form = UserRegisterForm(request.POST)
            if form.is_valid():
                data = form.cleaned_data
                if data['email'] in registered_emails:
                    context['form'] = form
                    context['email_registered'] = True
                    return render_to_response('user-register.html', context)
                else:
                    form.save()
                    context['registration_complete'] = True
                    form = UserLoginForm()
                    context['form'] = form
                    context['user'] = request.user
                    return render_to_response('cfp.html', context)
            else:
                context.update(csrf(request))
                context['form'] = form
                return render_to_response('user-register.html', context)
        else:
            form = UserRegisterForm()
        context.update(csrf(request))
        context['form'] = form
        return render_to_response('user-register.html', context)
    else:
        context['user'] = request.user
        return render_to_response('cfp.html', context)

def contact_us(request,next_url):
    pass
    # user = request.user
    # context = {}
    # if request.method == "POST":
    #     form = ContactForm(request.POST)
    #     sender_name = request.POST['name']
    #     sender_email = request.POST['email']
    #     to = ('scipy@fossee.in',)
    #     subject = "Query from - "+sender_name
    #     message = request.POST['message']
    #     try:
    #         send_mail(subject, message, sender_email, to)
    #         context['mailsent'] = True
    #         context['user'] = user
    #     except:
    #         context['mailfailed'] = True
    #         context['user'] = user
    # return redirect(next_url,context)


def home(request):
    #pass
    context = {}
    if request.user.is_authenticated():
        social_user = request.user
        context.update(csrf(request))
        django_user = User.objects.get(username=social_user)
        context['user'] = django_user
    if request.method == "POST":
        sender_name = request.POST['name']
        sender_email = request.POST['email']
        to = ('scipy@fossee.in', sender_email)
        subject = "Query from - "+sender_name
        message = request.POST['message']
        try:
            send_mail(subject, message, sender_email, to)
            context['mailsent'] = True
        except:
            context['mailfailed'] = True
    return render_to_response('base.html', context)


def cfp(request):
    if request.method == "POST":
        context = {}
        context.update(csrf(request))
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        if user is not None:
            login(request, user)
            if 'next' in request.GET:
                next = request.GET['next']
                return HttpResponseRedirect(next)
            proposals = Proposal.objects.filter(user = request.user).count()
            context['user'] = user
            context['proposals'] = proposals
            return render_to_response('cfp.html', context)
        else:
            context['invalid'] = True
            context['form'] = UserLoginForm
            context['user'] = user
            return render_to_response('cfp.html', context)
    else:
        form = UserLoginForm()
        context = RequestContext(request, {'request': request,
                                           'user': request.user,
                                           'form': form})
        context.update(csrf(request))
        return render_to_response('cfp.html',
                             context_instance=context)

@login_required
def submitcfp(request):
    context = {}
    if request.user.is_authenticated():
        social_user = request.user
        context.update(csrf(request))
        django_user = User.objects.get(username=social_user)
        context['user'] = django_user
        proposals_a = Proposal.objects.filter(user = request.user, proposal_type = 'ABSTRACT').count()
        if request.method == 'POST':
            form = ProposalForm(request.POST, request.FILES)
            if form.is_valid():
                data = form.save(commit=False)
                data.user = django_user
                data.save()
                context['proposal_submit'] = True
                sender_name = "SciPy India 2016"
                sender_email = "scipy@fossee.in"
                subject = "SciPy India 2016 – Talk Proposal Submission Acknowledgment"
                to = (social_user.email, "scipy@fossee.in")
                message = """
                Dear {0}, <br><br>
                Thank you for showing interest & submitting a talk proposal at SciPy India 2016 conference for the talk titled <b>“{1}”</b>. Reviewal of the proposals will start once the CFP closes.
                <br><br>You will be notified regarding comments/selection/rejection of your talk via email.
                Visit this {2} link to view status of your submission.
                <br>Thank You ! <br><br>Regards,<br>SciPy India 2016,<br>FOSSEE - IIT Bombay.
                """.format(
                social_user.first_name,
                request.POST['title'],
                'http://scipy.in/2016/view-abstracts/',  )
                email = EmailMultiAlternatives(
                subject,'',
                sender_email, to,
                headers={"Content-type":"text/html;charset=iso-8859-1"}
                )
                email.attach_alternative(message, "text/html")
                email.send(fail_silently=True)
                return render_to_response('cfp.html', context)
            else:
                context['proposal_form'] =  form
                context['proposals_a'] = proposals_a
                return render_to_response('submit-cfp.html', context)
        else:
            form = ProposalForm()
            context['proposals_a'] = proposals_a 
            context['proposal_form'] = form
        return render_to_response('submit-cfp.html', context) #when link clicked
    else:
        context['login_required'] = True
        return render_to_response('cfp.html', context)


@login_required
def submitcfw(request):
    context = {}
    if request.user.is_authenticated():
        social_user = request.user
        context.update(csrf(request))
        django_user = User.objects.get(username=social_user)
        context['user'] = django_user
        proposals_w = Proposal.objects.filter(user = request.user, proposal_type = 'WORKSHOP').count()
        if request.method == 'POST':
            form = WorkshopForm(request.POST, request.FILES)
            if form.is_valid():
                data = form.save(commit=False)
                data.user = django_user
                data.save()
                context['proposal_submit'] = True
                sender_name = "SciPy India 2016"
                sender_email = "scipy@fossee.in"
                subject = "SciPy India 2016 – Workshop Proposal Submission Acknowledgment"
                to = (social_user.email, "scipy@fossee.in")
                message = """
                Dear {0}, <br><br>
                Thank you for showing interest & submitting a workshop proposal at SciPy India 2016 conference for the workshop titled <b>“{1}”</b>. Reviewal of the proposals will start once the CFP closes.
                <br><br>You will be notified regarding comments/selection/rejection of your workshop via email.
                Visit this {2} link to view status of your submission.
                <br>Thank You ! <br><br>Regards,<br>SciPy India 2016,<br>FOSSEE - IIT Bombay.
                """.format(
                social_user.first_name,
                request.POST['title'],
                'http://scipy.in/2016/view-abstracts/',  )
                email = EmailMultiAlternatives(
                subject,'',
                sender_email, to,
                headers={"Content-type":"text/html;charset=iso-8859-1"}
                )
                email.attach_alternative(message, "text/html")
                email.send(fail_silently=True)
                return render_to_response('cfp.html', context)
            else:
                context['proposal_form'] =  form
                context['proposals_w'] = proposals_w
                return render_to_response('submit-cfw.html', context)
        else:
            form = WorkshopForm()
            context['proposal_form'] = form
            context['proposals_w'] = proposals_w
        return render_to_response('submit-cfw.html', context)
    else:
        context['login_required'] = True
        return render_to_response('cfp.html', context)

@login_required
def view_abstracts(request):
    user = request.user
    context = {}
    count_list =[]
    if user.is_authenticated():
        if user.is_superuser :
            proposals = Proposal.objects.all().order_by('status')
            ratings = Ratings.objects.all()
            context['ratings'] = ratings
            context['proposals'] = proposals
            context['user'] = user
            return render(request, 'view-abstracts.html', context)
        elif user is not None:
            if Proposal.objects.filter(user = user).exists :
                proposals = Proposal.objects.filter(user = user).order_by('status')
                context['counts'] = count_list
                context['proposals'] = proposals
                context['user'] = user
            return render(request, 'view-abstracts.html', context)
        else:
            return render(request, 'cfp.html')
    else:
        return render(request, 'cfp.html', context)


@login_required
def edit_proposal(request, proposal_id = None):
    user = request.user
    context = {}
    if user.is_authenticated():
        proposal = Proposal.objects.get(id=proposal_id)
        if proposal.proposal_type == 'ABSTRACT':
            form = ProposalForm( instance=proposal)
        else:
            form = WorkshopForm( instance=proposal)
        if request.method == 'POST':
            if proposal.proposal_type == 'ABSTRACT':
                form = ProposalForm( request.POST, request.FILES, instance=proposal)
            else:
                form = WorkshopForm( request.POST, request.FILES, instance=proposal)
            if form.is_valid():
                data = form.save(commit = False)
                data.user = user
                proposal.status = 'Resubmitted'
                data.save()
                context.update(csrf(request))
                proposals = Proposal.objects.filter(user = user).order_by('status')
                context['proposals'] = proposals
                return render(request, 'view-abstracts.html', context)
            else:
                context['user'] = user
                context['form'] = form
                context['proposal'] = proposal
                return render(request, 'edit-proposal.html', context)
        context['user'] = user
        context['form'] = form
        context['proposal'] = proposal
    return render(request, 'edit-proposal.html', context)

@login_required
def abstract_details(request, proposal_id=None):
    user = request.user
    context = {}
    if user.is_authenticated():
        if user.is_superuser :
            proposals = Proposal.objects.all()
            context['proposals'] = proposals
            context['user'] = user
            return render(request, 'abstract_details.html', context)
        elif user is not None:
            proposal = Proposal.objects.get(id=proposal_id)
            print "------------------> owner",proposal.user
            if proposal.user == user:
                url = '/2016'+str(proposal.attachment.url) 
                comments = Comments.objects.filter(proposal=proposal)
                context['proposal'] = proposal
                context['user'] = user
                context['url'] = url
                context['comments'] = comments
                path, filename = os.path.split(str(proposal.attachment))
                context['filename'] = filename
                return render(request, 'abstract-details.html', context)
            else:
                return render(request, 'cfp.html', context)
    else:
        return render(request, 'cfp.html', context)


@login_required
def rate_proposal(request, proposal_id = None):
    user = request.user
    context = {}
    if user.is_authenticated():
        proposal = Proposal.objects.get(id=proposal_id)
        if request.method == 'POST':
            ratings = Ratings.objects.filter(proposal_id= proposal_id, user_id = user.id)
            if ratings:
                for rate in ratings:
                    rate.rating = request.POST['rating']
                    rate.save()
            else:
                newrate = Ratings()
                newrate.rating = request.POST['rating']
                newrate.user = user
                newrate.proposal = proposal
                newrate.save()
            rates = Ratings.objects.filter(proposal_id=proposal_id)
            comments = Comments.objects.filter(proposal=proposal)
            context['comments'] = comments
            context['proposal'] = proposal
            context['rates'] = rates
            context.update(csrf(request))
            return render(request, 'comment-abstract.html', context)
        else:
            rates = Ratings.objects.filter(proposal=proposal)
            comments = Comments.objects.filter(proposal=proposal)
            context['comments'] = comments
            context['proposal'] = proposal
            context['rates'] = rates
            context.update(csrf(request))
            return render(request, 'comment-abstract.html', context)
    else:
        return render(request, 'comment-abstract.html', context)



@login_required
def comment_abstract(request, proposal_id = None):
    user = request.user
    context = {}
    if user.is_authenticated():
        if user.is_superuser :
            proposal = Proposal.objects.get(id=proposal_id)
            url = '/2016'+str(proposal.attachment.url) 
            if request.method == 'POST':
                comment = Comments()
                comment.comment = request.POST['comment']
                comment.user = user
                comment.proposal = proposal
                comment.save()
                comments = Comments.objects.filter(proposal=proposal)
                sender_name = "SciPy India 2016"
                sender_email = "scipy@fossee.in"
                to = (proposal.user.email, "scipy@fossee.in" )
                if proposal.proposal_type == 'ABSTRACT':
                    subject = "SciPy India 216 - Comment on Your talk Proposal"
                    message = """
                        Dear {0}, <br><br>
                        There is a comment posted on your proposal for the talk titled <b>{1}</b>.<br>
                        Once we receive your response, you will be notified regarding further comments/acceptance/ rejection of your talk/workshop via email. 
                        Visit this link {2} to view comments on your submission.<br><br>
                        Thank You ! <br><br>Regards,<br>SciPy India 2016,<br>FOSSEE - IIT Bombay.
                        """.format(
                        proposal.user.first_name,
                        proposal.title, 
                        'http://scipy.in/2016/abstract-details/' + str(proposal.id),
                        )
                elif proposal.proposal_type =='WORKSHOP':
                    subject = "SciPy India 216 - Comment on Your Workshop Proposal"
                    message = """
                        Dear {0}, <br><br>
                        There is a comment posted on your proposal for the workshop titled <b>{1}</b>.<br>
                        Once we receive your response, you will be notified regarding further comments/acceptance/ rejection of your talk/workshop via email. 
                        Visit this {2} link to view comments on your submission.<br><br>
                        Thank You ! <br><br>Regards,<br>SciPy India 2016,<br>FOSSEE - IIT Bombay.
                        """.format(
                        proposal.user.first_name,
                        proposal.title, 
                        'http://scipy.in/2016/abstract-details/' + str(proposal.id),
                        )
                email = EmailMultiAlternatives(
                    subject,'',
                    sender_email, to,
                    headers={"Content-type":"text/html;charset=iso-8859-1"}
                )
                email.attach_alternative(message, "text/html")
                email.send(fail_silently=True)
                proposal.status="Commented"
                proposal.save()
                rates = Ratings.objects.filter(proposal=proposal)
                context['rates'] = rates
                context['proposal'] = proposal
                context['comments'] = comments
                context['url'] = url
                path, filename = os.path.split(str(proposal.attachment))
                context['filename'] = filename
                context.update(csrf(request))
                return render(request, 'comment-abstract.html', context)
            else:
                comments = Comments.objects.filter(proposal=proposal)
                rates = Ratings.objects.filter(proposal=proposal)
                context['rates'] = rates
                context['proposal'] = proposal
                context['url'] = url
                context['comments'] = comments
                path, filename = os.path.split(str(proposal.attachment))
                context['filename'] = filename
                context.update(csrf(request))
                return render(request, 'comment-abstract.html', context)
        else:
            return render(request, 'cfp.html', context)
    else:
        return render(request, 'cfp.html', context)


@login_required
def status(request, proposal_id= None):
    user = request.user
    context = {}
    if user.is_authenticated():
        if user.is_superuser :
            proposal = Proposal.objects.get(id=proposal_id)
            if 'accept' in request.POST:
                proposal.status="Accepted"
                proposal.save()
                sender_name = "SciPy India 2016"
                sender_email = "scipy@fossee.in"
                to = (proposal.user.email, "scipy@fossee.in")
                if proposal.proposal_type == 'ABSTRACT':
                    subject = "SciPy India 2016 - Talk Proposal Accepted"
                    message = """Dear """+proposal.user.first_name+""",
                    Congratulations. Your proposal for the talk titled '"""+ proposal.title+ """' is accepted. 
                    You shall present the talk at the conference.\n\nYou will be notified regarding instructions of your talk via email.\n\nThank You ! \n\nRegards,\nSciPy India 2016,\nFOSSEE - IIT Bombay"""
                elif proposal.proposal_type == 'WORKSHOP':
                    subject = "SciPy India 2016 - Workshop Proposal Accepted"
                    message = """Dear """+proposal.user.first_name+""",
                    Congratulations. Your proposal for the workshop titled '"""+ proposal.title+ """' is accepted. 
                    You shall conduct the workshop at the conference.\n\nYou will be notified regarding instructions of your workshop via email.\n\nThank You ! \n\nRegards,\nSciPy India 2016,\nFOSSEE - IIT Bombay"""
                send_mail(subject, message, sender_email, to)
                context.update(csrf(request))
            elif 'reject' in request.POST:
                proposal.status="Rejected"
                proposal.save()
                sender_name = "SciPy India 2016"
                sender_email = "scipy@fossee.in"
                to = (proposal.user.email,"scipy@fossee.in", )
                if proposal.proposal_type == 'ABSTRACT':
                    subject = "SciPy India 2016 - Talk Proposal Rejected"
                    message = """Dear """+proposal.user.first_name+""",
                    We regret to inform you that your proposal for the talk titled '"""+ proposal.title+ """' as not been shortlisted.<br> 
                    You may register and attend the conference by clicking http://scipyindia2016.doattend.com/
                    \n\nThank You ! \n\nRegards,\nSciPy India 2016,\nFOSSEE - IIT Bombay"""
                elif proposal.proposal_type == 'WORKSHOP':
                    subject = "SciPy India 2016 - Workshop Proposal Rejected"
                    message = """Dear """+proposal.user.first_name+""",
                    We regret to inform you that your proposal for the workshop titled '"""+ proposal.title+ """' as not been shortlisted.<br> 
                    You may register and attend the conference by clicking http://scipyindia2016.doattend.com/
                    \n\nThank You ! \n\nRegards,\nSciPy India 2016,\nFOSSEE - IIT Bombay"""
                send_mail(subject, message, sender_email, to)
                context.update(csrf(request))  
            elif 'resubmit' in request.POST:
                to = (proposal.user.email, "scipy@fossee.in" )
                sender_name = "SciPy India 2016"
                sender_email = "scipy@fossee.in"
                if proposal.proposal_type == 'ABSTRACT':
                    subject = "SciPy India 216 - Talk Proposal Resumbmission"
                    message = """
                    Dear {0}, <br><br>
                    Thank you for showing interest & submitting a talk proposal at SciPy India 2016 conference for the talk titled <b>"{1}"</b>. You are requested to submit this talk proposal once again.<br>
                    You will be notified regarding comments/selection/rejection of your talk via email.
                    Visit this {2} link to view comments on your submission.<br><br>
                    Thank You ! <br><br>Regards,<br>SciPy India 2016,<br>FOSSEE - IIT Bombay.
                    """.format(
                    proposal.user.first_name,
                    proposal.title, 
                    'http://scipy.in/2016/view-abstracts/' 
                    )
                elif proposal.proposal_type =='WORKSHOP':
                    subject = "SciPy India 216 - Workshop Proposal Resubmission"
                    message = """
                    Thank you for showing interest & submitting a workshop proposal at SciPy India 2016 conference for the workshop titled <b>"{1}"</b>. You are requested to submit this talk proposal once        again.<br>
                    You will be notified regarding comments/selection/rejection of your workshop via email.
                    Visit this {2} link to view comments on your submission.<br><br>
                    Thank You ! <br><br>Regards,<br>SciPy India 2016,<br>FOSSEE - IIT Bombay.
                    """.format(
                    proposal.user.first_name,
                    proposal.title, 
                    'http://scipy.in/2016/view-abstracts/' 
                    )
                email = EmailMultiAlternatives(
                subject,'',
                sender_email, to,
                headers={"Content-type":"text/html;charset=iso-8859-1"}
                )
                email.attach_alternative(message, "text/html")
                email.send(fail_silently=True)
                proposal.status="Edit"
                proposal.save()
                context.update(csrf(request)) 
        else:
            return render(request, 'cfp.html')  
    else:
        return render(request, 'cfp.html')  
    proposals = Proposal.objects.all().order_by('status')
    context['proposals'] = proposals
    context['user'] = user
    return render(request, 'view-abstracts.html', context)  
    

@login_required
def status_change(request):
    user = request.user
    context = {}
    if user.is_authenticated():
        if user.is_superuser:
            if 'delete' in request.POST:
                delete_proposal = request.POST.getlist('delete_proposal')
                for proposal_id in delete_proposal:
                    proposal = Proposal.objects.get(id = proposal_id)
                    proposal.delete()
                context.update(csrf(request)) 
                proposals = Proposal.objects.all()
                context['proposals'] = proposals
                context['user'] = user
                return render(request, 'view-abstracts.html', context)  
            elif 'dump' in request.POST:
                delete_proposal = request.POST.getlist('delete_proposal')
                try:
                    response = HttpResponse(content_type='text/csv')
                    response['Content-Disposition'] = 'attachment; filename="Proposals.csv"'
                    writer = csv.writer(response)
                    header = [
                                'name',
                                'username',
                                'email',
                                'about_me',
                                'phone',
                                'title',
                                'abstract',
                                'prerequisite',
                                'duration',
                                'attachment',
                                'date_created',
                                'status',
                                'proposal_type',
                                'tags',
                          ]
                    writer.writerow(header)
                    for proposal_id in delete_proposal:
                        proposal = Proposal.objects.get(id = proposal_id)
                        row = [
                                '{0} {1}'.format(proposal.user.first_name, proposal.user.last_name),
                                proposal.user.username,
                                proposal.user.email,
                                proposal.about_me,
                                proposal.phone,
                                proposal.title,
                                proposal.abstract,
                                proposal.prerequisite,
                                proposal.duration,
                                proposal.attachment,
                                proposal.date_created,
                                proposal.status,
                                proposal.proposal_type,
                                proposal.tags,
                                ]
                        writer.writerow(row)
                    return response
                except:
                    proposals = Proposal.objects.all()
                    context['proposals'] = proposals
                    context['user'] = user
                    return render(request, 'view-abstracts.html', context) 
            elif 'accept' in request.POST:
                delete_proposal = request.POST.getlist('delete_proposal') 
                for proposal_id in delete_proposal:
                    proposal = Proposal.objects.get(id = proposal_id)
                    proposal.status = "Accepted"
                    proposal.save()
                    sender_name = "SciPy India 2016"
                    sender_email = "scipy@fossee.in"
                    to = (proposal.user.email, "scipy@fossee.in")
                    if proposal.proposal_type == 'ABSTRACT':
                        subject = "SciPy India 2016 - Talk Proposal Accepted"
                        message = """Dear """+proposal.user.first_name+""",
                        Congratulations. Your proposal for the talk titled '"""+ proposal.title+ """'is accepted. 
                        You shall present the talk at the conference.\n\nYou will be notified regarding instructions of your talk via email.\n\nThank You ! \n\nRegards,\nSciPy India 2016,\nFOSSEE - IIT Bombay"""
                    elif proposal.proposal_type == 'WORKSHOP':
                        subject = "SciPy India 2016 - Workshop Proposal Accepted"
                        message = """Dear """+proposal.user.first_name+""",
                        Congratulations. Your proposal for the workshop titled '"""+ proposal.title+ """'is accepted. 
                        You shall conduct the workshop at the conference.\n\nYou will be notified regarding instructions of your workshop via email.\n\nThank You ! \n\nRegards,\nSciPy India 2016,\nFOSSEE - IIT Bombay"""
                    send_mail(subject, message, sender_email, to)
                    context.update(csrf(request))
                proposals = Proposal.objects.all()
                context['proposals'] = proposals
                context['user'] = user
                return render(request, 'view-abstracts.html', context)  
            elif 'reject' in request.POST:
                delete_proposal = request.POST.getlist('delete_proposal') 
                for proposal_id in delete_proposal:
                    proposal = Proposal.objects.get(id = proposal_id)
                    proposal.status="Rejected"
                    proposal.save()
                    sender_name = "SciPy India 2016"
                    sender_email = "scipy@fossee.in"
                    to = (proposal.user.email, "scipy@fossee.in")
                    if proposal.proposal_type == 'ABSTRACT':
                        subject = "SciPy India 2016 - Talk Proposal Rejected"
                        message = """Dear """+proposal.user.first_name+""",
                        We regret to inform you that your proposal for the talk titled '"""+ proposal.title+ """' as not been shortlisted.<br> 
                        You may register and attend the conference by clicking http://scipyindia2016.doattend.com/
                        \n\nThank You ! \n\nRegards,\nSciPy India 2016,\nFOSSEE - IIT Bombay"""
                    elif proposal.proposal_type == 'WORKSHOP':
                        subject = "SciPy India 2016 - Workshop Proposal Rejected"
                        message = """Dear """+proposal.user.first_name+""",
                        We regret to inform you that your proposal for the workshop titled '"""+ proposal.title+ """' as not been shortlisted.<br> 
                        You may register and attend the conference by clicking http://scipyindia2016.doattend.com/
                        \n\nThank You ! \n\nRegards,\nSciPy India 2016,\nFOSSEE - IIT Bombay"""
                    send_mail(subject, message, sender_email, to)
                    context.update(csrf(request))  
                proposals = Proposal.objects.all()
                context['proposals'] = proposals
                context['user'] = user
                return render(request, 'view-abstracts.html', context)  
            elif 'resubmit' in request.POST:
                delete_proposal = request.POST.getlist('delete_proposal') 
                for proposal_id in delete_proposal:
                    proposal = Proposal.objects.get(id = proposal_id)
                    sender_name = "SciPy India 2016"
                    sender_email = "scipy@fossee.in"
                    to = (proposal.user.email, "scipy@fossee.in" )
                    if proposal.proposal_type == 'ABSTRACT':
                        subject = "SciPy India 216 - Talk Proposal Resumbmission"
                        message = """
                        Dear {0}, <br><br>
                        Thank you for showing interest & submitting a talk proposal at SciPy India 2016 conference for the talk titled <b>"{1}"</b>. You are requested to submit this talk proposal once again.<br>
                        You will be notified regarding comments/selection/rejection of your talk via email.
                        Visit this {2} link to view comments on your submission.<br><br>
                        Thank You ! <br><br>Regards,<br>SciPy India 2016,<br>FOSSEE - IIT Bombay.
                        """.format(
                        proposal.user.first_name,
                        proposal.title, 
                        'http://scipy.in/2016/view-abstracts/' 
                        )
                    elif proposal.proposal_type =='WORKSHOP':
                        subject = "SciPy India 216 - Workshop Proposal Resubmission"
                        message = """
                        Thank you for showing interest & submitting a workshop proposal at SciPy India 2016 conference for the workshop titled <b>"{1}"</b>. You are requested to submit this talk proposal once        again.<br>
                        You will be notified regarding comments/selection/rejection of your workshop via email.
                        Visit this {2} link to view comments on your submission.<br><br>
                        Thank You ! <br><br>Regards,<br>SciPy India 2016,<br>FOSSEE - IIT Bombay.
                        """.format(
                        proposal.user.first_name,
                        proposal.title, 
                        'http://scipy.in/2016/view-abstracts/' 
                        )
                    email = EmailMultiAlternatives(
                    subject,'',
                    sender_email, to,
                    headers={"Content-type":"text/html;charset=iso-8859-1"}
                    )
                    email.attach_alternative(message, "text/html")
                    email.send(fail_silently=True)
                    proposal.status="Edit"
                    proposal.save()
                    context.update(csrf(request))  
                proposals = Proposal.objects.all()
                context['proposals'] = proposals
                context['user'] = user
                return render(request, 'view-abstracts.html', context)  
            else:
                proposals = Proposal.objects.all()
                context['proposals'] = proposals
                context['user'] = user
                return render(request, 'view-abstracts.html', context) 
        else:
            return render(request, 'cfp.html', context) 
    else:
        return render(request, 'view-abstracts.html', context)