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
|
# Create your views here.
from django.http import HttpResponse
from django.shortcuts import render
from django.shortcuts import render_to_response
from django.template import loader
from django.template import RequestContext
from django.contrib.auth.forms import UserCreationForm
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from website.models import Proposal, Comments, Ratings
from website.forms import ProposalForm
#UserRegisterForm, UserLoginForm, WorkshopForm, ContactForm
def index(request):
context = {}
template = loader.get_template('index.html')
return HttpResponse(template.render(context, request))
def proposal(request):
context = {}
template = loader.get_template('proposal.html')
return HttpResponse(template.render(context, request))
## User Register
def userregister(request):
context = {}
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('registration/signup.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['form'] = form
return render_to_response('user-register.html', context)
else:
form = UserRegisterForm()
context['form'] = form
return render_to_response('user-register.html', context)
else:
context['user'] = request.user
return render_to_response('cfp.html', context)
## View Proposal/Abstract
@login_required
def view_abstracts(request):
user = request.user
context = {}
count_list =[]
if request.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-proposals.html', context)
elif user is not None:
if Proposal.objects.filter(user = user).exists :
proposals = Proposal.objects.filter(user = user).order_by('status')
proposal_list= [pro.proposal_type for pro in proposals]
if 'WORKSHOP' in proposal_list and 'ABSTRACT' in proposal_list:
proposal_type = 'BOTH'
elif 'WORKSHOP' in proposal_list and 'ABSTRACT' not in proposal_list:
proposal_type = 'WORKSHOP'
else:
proposal_type = 'ABSTRACT'
context['counts'] = count_list
context['proposals'] =proposals
context['type'] = proposal_type
context['user'] = user
return render(request, 'view-proposals.html', context)
else:
return render(request, 'cfp.html')
else:
return render(request, 'cfp.html', context)
def cfp(request):
if request.method == "POST":
context = {}
username = request.POST.get('username', None)
password = request.POST.get('password', None)
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
if 'next' in request.GET:
next = request.GET.get('next', None)
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 = {'request': request,
'user': request.user,
}
template = loader.get_template('cfp.html')
return HttpResponse(template.render(context, request))
@login_required
def submitcfp(request):
context = {}
if request.user.is_authenticated:
social_user = request.user
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.email = social_user.email
data.save()
context['proposal_submit'] = True
sender_name = "SciPy India 2017"
sender_email = TO_EMAIL
subject = "SciPy India 2017 – Talk Proposal Submission Acknowledgment"
to = (social_user.email, TO_EMAIL)
message = """
Dear {0}, <br><br>
Thank you for showing interest & submitting a talk proposal at SciPy India 2017 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 2017,<br>FOSSEE - IIT Bombay.
""".format(
social_user.first_name,
request.POST.get('title', None),
'http://scipy.in/2017/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
template = loader.get_template('submit-cfp.html')
return HttpResponse(template.render(context, request))
else:
form = ProposalForm()
context['proposals_a'] = proposals_a
return render(request, 'submit-cfp.html', {'form': form})
else:
context['login_required'] = True
return render_to_response('cfp.html', context)
|