class NewPermissionForm(forms.Form): permission_type = forms.ChoiceField(choices=filter( lambda x: isinstance(x[1], tuple) and "Deadline" in x[0], Permission.PERMISSION_CHOICES)) role = forms.ChoiceField(choices=[("Student", "Students"), ("Teacher", "Teachers")]) start_date = forms.DateTimeField(label='Opening date/time', initial=datetime.now, widget=DateTimeWidget(), required=False) end_date = forms.DateTimeField(label='Closing date/time', initial=None, widget=DateTimeWidget(), required=False)
class ProgramCreationForm(BetterModelForm): """ Massive form for creating a new instance of a program. """ term = forms.SlugField( label='Term or year, in URL form (i.e. "2007_Fall")', widget=forms.TextInput(attrs={'size': '40'})) term_friendly = forms.CharField( label='Term, in English (i.e. "Fall 07")', widget=forms.TextInput(attrs={'size': '40'})) admins = forms.MultipleChoiceField(choices=[], label='Administrators') teacher_reg_start = forms.DateTimeField(widget=DateTimeWidget()) teacher_reg_end = forms.DateTimeField(widget=DateTimeWidget()) student_reg_start = forms.DateTimeField(widget=DateTimeWidget()) student_reg_end = forms.DateTimeField(widget=DateTimeWidget()) base_cost = forms.IntegerField(label='Cost of Program Admission $', min_value=0) sibling_discount = forms.DecimalField( max_digits=9, decimal_places=2, required=False, initial=None, help_text= 'The amount of the sibling discount. Leave blank to disable sibling discounts.' ) program_type = forms.CharField(label="Program Type") program_modules = forms.MultipleChoiceField(choices=[], label='Program Modules') def __init__(self, *args, **kwargs): """ Used to update ChoiceFields with the current admins and modules. """ super(ProgramCreationForm, self).__init__(*args, **kwargs) admin_list = ESPUser.objects.filter(groups__name="Administrator") self.fields['admins'].choices = make_id_tuple( admin_list.distinct().order_by('username')) self.fields['program_modules'].choices = make_id_tuple( ProgramModule.objects.all()) # Enable validation on other fields self.fields['program_size_max'].required = True self.fields['program_size_max'].validators.append( validators.MaxValueValidator((1 << 31) - 1)) #self.fields.keyOrder = ['term','term_friendly','grade_min','grade_max','class_size_min','class_size_max','director_email','program_modules'] def load_program(self, program): # Copy the data in the program into the form so that we don't have to re-select modules and stuff. pass # use field grouping #as_table = grouped_as_table class Meta: fieldsets = [ ('Program Title', { 'fields': ['term', 'term_friendly'] }), ('Program Constraints', { 'fields': [ 'grade_min', 'grade_max', 'program_size_max', 'program_allow_waitlist' ] }), ('About Program Creator', { 'fields': ['admins', 'director_email'] }), ('Financial Details', { 'fields': ['base_cost', 'sibling_discount'] }), ('Program Internal details', { 'fields': ['program_type', 'program_modules', 'class_categories'] }), ('Registrations Date', { 'fields': [ 'teacher_reg_start', 'teacher_reg_end', 'student_reg_start', 'student_reg_end' ], }), ] # Here You can also add description for each fieldset. model = Program
class EditPermissionForm(forms.Form): start_date = forms.DateTimeField(widget=DateTimeWidget(), required=False) end_date = forms.DateTimeField(widget=DateTimeWidget(), required=False) id = forms.IntegerField(required=True, widget=forms.HiddenInput)
class ProgramCreationForm(BetterModelForm): """ Massive form for creating a new instance of a program. """ term = forms.CharField( label='Term or year, in URL form (i.e. "2007_Fall")', widget=forms.TextInput(attrs={'size': '40'})) term_friendly = forms.CharField( label='Term, in English (i.e. "Fall 07")', widget=forms.TextInput(attrs={'size': '40'})) admins = forms.MultipleChoiceField(choices=[], label='Administrators') teacher_reg_start = forms.DateTimeField(widget=DateTimeWidget()) teacher_reg_end = forms.DateTimeField(widget=DateTimeWidget()) student_reg_start = forms.DateTimeField(widget=DateTimeWidget()) student_reg_end = forms.DateTimeField(widget=DateTimeWidget()) publish_start = forms.DateTimeField( label='Program-Visible-on-Website Date', widget=DateTimeWidget()) publish_end = forms.DateTimeField( label='Program-Completely-Over Archive Date', widget=DateTimeWidget()) base_cost = forms.IntegerField(label='Cost of Program Admission $', min_value=0) finaid_cost = forms.IntegerField( label='Cost to Students who receive Financial Aid $', min_value=0) anchor = forms.ModelChoiceField([], label="Program Type") program_modules = forms.MultipleChoiceField(choices=[], label='Program Modules') def __init__(self, *args, **kwargs): """ Used to update ChoiceFields with the current admins and modules. """ super(ProgramCreationForm, self).__init__(*args, **kwargs) ub_list = UserBit.objects.bits_get_users( GetNode('Q'), GetNode('V/Flags/UserRole/Administrator')) self.fields['admins'].choices = make_id_tuple( ESPUser.objects.filter( id__in=[u.user_id for u in ub_list]).distinct().order_by('username')) self.fields['anchor'].queryset = DataTree.objects.filter( Q(child_set__program__isnull=False) | Q(parent=GetNode("Q/Programs"))).exclude( parent__name="Subprograms").distinct() self.fields['program_modules'].choices = make_id_tuple( ProgramModule.objects.all()) # Enable validation on other fields self.fields['program_size_max'].required = True self.fields['program_size_max'].validators.append( validators.MaxValueValidator((1 << 31) - 1)) #self.fields.keyOrder = ['term','term_friendly','grade_min','grade_max','class_size_min','class_size_max','director_email','program_modules'] def load_program(self, program): # Copy the data in the program into the form so that we don't have to re-select modules and stuff. pass # use field grouping #as_table = grouped_as_table class Meta: fieldsets = [ ('Program Title', { 'fields': ['term', 'term_friendly'] }), ('Program Constraints', { 'fields': [ 'grade_min', 'grade_max', 'program_size_max', 'program_allow_waitlist' ] }), ('About Program Creator', { 'fields': ['admins', 'director_email'] }), ('Financial Details', { 'fields': ['base_cost', 'finaid_cost'] }), ('Program Internal details', { 'fields': ['anchor', 'program_modules', 'class_categories'] }), ('Registrations Date', { 'fields': [ 'publish_start', 'publish_end', 'teacher_reg_start', 'teacher_reg_end', 'student_reg_start', 'student_reg_end' ], }), ] # Here You can also add description for each fieldset. model = Program
class NewUserbitForm(forms.Form): verb = AjaxTreeField(label='Activity', root_uri="V/Deadline/Registration") startdate = forms.DateTimeField(label='Opening date/time', initial=datetime.now, widget=DateTimeWidget()) enddate = forms.DateTimeField(label='Closing date/time', initial=datetime(9999, 01, 01), widget=DateTimeWidget(), required=False) recursive = forms.ChoiceField(label='Scope', choices=((True, 'Recursive'), (False, 'Individual')), initial=False, widget=forms.RadioSelect, required=False)
class EditUserbitForm(forms.Form): startdate = forms.DateTimeField(widget=DateTimeWidget()) enddate = forms.DateTimeField(widget=DateTimeWidget(), required=False) recursive = forms.ChoiceField(choices=((True, 'Recursive'), (False, 'Individual')), widget=forms.RadioSelect, required=False) id = forms.IntegerField(required=True, widget=forms.HiddenInput)
class ProgramCreationForm(BetterModelForm): """ Massive form for creating a new instance of a program. """ term = forms.SlugField( label='Term or year, in URL form (i.e. "2007_Fall")', widget=forms.TextInput(attrs={'size': '40'})) term_friendly = forms.CharField( label='Term, in English (i.e. "Fall 07")', widget=forms.TextInput(attrs={'size': '40'})) teacher_reg_start = forms.DateTimeField(widget=DateTimeWidget()) teacher_reg_end = forms.DateTimeField(widget=DateTimeWidget()) student_reg_start = forms.DateTimeField(widget=DateTimeWidget()) student_reg_end = forms.DateTimeField(widget=DateTimeWidget()) base_cost = forms.IntegerField(label='Cost of Program Admission $', min_value=0) sibling_discount = forms.DecimalField( max_digits=9, decimal_places=2, required=False, initial=None, help_text= 'The amount of the sibling discount. Leave blank to disable sibling discounts.' ) program_type = forms.CharField(label="Program Type") program_modules = forms.MultipleChoiceField( choices=[], label='Program Modules', widget=forms.SelectMultiple(attrs={'class': 'input-xxlarge'}), help_text=Program.program_modules.field.help_text) def __init__(self, *args, **kwargs): """ Used to update ChoiceFields with the current modules. """ super(ProgramCreationForm, self).__init__(*args, **kwargs) self.fields['program_modules'].choices = make_id_tuple( ProgramModule.objects.all()) # Enable validation on other fields self.fields['program_size_max'].required = True self.fields['program_size_max'].validators.append( validators.MaxValueValidator((1 << 31) - 1)) def save(self, commit=True): ''' Takes the program creation form's program_type, term, and term_friendly fields, and constructs the url and name fields on the Program instance; then calls the superclass's save() method. ''' # Filter out unwanted characters from program type to form URL ptype_slug = re.sub( '[-\s]+', '_', re.sub( '[^\w\s-]', '', unicodedata.normalize( 'NFKD', self.cleaned_data['program_type']).encode( 'ascii', 'ignore')).strip()) self.instance.url = u'%(type)s/%(instance)s' \ % {'type': ptype_slug ,'instance': self.cleaned_data['term'] } self.instance.name = u'%(type)s %(instance)s' \ % {'type': self.cleaned_data['program_type'] ,'instance': self.cleaned_data['term_friendly'] } return super(ProgramCreationForm, self).save(commit=commit) def load_program(self, program): # Copy the data in the program into the form so that we don't have to re-select modules and stuff. pass def clean_program_modules(self): value = self.cleaned_data['program_modules'] value = map(int, value) json_module = ProgramModule.objects.get(handler=u'JSONDataModule') # If the JSON Data Module isn't already in the list of selected # program modules, add it. The JSON Data Module is a dependency for # many commonly-used modules, so it is important that it be enbabled # by default for all new programs. if json_module.id not in value: value.append(json_module.id) return value class Meta: fieldsets = [ ('Program Title', { 'fields': ['term', 'term_friendly'] }), ('Program Constraints', { 'fields': [ 'grade_min', 'grade_max', 'program_size_max', 'program_allow_waitlist' ] }), ('About Program Creator', { 'fields': [ 'director_email', 'director_cc_email', 'director_confidential_email' ] }), ('Financial Details', { 'fields': ['base_cost', 'sibling_discount'] }), ('Program Internal details', { 'fields': [ 'program_type', 'program_modules', 'class_categories', 'flag_types' ] }), ('Registrations Date', { 'fields': [ 'teacher_reg_start', 'teacher_reg_end', 'student_reg_start', 'student_reg_end' ], }), ] # Here You can also add description for each fieldset. model = Program
class ProgramCreationForm(BetterModelForm): """ Massive form for creating a new instance of a program. """ term = forms.SlugField( label='Term or year, in URL form (i.e. "2007_Fall")', widget=forms.TextInput(attrs={'size': '40'})) term_friendly = forms.CharField( label='Term, in English (i.e. "Fall 07")', widget=forms.TextInput(attrs={'size': '40'})) admins = forms.MultipleChoiceField(choices=[], label='Administrators') teacher_reg_start = forms.DateTimeField(widget=DateTimeWidget()) teacher_reg_end = forms.DateTimeField(widget=DateTimeWidget()) student_reg_start = forms.DateTimeField(widget=DateTimeWidget()) student_reg_end = forms.DateTimeField(widget=DateTimeWidget()) base_cost = forms.IntegerField(label='Cost of Program Admission $', min_value=0) sibling_discount = forms.DecimalField( max_digits=9, decimal_places=2, required=False, initial=None, help_text= 'The amount of the sibling discount. Leave blank to disable sibling discounts.' ) program_type = forms.CharField(label="Program Type") program_modules = forms.MultipleChoiceField(choices=[], label='Program Modules') def __init__(self, *args, **kwargs): """ Used to update ChoiceFields with the current admins and modules. """ super(ProgramCreationForm, self).__init__(*args, **kwargs) admin_list = ESPUser.objects.filter(groups__name="Administrator") self.fields['admins'].choices = make_id_tuple( admin_list.distinct().order_by('username')) self.fields['program_modules'].choices = make_id_tuple( ProgramModule.objects.all()) # Enable validation on other fields self.fields['program_size_max'].required = True self.fields['program_size_max'].validators.append( validators.MaxValueValidator((1 << 31) - 1)) def save(self, commit=True): ''' Takes the program creation form's program_type, term, and term_friendly fields, and constructs the url and name fields on the Program instance; then calls the superclass's save() method. ''' # Filter out unwanted characters from program type to form URL ptype_slug = re.sub( '[-\s]+', '_', re.sub( '[^\w\s-]', '', unicodedata.normalize( 'NFKD', self.cleaned_data['program_type']).encode( 'ascii', 'ignore')).strip()) self.instance.url = u'%(type)s/%(instance)s' \ % {'type': ptype_slug ,'instance': self.cleaned_data['term'] } self.instance.name = u'%(type)s %(instance)s' \ % {'type': self.cleaned_data['program_type'] ,'instance': self.cleaned_data['term_friendly'] } return super(ProgramCreationForm, self).save(commit=commit) #self.fields.keyOrder = ['term','term_friendly','grade_min','grade_max','class_size_min','class_size_max','director_email','program_modules'] def load_program(self, program): # Copy the data in the program into the form so that we don't have to re-select modules and stuff. pass # use field grouping #as_table = grouped_as_table class Meta: fieldsets = [ ('Program Title', { 'fields': ['term', 'term_friendly'] }), ('Program Constraints', { 'fields': [ 'grade_min', 'grade_max', 'program_size_max', 'program_allow_waitlist' ] }), ('About Program Creator', { 'fields': ['admins', 'director_email'] }), ('Financial Details', { 'fields': ['base_cost', 'sibling_discount'] }), ('Program Internal details', { 'fields': ['program_type', 'program_modules', 'class_categories'] }), ('Registrations Date', { 'fields': [ 'teacher_reg_start', 'teacher_reg_end', 'student_reg_start', 'student_reg_end' ], }), ] # Here You can also add description for each fieldset. model = Program