views.py 23.2 KB
Newer Older
1
2
# standard library imports
from __future__ import absolute_import, print_function
3
import random
4
5
from operator import attrgetter
from itertools import chain
6
# core django imports
Daniel W Bond's avatar
Daniel W Bond committed
7
from django.shortcuts import get_object_or_404
8
from django.http import HttpResponseForbidden
9
10
from django.views.generic import (CreateView, ListView, DetailView, UpdateView,
                                  FormView, DeleteView)
11
from django.core.urlresolvers import reverse
12
13
from django.contrib import messages
from django.utils.safestring import mark_safe
14
from django.forms.widgets import HiddenInput
15
# third party imports
16
from braces.views import LoginRequiredMixin, FormValidMessageMixin
17
from cas.views import login as cas_login
18
from ratelimit.decorators import ratelimit
19
# imports from your apps
Daniel W Bond's avatar
Daniel W Bond committed
20
21
from .models import Student, Major, Confirmation
from housing.models import Building, Floor, Room
22
23
from .forms import (StudentUpdateForm, WelcomeNameForm, WelcomePrivacyForm,
                    WelcomeSocialForm)
24

Daniel W Bond's avatar
Daniel W Bond committed
25

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
not_started = """Welcome to SRCT Roomlist! <a href="%s">Click here</a> to walk through
                 your profile setup."""

# 1 or 2
started = """Welcome back to SRCT Roomlist! It looks like you're not quite finished with
             setting up your profile. <a href="%s">Click here</a> to return to your
             welcome walkthrough."""

# 3
almost = """Welcome back to SRCT Roomlist! It looks like you're almost finished
            with setting up your profile. <a href="%s">Click here</a> to return
            to the last page of your welcome walkthrough."""

# walkthrough finished but Room is None
no_room = """It looks like you haven't set your room yet. Head to <a href="%s"> your
             settings page</a> to get that taken care of."""

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
#########

bug_reporting = """Welcome back to SRCT Roomlist. This project is the
                   <a href="https://srct.gmu.edu/projects/">collaborative work
                   of students like you</a>. If you see anything amiss, or have ideas for
                   features or a better user experience, please send an email to
                   roomlist@lists.srct.gmu.edu, tweet
                   <a href="https://twitter.com/MasonSRCT/">@MasonSRCT</a>, or, for the
                   more technically experienced, review our
                   <a href="https://git.gmu.edu/srct/roomlist/issues">issues page</a>."""

privacy_reminder = """Welcome back to SRCT Roomlist. A friendly reminder you can change
                      your privacy settings at any time on your settings page by
                      clicking the cog in the upper right of your screen."""

disclaimer = """Welcome back to SRCT Roomlist. Just to be perfectly clear, this project
                is provided as a service by the
                <a href="https://gmu.collegiatelink.net/organization/srct">registered
                student organization</a>
                <a href="https://srct.gmu.edu/">Student-Run Computing and Technology</a>.
                We are not a part of <a href="http://housing.gmu.edu/">Mason Housing</a>:
                all information is voluntarily provided by participating students."""

whatsopen_plug = """Welcome back to SRCT Roomlist. Wondering what's open at this hour?
                    Check out another one of our
                    <a href="https://srct.gmu.edu/projects/">student-built and hosted</a>
                    projects: <a href="https://whatsopen.gmu.edu/">whatsopen.gmu.edu</a>."""

open_source = """Welcome back to SRCT Roomlist. For the curious at heart,
                 <a href="http://www.gnu.org/philosophy/free-sw.en.html">you can always
                 review</a> this project's
                 <a href="https://git.gmu.edu/srct/roomlist/tree/master">source code</a>.
                 Come <a href="https://srct.gmu.edu/">to a meeting</a> and learn how to
                 contribute!"""

return_messages = [bug_reporting, privacy_reminder, disclaimer, whatsopen_plug, open_source]

80
81
82
83

def custom_cas_login(request, *args, **kwargs):
    response = cas_login(request, *args, **kwargs)
    # returns HttpResponseRedirect
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
    if request.user.is_authenticated():

        if request.user.student.completedName is False:
            rendered_url = reverse('welcomeName', args=[request.user.username])
            add_url = not_started % rendered_url
            messages.add_message(request, messages.INFO, mark_safe(add_url))

        elif request.user.student.completedPrivacy is False:
            rendered_url = reverse('welcomePrivacy', args=[request.user.username])
            add_url = started % rendered_url
            messages.add_message(request, messages.INFO, mark_safe(add_url))

        elif request.user.student.completedMajor is False:
            rendered_url = reverse('welcomeMajor', args=[request.user.username])
            add_url = started % rendered_url
            messages.add_message(request, messages.INFO, mark_safe(add_url))

        elif request.user.student.completedName is False:
            rendered_url = reverse('welcomeSocial', args=[request.user.username])
            add_url = started % rendered_url
            messages.add_message(request, messages.INFO, mark_safe(add_url))

        elif request.user.student.room is None:
            rendered_url = reverse('updateStudent', args=[request.user.username])
            add_url = started % rendered_url
            messages.add_message(request, messages.INFO, mark_safe(add_url))
111
112
113
        else:
            welcome_back = random.choice(return_messages)
            messages.add_message(request, messages.INFO, mark_safe(welcome_back))
114
115
116
117

    return response


118
119
def on_the_same_floor(student, confirmer):
    if student == confirmer:
120
        # Student is confirmer
121
122
123
124
125
        return False
    student_floor = student.get_floor()
    confirmer_floor = confirmer.get_floor()
    # room hasn't been set yet
    if (student_floor is None) or (confirmer_floor is None):
126
        # one Student is None
127
128
        return False
    elif not(student_floor == confirmer_floor):
129
        # not the same floor
130
131
132
133
134
        return False
    else:
        return True


135
136
137
138
139
140
def pk_or_none(me, obj):
    if obj is None:
        return None
    else:
        return obj.pk

141

142
143
144
# details about the student
class DetailStudent(LoginRequiredMixin, DetailView):
    model = Student
145
146
147
148
    context_object_name = 'student'
    template_name = 'detailStudent.html'

    login_url = 'login'
Daniel W Bond's avatar
Daniel W Bond committed
149
150
151
152

    def get_context_data(self, **kwargs):
        context = super(DetailStudent, self).get_context_data(**kwargs)

153
        requesting_student = Student.objects.get(user=self.request.user)
Daniel W Bond's avatar
Daniel W Bond committed
154

155
156
157
158
159
        same_floor = on_the_same_floor(self.get_object(), requesting_student)

        flags = Confirmation.objects.filter(confirmer=requesting_student,
                                            student=self.get_object()).count()

Daniel W Bond's avatar
Daniel W Bond committed
160
161
162
163
164
        if flags:
            try:
                my_flag = Confirmation.objects.get(confirmer=requesting_student,
                                                   student=self.get_object())
            except Exception as e:
165
166
                print("Students are not supposed to be able to make more than one flag per student.")
                print(e)
167

Daniel W Bond's avatar
Daniel W Bond committed
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
        def onFloor():
            floor_status = False
            if requesting_student.get_floor() == self.get_object().get_floor():
                floor_status = True
            return floor_status

        def inBuilding():
            floor_status = False
            if requesting_student.get_building() == self.get_object().get_building():
                floor_status = True
            return floor_status

        def shares():
            student_shares = False
            # if the student's privacy is floor and the requesting user is on their floor
            if(self.get_object().privacy == 'floor') and onFloor():
                student_shares = True
Daniel W Bond's avatar
Daniel W Bond committed
185
186
            # if the student's privacy is building and the requesting users is
            # on their floor or in their building
Daniel W Bond's avatar
Daniel W Bond committed
187
188
189
190
191
192
            elif(self.get_object().privacy == 'building') and inBuilding():
                student_shares = True
            # if the student's privacy is set to 'student'
            elif(self.get_object().privacy == 'students'):
                student_shares = True
            return student_shares
Daniel W Bond's avatar
Daniel W Bond committed
193

Daniel W Bond's avatar
Daniel W Bond committed
194
        context['shares'] = shares()
195
196
        context['same_floor'] = same_floor
        context['has_flagged'] = bool(flags)
Daniel W Bond's avatar
Daniel W Bond committed
197
198
        if flags:
            context['my_flag'] = my_flag
Daniel W Bond's avatar
Daniel W Bond committed
199
200
        return context

Daniel W Bond's avatar
Daniel W Bond committed
201

202
class DetailCurrentStudent(LoginRequiredMixin, DetailView):
203
204
205
206
207
    model = Student
    context_object_name = 'student'
    template_name = 'detailStudent.html'

    login_url = 'login'
208
209
210
211

    def get_object(self):
        return get_object_or_404(Student, pk=self.request.session['_auth_user_id'])

Daniel W Bond's avatar
Daniel W Bond committed
212

213
214
215
# changeable student settings
class DetailStudentSettings(LoginRequiredMixin, DetailView):
    model = Student
216
217
218
219
    context_object_name = 'student'
    template_name = 'studentSettings.html'

    login_url = 'login'
220

Daniel W Bond's avatar
Daniel W Bond committed
221

222
class DetailCurrentStudentSettings(LoginRequiredMixin, DetailView):
223
    model = Student
224
225
226
227
    context_object_name = 'student'
    template_name = 'studentSettings.html'

    login_url = 'login'
228
229
230

    def get_object(self):
        return get_object_or_404(Student, pk=self.request.session['_auth_user_id'])
Daniel W Bond's avatar
Daniel W Bond committed
231

232

233
# update a student, but FormView to allow name update on same page
234
class UpdateStudent(LoginRequiredMixin, FormValidMessageMixin, FormView):
235
    template_name = 'updateStudent.html'
236
    form_class = StudentUpdateForm
237
238
    login_url = 'login'

239
240
    form_valid_message = "Your profile was successfully updated!"

241
242
243
244
245
246
247
248
249
250
    def get(self, request, *args, **kwargs):

        current_url = self.request.get_full_path()
        url_uname = current_url.split('/')[3]

        if not(url_uname == self.request.user.username):
            return HttpResponseForbidden()
        else:
            return super(UpdateStudent, self).get(request, *args, **kwargs)

251
252
253
254
255
256
    def get_context_data(self, **kwargs):
        context = super(UpdateStudent, self).get_context_data(**kwargs)

        me = Student.objects.get(user=self.request.user)

        form = StudentUpdateForm(initial={'first_name': me.user.first_name,
257
258
                                          'last_name': me.user.last_name,
                                          'gender': me.gender,
259
                                          'show_gender': me.show_gender,
260
261
262
263
                                          'room': pk_or_none(me, me.room),
                                          'privacy': me.privacy,
                                          'major': pk_or_none(me, me.major),
                                          'graduating_year' : me.graduating_year,})
264

265
        if me.recent_changes() > 2:
266
            form.fields['room'].widget = HiddenInput()
267
268
        else:
            form.fields['room'].widget.user = self.request.user
269

270
        context['my_form'] = form
Daniel W Bond's avatar
Daniel W Bond committed
271

272
273
        return context

Daniel W Bond's avatar
Daniel W Bond committed
274
275
276
    @ratelimit(key='user', rate='5/m', method='POST', block=True)
    @ratelimit(key='user', rate='10/d', method='POST', block=True)
    def post(self, request, *args, **kwargs):
277
278
        #for key, value in request.POST.iteritems():
            #print(key, value)
Daniel W Bond's avatar
Daniel W Bond committed
279
280
        return super(UpdateStudent, self).post(request, *args, **kwargs)

281
282
283
    def form_valid(self, form):
        me = Student.objects.get(user=self.request.user)

284
        #print("In form valid method!")
Daniel W Bond's avatar
Daniel W Bond committed
285

286
287
        #for key, value in form.data.iteritems():
            #print(key, value)
Daniel W Bond's avatar
Daniel W Bond committed
288

289
290
291
292
293
294
295
296
        current_room = me.room
        try:
            form_room = Room.objects.get(pk=form.data['room'])
        except:
            form_room = None

        if current_room != form_room:
            me.times_changed_room += 1
297
            Confirmation.objects.filter(student=me).delete()
298

299
300
301
302
303
304
305
        me.room = form_room

        try:
            me.major = Major.objects.get(pk=form.data['major'])
        except:
            me.major = None

306
307
308
        me.user.first_name = form.data['first_name']
        me.user.last_name = form.data['last_name']
        me.gender = form.data.getlist('gender')
309
        me.show_gender = form.data.get('show_gender', False)
310
        me.privacy = form.data['privacy']
