def UserFormFactory(FormType, instance): extra_fields = {} extra_fields['rank'] = forms.ModelChoiceField( label=_("Rank"), help_text=_("Ranks are used to group and distinguish users. " "They are also used to add permissions to groups of " "users."), queryset=Rank.objects.order_by('name'), initial=instance.rank) roles = Role.objects.order_by('name') extra_fields['roles'] = forms.ModelMultipleChoiceField( label=_("Roles"), help_text=_('Individual roles of this user. ' 'All users must have "member" role.'), queryset=roles, initial=instance.roles.all() if instance.pk else None, widget=forms.CheckboxSelectMultiple) if instance.pk: extra_fields['timezone'] = forms.ChoiceField( label=_("Timezone"), choices=timezones.choices()) return type('UserFormFinal', (FormType,), extra_fields)
def UserFormFactory(FormType, instance): extra_fields = {} extra_fields['rank'] = forms.ModelChoiceField( label=_("Rank"), help_text=_("Ranks are used to group and distinguish users. " "They are also used to add permissions to groups of " "users."), queryset=Rank.objects.order_by('name'), initial=instance.rank) roles = Role.objects.order_by('name') extra_fields['roles'] = forms.ModelMultipleChoiceField( label=_("Roles"), help_text=_('Individual roles of this user. ' 'All users must have "member" role.'), queryset=roles, initial=instance.roles.all() if instance.pk else None, widget=forms.CheckboxSelectMultiple) if instance.pk: extra_fields['timezone'] = forms.ChoiceField( label=_("Timezone"), choices=timezones.choices()) return type('UserFormFinal', (FormType, ), extra_fields)
def ChangeForumOptionsForm(*args, **kwargs): timezone = forms.ChoiceField( label=_("Your current timezone"), choices=timezones.choices(), help_text=_("If dates and hours displayed by forums are inaccurate, " "you can fix it by adjusting timezone setting.")) FinalFormType = type('FinalChangeForumOptionsForm', (ChangeForumOptionsBaseForm,), {'timezone': timezone}) return FinalFormType(*args, **kwargs)
def ChangeForumOptionsForm(*args, **kwargs): timezone = forms.ChoiceField( label=_("Your current timezone"), choices=timezones.choices(), help_text=_("If dates and hours displayed by forums are inaccurate, " "you can fix it by adjusting timezone setting.")) FinalFormType = type('FinalChangeForumOptionsForm', (ChangeForumOptionsBaseForm, ), {'timezone': timezone}) return FinalFormType(*args, **kwargs)
def create_choice(setting, kwargs, extra): if setting.form_field == 'choice': kwargs['widget'] = forms.RadioSelect() else: kwargs['widget'] = forms.Select() kwargs['choices'] = extra.get('choices', []) if kwargs['choices'] == '#TZ#': kwargs['choices'] = timezones.choices() if setting.python_type == 'int': return forms.TypedChoiceField(coerce='int', **kwargs) else: return forms.ChoiceField(**kwargs)