Commit 3a53575b authored by Daniel W Bond's avatar Daniel W Bond

students have one more chance to change their rooms (two _after_ the welcome walkthrough)

parent f3eeb156
......@@ -6,6 +6,7 @@ from django.utils.safestring import mark_safe
from django.template.loader import render_to_string
from django.utils.encoding import force_text
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext as _
# third party imports
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Layout
......@@ -73,6 +74,15 @@ class StudentUpdateForm(forms.Form):
graduating_year = forms.IntegerField(label='Graduating Year')
def clean(self):
cleaned_data = super(StudentUpdateForm, self).clean()
form_room = cleaned_data.get('room')
students_in_room = Student.objects.filter(room=form_room).count()
#print(students_in_room)
# like in bookshare, I have no idea why the form errors don't display.
if students_in_room > 12:
raise ValidationError(_('Too many students in room (%d).' % students_in_room), code='invalid')
def is_valid(self):
# errors are not printed in form.as_p?
#print("In is_valid.")
......@@ -97,12 +107,21 @@ class WelcomePrivacyForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(WelcomePrivacyForm, self).__init__(*args, **kwargs)
if self.instance.recent_changes() >= 2:
if self.instance.recent_changes() > 2:
self.fields['room'].widget = forms.widgets.HiddenInput()
else:
self.fields['room'] = SelectRoomField(queryset=Room.objects.all(),
label='', required=False)
def clean(self):
cleaned_data = super(WelcomePrivacyForm, self).clean()
form_room = cleaned_data.get('room')
students_in_room = Student.objects.filter(room=form_room).count()
#print(students_in_room)
# like in bookshare, I have no idea why the form errors don't display.
if students_in_room > 12:
raise ValidationError(_('Too many students in room (%d).' % students_in_room), code='invalid')
class Meta:
model = Student
fields = ('room', 'privacy', )
......
{% if request.user.student.recent_changes %}
<div class="row">
<div class="col-md-12">
{% if request.user.student.recent_changes == 1 %}
{% if request.user.student.recent_changes <= 2 %}
<div class="alert alert-warning text-center" role="alert">
<strong>To safeguard everyone's privacy, the number of times you can change your room in a semester is limited.</strong>
{% else %}
......
......@@ -261,7 +261,7 @@ class UpdateStudent(LoginRequiredMixin, FormValidMessageMixin, FormView):
'major': pk_or_none(me, me.major),
'graduating_year' : me.graduating_year,})
if me.recent_changes() >= 2:
if me.recent_changes() > 2:
form.fields['room'].widget = HiddenInput()
else:
form.fields['room'].widget.user = self.request.user
......@@ -273,17 +273,17 @@ class UpdateStudent(LoginRequiredMixin, FormValidMessageMixin, FormView):
@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):
for key, value in request.POST.iteritems():
print(key, value)
#for key, value in request.POST.iteritems():
#print(key, value)
return super(UpdateStudent, self).post(request, *args, **kwargs)
def form_valid(self, form):
me = Student.objects.get(user=self.request.user)
print("In form valid method!")
#print("In form valid method!")
for key, value in form.data.iteritems():
print(key, value)
#for key, value in form.data.iteritems():
#print(key, value)
current_room = me.room
try:
......@@ -315,6 +315,11 @@ class UpdateStudent(LoginRequiredMixin, FormValidMessageMixin, FormView):
return super(UpdateStudent, self).form_valid(form)
def get_success_url(self):
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.')
return reverse('detail_student',
kwargs={'slug':self.request.user.username})
......
......@@ -2,7 +2,7 @@
{% for message in messages %}
<div class="row">
<div class="col-md-12">
<div class="alert alert-info alert-dismissable text-center" role="alert">
<div class="alert alert-{{ message.tags }} alert-dismissable text-center" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="close"><span aria-hidden="true">&times;</span></button>
<strong>{{ message }}</strong>
</div>
......
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