311
312
        me.graduating_year = form.data['graduating_year']

313
314
315
316
317
318
        me.user.save()
        me.save()

        return super(UpdateStudent, self).form_valid(form)

    def get_success_url(self):
319
320
321
322
323

        if self.request.user.student.recent_changes() == 2:

            messages.add_message(self.request, messages.WARNING, 'To safeguard everyone\'s privacy, you have just one remaining room change for the semester before you\'ll need to send us an email at roomlist@lists.srct.gmu.edu.')

324
325
        return reverse('detail_student',
                       kwargs={'slug':self.request.user.username})
326

327

328
329
# welcome pages
class WelcomeName(LoginRequiredMixin, FormView):
330
    template_name = 'welcome_name.html'
331
332
333
    form_class = WelcomeNameForm
    login_url = 'login'

334
335
336
337
338
339
340
341
342
343
    def get(self, request, *args, **kwargs):

        current_url = self.request.get_full_path()
        url_uname = current_url.split('/')[3]

        if not(url_uname == self.request.user.username):
            return HttpResponseForbidden()
        else:
            return super(WelcomeName, self).get(request, *args, **kwargs)

Daniel W Bond's avatar
Daniel W Bond committed
344
345
346
347
348
349
350
    def get_context_data(self, **kwargs):
        context = super(WelcomeName, self).get_context_data(**kwargs)

        me = Student.objects.get(user=self.request.user)

        form = WelcomeNameForm(initial={'first_name': me.user.first_name,
                                        'last_name': me.user.last_name,
351
352
                                        'gender': me.gender,
                                        'show_gender': me.show_gender, })
Daniel W Bond's avatar
Daniel W Bond committed
353
354
        context['my_form'] = form
        return context
355

356
357
358
359
360
    @ratelimit(key='user', rate='5/m', method='POST', block=True)
    @ratelimit(key='user', rate='10/d', method='POST', block=True)
    def post(self, request, *args, **kwargs):
        return super(WelcomeName, self).post(request, *args, **kwargs)

361
    def form_valid(self, form):
Daniel W Bond's avatar
Daniel W Bond committed
362
        me = Student.objects.get(user=self.request.user)
363

Daniel W Bond's avatar
Daniel W Bond committed
364
365
366
367
        me.user.first_name = form.data['first_name']
        me.user.last_name = form.data['last_name']

        me.gender = form.data.getlist('gender')
368
        me.show_gender = form.data.get('show_gender', False)
Daniel W Bond's avatar
Daniel W Bond committed
369
370
371
372
373

        me.completedName = True

        me.user.save()
        me.save()
374
375
376

        return super(WelcomeName, self).form_valid(form)

377
378
379
380
    def get_success_url(self):
        return reverse('welcomePrivacy',
                       kwargs={'slug':self.request.user.username})

381
382
383

class WelcomePrivacy(LoginRequiredMixin, UpdateView):
    model = Student
Daniel W Bond's avatar
Daniel W Bond committed
384
    form_class = WelcomePrivacyForm
385
    context_object_name = 'student'
386
    template_name = 'welcome_privacy.html'
387
388
389

    login_url = 'login'

390
391
392
393
394
395
396
397
398
399
    def get(self, request, *args, **kwargs):

        current_url = self.request.get_full_path()
        url_uname = current_url.split('/')[3]

        if not(url_uname == self.request.user.username):
            return HttpResponseForbidden()
        else:
            return super(WelcomePrivacy, self).get(request, *args, **kwargs)

400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
    def get_context_data(self, **kwargs):
        context = super(WelcomePrivacy, self).get_context_data(**kwargs)

        me = Student.objects.get(user=self.request.user)

        form = WelcomePrivacyForm()

        form.fields['room'].widget.user = self.request.user

        context['my_form'] = form

        return context

    @ratelimit(key='user', rate='5/m', method='POST', block=True)
    @ratelimit(key='user', rate='10/d', method='POST', block=True)
    def post(self, request, *args, **kwargs):
        return super(WelcomePrivacy, self).post(request, *args, **kwargs)

Daniel W Bond's avatar
Daniel W Bond committed
418
419
    def form_valid(self, form):
        me = self.get_object()
420

Daniel W Bond's avatar
Daniel W Bond committed
421
        current_room = me.room
422

