Commit 6aa8bb1f authored by Daniel W Bond's avatar Daniel W Bond

I swear to fucking god

parent 675c0fb5
......@@ -4,6 +4,8 @@ from __future__ import absolute_import, print_function
from django import forms
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
# third party imports
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Layout
......@@ -25,7 +27,7 @@ class SelectRoomWidget(forms.widgets.Select):
print("Sorry about that, but we're currently ignoring your fancy attrs.")
# should probably type check the other fields too
if choices is None:
self.rooms = Room.objects.all()
self.choices = Room.objects.all()
else:
if not all(isinstance(thing, Room) for thing in rooms):
raise TypeError("Rooms in a SelectRoomWidget must all be Rooms!")
......@@ -41,11 +43,15 @@ class SelectRoomWidget(forms.widgets.Select):
'neighborhoods': self.neighborhoods,
'buildings': self.buildings,
'floors': self.floors,
'rooms': self.rooms,
'rooms': self.choices,
}
return mark_safe(render_to_string(self.template_name, context))
class SelectRoomField(forms.models.ModelChoiceField):
widget = SelectRoomWidget
class StudentUpdateForm(forms.Form):
first_name = forms.CharField(label='First Name')
......@@ -53,14 +59,30 @@ class StudentUpdateForm(forms.Form):
gender = MultiSelectFormField(choices=Student.GENDER_CHOICES,
label='Gender Identity (please choose all that apply)')
room = forms.ModelChoiceField(queryset=Room.objects.all(), widget=SelectRoomWidget(),
label='')
room = SelectRoomField(queryset=Room.objects.all(), label='')
privacy = forms.ChoiceField(choices=Student.PRIVACY_CHOICES)
major = forms.ModelChoiceField(queryset=Major.objects.all())
graduating_year = forms.IntegerField(label='Graduating Year')
def errors(self):
print("In errors.")
errors = super(StudentUpdateForm, self).errors()
print(errors)
return errors
def full_clean(self):
full_clean = super(StudentUpdateForm, self).full_clean()
print(full_clean)
return full_clean
def is_valid(self):
print("In is_valid.")
valid = super(StudentUpdateForm, self).is_valid()
print(valid)
return valid
class WelcomeNameForm(forms.Form):
first_name = forms.CharField(label='First Name')
......
......@@ -227,12 +227,27 @@ class UpdateStudent(LoginRequiredMixin, FormValidMessageMixin, FormView):
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):
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!")
for key, value in form.data.iteritems():
print(key, value)
print(form.data['room'])
current_room = me.room
try:
form_room = Room.objects.get(pk=form.data['room'])
print(form_room)
except:
form_room = None
......@@ -258,12 +273,6 @@ class UpdateStudent(LoginRequiredMixin, FormValidMessageMixin, FormView):
kwargs={'slug':self.request.user.username})
@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(UpdateStudent, self).post(request, *args, **kwargs)
# welcome pages
class WelcomeName(LoginRequiredMixin, FormView):
template_name = 'welcome_name.html'
......
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