Commit ccbad61c authored by Luuk Scholten's avatar Luuk Scholten
Browse files

Convert year selection in summary form to study years

parent 50d25b1e
......@@ -2,8 +2,11 @@ import datetime
from django.conf import settings
from django.forms import (ChoiceField, DateField, ModelChoiceField,
ModelForm, SelectDateWidget)
ModelForm, SelectDateWidget,
TypedChoiceField)
from django.utils import timezone
from utils.snippets import datetime_to_lectureyear
from .models import Course, Exam, Summary
......@@ -30,6 +33,12 @@ class AddSummaryForm(ModelForm):
queryset=Course.objects.order_by('name_' + settings.LANGUAGE_CODE),
empty_label=None)
this_year = datetime_to_lectureyear(timezone.now())
years = reversed([(x, "{} - {}".format(x, x + 1)) for x in
range(this_year - 20, this_year + 1)])
year = TypedChoiceField(choices=years, coerce=int, empty_value=this_year)
class Meta:
model = Summary
fields = ('name', 'year', 'file', 'course', 'author')
......@@ -106,14 +106,12 @@ def submit_summary(request, id=None):
obj.save()
obj = Summary()
obj.year = datetime.now().year
obj.author = request.user.get_full_name()
form = AddSummaryForm(instance=obj)
else:
obj = Summary()
if id is not None:
obj.course = Course.objects.get(id=id)
obj.year = datetime.now().year
obj.author = request.user.get_full_name()
form = AddSummaryForm(instance=obj)
......
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