Daniel W Bond's avatar
Daniel W Bond committed
423
424
425
426
        try:
            form_room = Room.objects.get(pk=form.data['room'])
        except:
            form_room = None
427

Daniel W Bond's avatar
Daniel W Bond committed
428
429
        if current_room != form_room:
            form.instance.times_changed_room += 1
430
            Confirmation.objects.filter(student=me).delete()
431

Daniel W Bond's avatar
Daniel W Bond committed
432
        form.instance.completedPrivacy = True
433
434
435

        return super(WelcomePrivacy, self).form_valid(form)

436
437
438
439
    def get_success_url(self):
        return reverse('welcomeMajor',
                       kwargs={'slug':self.request.user.username})

440
441
442

class WelcomeMajor(LoginRequiredMixin, UpdateView):
    model = Student
443
    fields = ['major', 'graduating_year', ]
444
    context_object_name = 'student'
445
    template_name = 'welcome_major.html'
446
447
448

    login_url = 'login'

449
450
451
452
453
454
455
456
457
458
    def get(self, request, *args, **kwargs):

        current_url = self.request.get_full_path()
        url_uname = current_url.split('/')[3]

        if not(url_uname == self.request.user.username):
            return HttpResponseForbidden()
        else:
            return super(WelcomeMajor, self).get(request, *args, **kwargs)

459
460
461
462
463
    @ratelimit(key='user', rate='5/m', method='POST', block=True)
    @ratelimit(key='user', rate='10/d', method='POST', block=True)
    def post(self, request, *args, **kwargs):
        return super(WelcomeMajor, self).post(request, *args, **kwargs)

464
465
    def form_valid(self, form):

Daniel W Bond's avatar
Daniel W Bond committed
466
        form.instance.completedMajor = True
467
468
469

        return super(WelcomeMajor, self).form_valid(form)

470
471
472
473
    def get_success_url(self):
        return reverse('welcomeSocial',
                       kwargs={'slug':self.request.user.username})

474

475
class WelcomeSocial(LoginRequiredMixin, UpdateView):
476
    model = Student
Daniel W Bond's avatar
Daniel W Bond committed
477
    form_class = WelcomeSocialForm
478
    context_object_name = 'student'
479
    template_name = 'welcome_social.html'
480
481
    login_url = 'login'

482
483
484
485
486
487
488
489
490
491
    def get(self, request, *args, **kwargs):

        current_url = self.request.get_full_path()
        url_uname = current_url.split('/')[3]

        if not(url_uname == self.request.user.username):
            return HttpResponseForbidden()
        else:
            return super(WelcomeSocial, self).get(request, *args, **kwargs)

492
493
494
495
496
    @ratelimit(key='user', rate='5/m', method='POST', block=True)
    @ratelimit(key='user', rate='10/d', method='POST', block=True)
    def post(self, request, *args, **kwargs):
        return super(WelcomeSocial, self).post(request, *args, **kwargs)

497
498
    def form_valid(self, form):

Daniel W Bond's avatar
Daniel W Bond committed
499
        form.instance.completedSocial = True
500
501
502

        return super(WelcomeSocial, self).form_valid(form)

503
    def get_success_url(self):
504
505
506
507
508

        if self.request.user.student.totally_done():
            messages.add_message(self.request, messages.SUCCESS,
                                 "You successfully finished the welcome walkthrough!")

509
510
511
        return reverse('detail_student',
                       kwargs={'slug':self.request.user.username})

512
513

# majors pages
Daniel W Bond's avatar
Daniel W Bond committed
514
515
516
517
518
519
class ListMajors(LoginRequiredMixin, ListView):
    model = Major
    queryset = Major.objects.all().order_by('name')
    context_object_name = 'majors'
    template_name = 'list_majors.html'

520
521
522
523
524
525
526
527
528
529
530
531
    login_url = 'login'


class DetailMajor(LoginRequiredMixin, DetailView):
    model = Major
    context_object_name = 'major'
    template_name = 'detail_major.html'

    login_url = 'login'

    def get_context_data(self, **kwargs):
        context = super(DetailMajor, self).get_context_data(**kwargs)
532
        requesting_student = Student.objects.get(user=self.request.user)
533

