Пример #1
0
class ChangeForumOptionsBaseForm(forms.ModelForm):
    timezone = forms.ChoiceField(
        label=_("Your current timezone"),
        choices=[],
        help_text=_("If dates and hours displayed by forums are inaccurate, "
                    "you can fix it by adjusting timezone setting."))

    is_hiding_presence = forms.YesNoSwitch(
        label=_("Hide my presence"),
        help_text=_("If you hide your presence, only members with permission "
                    "to see hidden will see when you are online."))

    limits_private_thread_invites_to = forms.TypedChoiceField(
        label=_("Who can add me to private threads"),
        coerce=int,
        choices=PRIVATE_THREAD_INVITES_LIMITS_CHOICES)

    subscribe_to_started_threads = forms.TypedChoiceField(
        label=_("Threads I start"), coerce=int, choices=AUTO_SUBSCRIBE_CHOICES)

    subscribe_to_replied_threads = forms.TypedChoiceField(
        label=_("Threads I reply to"),
        coerce=int,
        choices=AUTO_SUBSCRIBE_CHOICES)

    class Meta:
        model = get_user_model()
        fields = [
            'timezone', 'is_hiding_presence',
            'limits_private_thread_invites_to', 'subscribe_to_started_threads',
            'subscribe_to_replied_threads'
        ]
Пример #2
0
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)
Пример #3
0
class SearchBansForm(forms.Form):
    check_type = forms.ChoiceField(
        label=_("Type"),
        required=False,
        choices=SARCH_BANS_CHOICES
    )
    value = forms.CharField(
        label=_("Banned value begins with"),
        required=False
    )
    state = forms.ChoiceField(
        label=_("State"),
        required=False,
        choices=(
            ('', _('Any')),
            ('used', _('Active')),
            ('unused', _('Expired')),
        )
    )

    def filter_queryset(self, search_criteria, queryset):
        criteria = search_criteria
        if criteria.get('check_type') == 'names':
            queryset = queryset.filter(check_type=0)

        if criteria.get('check_type') == 'emails':
            queryset = queryset.filter(check_type=1)

        if criteria.get('check_type') == 'ips':
            queryset = queryset.filter(check_type=2)

        if criteria.get('value'):
            queryset = queryset.filter(
                banned_value__startswith=criteria.get('value').lower())

        if criteria.get('state') == 'used':
            queryset = queryset.filter(is_checked=True)

        if criteria.get('state') == 'unused':
            queryset = queryset.filter(is_checked=False)

        return queryset
Пример #4
0
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)
Пример #5
0
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 setting.python_type == 'int':
        return forms.TypedChoiceField(coerce='int', **kwargs)
    else:
        return forms.ChoiceField(**kwargs)
Пример #6
0
class SearchBansForm(forms.Form):
    test = forms.ChoiceField(label=_("Type"),
                             required=False,
                             choices=SARCH_BANS_CHOICES)
    value = forms.CharField(label=_("Banned value begins with"),
                            required=False)
    state = forms.ChoiceField(label=_("State"),
                              required=False,
                              choices=(
                                  ('', _('All states')),
                                  ('valid', _('Valid bans')),
                                  ('expired', _('Expired bans')),
                              ))

    def filter_queryset(self, search_criteria, queryset):
        criteria = search_criteria
        if criteria.get('test') == 'names':
            queryset = queryset.filter(test=0)

        if criteria.get('test') == 'emails':
            queryset = queryset.filter(test=1)

        if criteria.get('test') == 'ips':
            queryset = queryset.filter(test=2)

        if criteria.get('value'):
            queryset = queryset.filter(
                banned_value__startswith=criteria.get('value').lower())

        if criteria.get('state') == 'valid':
            queryset = queryset.filter(is_valid=True)

        if criteria.get('state') == 'expired':
            queryset = queryset.filter(is_valid=False)

        return queryset