Source code for oioioi.teachers.forms

from django import forms
from django.urls import reverse
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _

from oioioi.contests.forms import SimpleContestForm
from oioioi.teachers.models import Teacher
from oioioi.base.utils.user_selection import UserSelectionField



[docs]class TeacherContestForm(SimpleContestForm):
[docs] class Meta(SimpleContestForm.Meta):
[docs] fields = ['name', 'id']
[docs]class AddTeacherForm(forms.ModelForm):
[docs] class Meta(object):
[docs] model = Teacher
[docs] fields = ['user', 'school']
[docs] user = UserSelectionField(label=_("Username"))
def __init__(self, *args, **kwargs): super(AddTeacherForm, self).__init__(*args, **kwargs) self.fields['user'].hints_url = reverse('user_search')
[docs] school = forms.CharField( label=_("School"), help_text=mark_safe( _( "Please provide the full name. If the " "school is a part of a larger organization of schools, " "<br>enter the name of this organization." ) ), )
[docs] message = forms.CharField( label=_("Message"), help_text=_( "Optional. If provided, this message will be sent to the managers." ), required=False, widget=forms.Textarea(attrs={'rows': 10}), )
[docs] def clean_school(self): data = self.cleaned_data['school'] return ' '.join(data.splitlines())