534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
	# retrieve every room that has a student with the major in question
	neighbourhoods = ("aq", "ra", "sh")
	visible_by_neighbourhood = {}
	for neighbourhood in neighbourhoods:
	    rooms = [
		room
		for room in Room.objects.filter(floor__building__neighbourhood=neighbourhood)
		if room.student_set.filter(major=self.get_object())
	    ]

	    # identify if the student(s) in that room are visible to the requesting student
	    # 'chain' is necessary if there are multiple students in one room with the same major
	    #
	    # we sort each of the lists of students by their username
	    # as elsewhere, this is imperfect if a student changes their display name
	    # this is necessary as a separate step because .visible returns a list type
	    # note we're using '.' instead of '__', because who likes syntactical consistency
	    visible_by_neighbourhood[neighbourhood] = sorted(list(chain(*[
		Student.objects.visible(requesting_student, room)
		for room in rooms
	    ])), key=attrgetter('user.username'))
555
556

        # see what students are left over (aren't visible)
557
558
559
560
561
562
        hidden = Student.objects.filter(major=self.get_object()).order_by('user__username')
	for visible in neighbourhoods.values():
	    hidden -= set(visible)

	for neighbourhood, visible in neighbourhoods.items():
	    context['%s_location_visible' % neighbourhood] = visible
563
        context['location_hidden'] = hidden
564
565

        return context
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


class CreateConfirmation(LoginRequiredMixin, CreateView):
    model = Confirmation
    fields = []
    template_name = 'create_confirmation.html'

    login_url = 'login'

    def get(self, request, *args, **kwargs):

        current_url = self.request.get_full_path()
        # [u'', u'accounts', u'student', u'gmason', u'flag', u'']
        url_uname = current_url.split('/')[3]

        confirmer = Student.objects.get(user=self.request.user)
        student = Student.objects.get(slug=url_uname)

        flags = Confirmation.objects.filter(confirmer=confirmer,
                                            student=student).count()

        # you can't flag yourself
        if confirmer == student:
            return HttpResponseForbidden()

        # check that the confirmer is on the floor of the student
        if not on_the_same_floor(student, confirmer):
            return HttpResponseForbidden()

        # check if the confirmer has already flagged the student
        if flags >= 1:
            return HttpResponseForbidden()

        return super(CreateConfirmation, self).get(request, *args, **kwargs)


    def get_context_data(self, **kwargs):
        context = super(CreateConfirmation, self).get_context_data(**kwargs)

        # duplicated code
        current_url = self.request.get_full_path()
        url_uname = current_url.split('/')[3]

        student = Student.objects.get(slug=url_uname)

        context['student'] = student

        return context

615
616
617
618
619
    @ratelimit(key='user', rate='10/m', method='POST', block=True)
    @ratelimit(key='user', rate='50/d', method='POST', block=True)
    def post(self, request, *args, **kwargs):
        return super(CreateConfirmation, self).post(request, *args, **kwargs)

620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
    def form_valid(self, form):

        # duplicated code
        current_url = self.request.get_full_path()
        url_uname = current_url.split('/')[3]

        confirmer = Student.objects.get(user=self.request.user)
        student = Student.objects.get(slug=url_uname)

        form.instance.confirmer = confirmer
        form.instance.student = student

        return super(CreateConfirmation, self).form_valid(form)

    def get_success_url(self):
        # redirect to the flagged student page when saving
        return reverse('detail_student',
                       kwargs={'slug':self.object.student.slug})


class DeleteConfirmation(LoginRequiredMixin, DeleteView):
    model = Confirmation
Daniel W Bond's avatar
Daniel W Bond committed
642
    template_name = 'delete_confirmation.html'
643
644
645

    login_url = 'login'

Daniel W Bond's avatar
Daniel W Bond committed
646
647
648
    def get(self, request, *args, **kwargs):
        requester = Student.objects.get(user=self.request.user)
        confirmer = self.get_object().confirmer
649

Daniel W Bond's avatar
Daniel W Bond committed
650
651
652
653
        if not(requester == confirmer):
            return HttpResponseForbidden()
        else:
            return super(DeleteConfirmation, self).get(request, *args, **kwargs)
654
655
656

    def get_success_url(self):
        return reverse('detail_student',
Daniel W Bond's avatar
Daniel W Bond committed
657
                       kwargs={'slug':self.object.student.slug})