Commit c19b9535 authored by Daniel W Bond's avatar Daniel W Bond

writing the test cases for the confirmation views led to a little bit of...

writing the test cases for the confirmation views led to a little bit of inadvertent tdd-- changed up the urls to be 'student ___ flags ____'
parent 8e6166ac
......@@ -25,14 +25,14 @@
<a href="{{ student.room.get_absolute_url }}">{{ student.room }}</a>
{% if same_floor %}
{% if has_flagged %}
<a href="{% url 'deleteConfirmation' student.slug my_flag.slug %}">
<a href="{% url 'deleteConfirmation' request.user.username student.user.username %}">
<small><span style="padding-left:15px" class="fa-stack fa-lg">
<i class="fa fa-flag fa-stack-1x"></i>
<i class="fa fa-ban fa-stack-2x text-danger"></i>
</span></small>
</a>
{% else %}
<a href="{% url 'createConfirmation' student.slug %}">
<a href="{% url 'createConfirmation' request.user.username student.user.username %}">
<i style="padding-left:15px" class="fa fa-flag"></i>
</a>
{% endif %}
......
......@@ -38,10 +38,10 @@ urlpatterns = patterns('',
name='remove_social'),
# student confirmation pages
url(r'^student/(?P<student_slug>[\w-]+)/flag/$',
url(r'^student/(?P<confirmer_slug>[\w-]+)/flag/(?P<student_slug>[\w-]+)/$',
CreateConfirmation.as_view(), name='createConfirmation'),
# delete confirmation
url(r'^student/(?P<student_slug>[\w-]+)/flag/(?P<slug>[\w-]+)/$',
url(r'^student/(?P<confirmer_slug>[\w-]+)/flag/(?P<student_slug>[\w-]+)/remove/$',
DeleteConfirmation.as_view(), name='deleteConfirmation'),
)
......@@ -16,6 +16,7 @@ from django.conf import settings
from django.template.loader import get_template
from django.core.mail import EmailMultiAlternatives, get_connection
from django.template import Context
from django.core.exceptions import ObjectDoesNotExist
# third party imports
from braces.views import LoginRequiredMixin, FormValidMessageMixin
from cas.views import login as cas_login
......@@ -468,18 +469,19 @@ class CreateConfirmation(LoginRequiredMixin, CreateView):
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]
# [u'', u'accounts', u'student', u'gmason', u'flag', u'confirmer']
confirmer_uname = current_url.split('/')[3]
student_uname = current_url.split('/')[5]
confirmer = Student.objects.get(user=self.request.user)
student = Student.objects.get(slug=url_uname)
confirmer = Student.objects.get(user__username=confirmer_uname)
student = Student.objects.get(user__username=student_uname)
flags = Confirmation.objects.filter(confirmer=confirmer,
student=student).count()
# you can't flag yourself
if confirmer == student:
return HttpResponseForbidden()
raise Http404
# check that the confirmer is on the floor of the student
if not on_the_same_floor(student, confirmer):
......@@ -500,7 +502,7 @@ class CreateConfirmation(LoginRequiredMixin, CreateView):
# duplicated code
current_url = self.request.get_full_path()
url_uname = current_url.split('/')[3]
url_uname = current_url.split('/')[5]
student = Student.objects.get(slug=url_uname)
......@@ -517,7 +519,7 @@ class CreateConfirmation(LoginRequiredMixin, CreateView):
# duplicated code
current_url = self.request.get_full_path()
url_uname = current_url.split('/')[3]
url_uname = current_url.split('/')[5]
confirmer = Student.objects.get(user=self.request.user)
student = Student.objects.get(slug=url_uname)
......@@ -540,14 +542,29 @@ class DeleteConfirmation(LoginRequiredMixin, DeleteView):
login_url = 'login'
def get(self, request, *args, **kwargs):
requester = Student.objects.get(user=self.request.user)
confirmer = self.get_object().confirmer
requester = self.request.user.student
try:
confirmer = self.get_object().confirmer
except ObjectDoesNotExist:
raise Http404
if not(requester == confirmer):
return HttpResponseForbidden()
else:
return super(DeleteConfirmation, self).get(request, *args, **kwargs)
def get_object(self):
current_url = self.request.get_full_path()
# [u'', u'accounts', u'student', u'gmason', u'flag', u'confirmer', delete]
confirmer_uname = current_url.split('/')[3]
student_uname = current_url.split('/')[5]
confirmer = Student.objects.get(user__username=confirmer_uname)
student = Student.objects.get(user__username=student_uname)
confirmation = Confirmation.objects.get(confirmer=confirmer, student=student)
return confirmation
def get_success_url(self):
return reverse('detail_student',
kwargs={'slug': self.object.student.slug})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment