Python django.db.models.fields.BLANK_CHOICE_DASH Examples

The following are 23 code examples of django.db.models.fields.BLANK_CHOICE_DASH(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.db.models.fields , or try the search function .
Example #1
Source File: relations.py    From esdc-ce with Apache License 2.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        queryset = kwargs.pop('queryset', None)
        self.many = kwargs.pop('many', self.many)
        if self.many:
            self.widget = self.many_widget
            self.form_field_class = self.many_form_field_class

        kwargs['read_only'] = kwargs.pop('read_only', self.read_only)
        super(RelatedField, self).__init__(*args, **kwargs)

        if not self.required:
            # Accessed in ModelChoiceIterator django/forms/models.py:1034
            # If set adds empty choice.
            self.empty_label = BLANK_CHOICE_DASH[0][1]

        self.queryset = queryset 
Example #2
Source File: widgets.py    From Dailyfresh-B2C with Apache License 2.0 6 votes vote down vote up
def render_option(self, name, selected_choices,
                      option_value, option_label):
        option_value = force_text(option_value)
        if option_label == BLANK_CHOICE_DASH[0][1]:
            option_label = _("All")
        data = self.data.copy()
        data[name] = option_value
        selected = data == self.data or option_value in selected_choices
        try:
            url = data.urlencode()
        except AttributeError:
            url = urlencode(data)
        return self.option_string() % {
            'attrs': selected and ' class="selected"' or '',
            'query_string': url,
            'label': force_text(option_label)
        } 
Example #3
Source File: forms.py    From SchoolIdolAPI with Apache License 2.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        request = kwargs.pop('request', None)
        super(FilterUserForm, self).__init__(*args, **kwargs)
        for field in self.fields.keys():
            self.fields[field].widget.attrs['placeholder'] = self.fields[field].label
        self.fields['best_girl'].choices = getGirls(with_japanese_name=(request and request.LANGUAGE_CODE == 'ja'))
        self.fields['language'].choices = BLANK_CHOICE_DASH + self.fields['language'].choices
        self.fields['os'].choices = BLANK_CHOICE_DASH + self.fields['os'].choices
        self.fields['verified'].choices = BLANK_CHOICE_DASH + [(3, _('Only'))] + self.fields['verified'].choices
        del(self.fields['verified'].choices[-1])
        self.fields['verified'].initial = None
        self.fields['os'].initial = None
        self.fields['language'].initial = None
        del(self.fields['status'].choices[0])
        del(self.fields['status'].choices[0])
        self.fields['status'].choices = BLANK_CHOICE_DASH + [('only', _('Only'))] + self.fields['status'].choices
        #self.fields['status'].choices.insert(1, ('only', _('Only'))) this doesn't work i don't know why 
Example #4
Source File: forms.py    From SchoolIdolAPI with Apache License 2.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(StaffFilterVerificationRequestForm, self).__init__(*args, **kwargs)
        self.fields['verified_by'].queryset = User.objects.filter(is_staff=True)
        self.fields['verified_by'].required = False
        self.fields['status'].required = False
        self.fields['status'].choices = BLANK_CHOICE_DASH + self.fields['status'].choices
        self.fields['verification'].required = False
        self.fields['verification'].help_text = None
        self.fields['allow_during_events'].help_text = None
        self.fields['allow_during_events'].label = 'Allowed us to verify them during events' 
Example #5
Source File: utils.py    From ldap-oauth2 with GNU General Public License v3.0 5 votes vote down vote up
def get_choices_with_blank_dash(choices):
    return BLANK_CHOICE_DASH + list(choices) 
Example #6
Source File: options.py    From python2017 with MIT License 5 votes vote down vote up
def get_action_choices(self, request, default_choices=BLANK_CHOICE_DASH):
        """
        Return a list of choices for use in a form object.  Each choice is a
        tuple (name, description).
        """
        choices = [] + default_choices
        for func, name, description in six.itervalues(self.get_actions(request)):
            choice = (name, description % model_format_dict(self.opts))
            choices.append(choice)
        return choices 
Example #7
Source File: widgets.py    From adhocracy4 with GNU Affero General Public License v3.0 5 votes vote down vote up
def get_option_label(self, value, choices=()):
        option_label = BLANK_CHOICE_DASH[0][1]

        for v, label in chain(self.choices, choices):
            if str(v) == value:
                option_label = label
                break

        if option_label == BLANK_CHOICE_DASH[0][1]:
            option_label = _('All')

        return option_label 
Example #8
Source File: options.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
def get_action_choices(self, request, default_choices=BLANK_CHOICE_DASH):
        """
        Return a list of choices for use in a form object.  Each choice is a
        tuple (name, description).
        """
        choices = [] + default_choices
        for func, name, description in six.itervalues(self.get_actions(request)):
            choice = (name, description % model_format_dict(self.opts))
            choices.append(choice)
        return choices 
Example #9
Source File: related.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH,
                    limit_to_currently_related=False):
        """Returns choices with a default blank choices included, for use
        as SelectField choices for this field.

        Analogue of django.db.models.fields.Field.get_choices, provided
        initially for utilisation by RelatedFieldListFilter.
        """
        first_choice = include_blank and blank_choice or []
        queryset = self.model._default_manager.all()
        if limit_to_currently_related:
            queryset = queryset.complex_filter(
                {'%s__isnull' % self.parent_model._meta.module_name: False})
        lst = [(x._get_pk_val(), smart_text(x)) for x in queryset]
        return first_choice + lst 
Example #10
Source File: options.py    From python with Apache License 2.0 5 votes vote down vote up
def get_action_choices(self, request, default_choices=BLANK_CHOICE_DASH):
        """
        Return a list of choices for use in a form object.  Each choice is a
        tuple (name, description).
        """
        choices = [] + default_choices
        for func, name, description in six.itervalues(self.get_actions(request)):
            choice = (name, description % model_format_dict(self.opts))
            choices.append(choice)
        return choices 
Example #11
Source File: forms.py    From SchoolIdolAPI with Apache License 2.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        account = kwargs.pop('account', None)
        super(TeamForm, self).__init__(*args, **kwargs)
        deck_choices = [(ownedcard.id, _ownedcard_label(ownedcard)) for ownedcard in account.deck]
        for i in range(9):
            self.fields['card' + str(i)].choices = BLANK_CHOICE_DASH + deck_choices
        if self.instance and hasattr(self.instance, 'all_members'):
            for member in getattr(self.instance, 'all_members'):
                self.fields['card' + str(member.position)].initial = member.ownedcard.id 
Example #12
Source File: forms.py    From SchoolIdolAPI with Apache License 2.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        request = kwargs.pop('request', None)
        super(FilterEventForm, self).__init__(*args, **kwargs)
        self.fields['idol'].choices = getGirls(with_japanese_name=(request and request.LANGUAGE_CODE == 'ja'))
        attributes = list(models.ATTRIBUTE_CHOICES)
        del(attributes[-1])
        self.fields['idol_attribute'].choices = BLANK_CHOICE_DASH + attributes
        if not request or not request.user.is_authenticated():
            del(self.fields['participation']) 
Example #13
Source File: models.py    From django-idcops with Apache License 2.0 5 votes vote down vote up
def choices_to_field(cls):
        _choices = [BLANK_CHOICE_DASH[0], ]
        for rel in cls._meta.related_objects:
            object_name = rel.related_model._meta.object_name.capitalize()
            field_name = rel.remote_field.name.capitalize()
            name = "{}-{}".format(object_name, field_name)
            remote_model_name = rel.related_model._meta.verbose_name
            verbose_name = "{}-{}".format(
                remote_model_name, rel.remote_field.verbose_name
            )
            _choices.append((name, verbose_name))
        return sorted(_choices) 
Example #14
Source File: test_blocks.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def setUp(self):
        from django.db.models.fields import BLANK_CHOICE_DASH
        self.blank_choice_dash_label = BLANK_CHOICE_DASH[0][1] 
Example #15
Source File: test_blocks.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def setUp(self):
        from django.db.models.fields import BLANK_CHOICE_DASH
        self.blank_choice_dash_label = BLANK_CHOICE_DASH[0][1] 
Example #16
Source File: field_block.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _get_callable_choices(self, choices, blank_choice=True):
        """
        Return a callable that we can pass into `forms.ChoiceField`, which will provide the
        choices list with the addition of a blank choice (if blank_choice=True and one does not
        already exist).
        """
        def choices_callable():
            # Variable choices could be an instance of CallableChoiceIterator, which may be wrapping
            # something we don't want to evaluate multiple times (e.g. a database query). Cast as a
            # list now to prevent it getting evaluated twice (once while searching for a blank choice,
            # once while rendering the final ChoiceField).
            local_choices = list(choices)

            # If blank_choice=False has been specified, return the choices list as is
            if not blank_choice:
                return local_choices

            # Else: if choices does not already contain a blank option, insert one
            # (to match Django's own behaviour for modelfields:
            # https://github.com/django/django/blob/1.7.5/django/db/models/fields/__init__.py#L732-744)
            has_blank_choice = False
            for v1, v2 in local_choices:
                if isinstance(v2, (list, tuple)):
                    # this is a named group, and v2 is the value list
                    has_blank_choice = any([value in ('', None) for value, label in v2])
                    if has_blank_choice:
                        break
                else:
                    # this is an individual choice; v1 is the value
                    if v1 in ('', None):
                        has_blank_choice = True
                        break

            if not has_blank_choice:
                return BLANK_CHOICE_DASH + local_choices

            return local_choices
        return choices_callable 
Example #17
Source File: forms.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _get_time_zone_choices():
    time_zones = [(tz, str(l18n.tz_fullnames.get(tz, tz)))
                  for tz in get_available_admin_time_zones()]
    time_zones.sort(key=itemgetter(1))
    return BLANK_CHOICE_DASH + time_zones 
Example #18
Source File: forms.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _get_language_choices():
    return sorted(BLANK_CHOICE_DASH + get_available_admin_languages(),
                  key=lambda l: l[1].lower()) 
Example #19
Source File: options.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
def get_action_choices(self, request, default_choices=BLANK_CHOICE_DASH):
        """
        Return a list of choices for use in a form object.  Each choice is a
        tuple (name, description).
        """
        choices = [] + default_choices
        for func, name, description in self.get_actions(request).values():
            choice = (name, description % model_format_dict(self.opts))
            choices.append(choice)
        return choices 
Example #20
Source File: options.py    From bioforum with MIT License 5 votes vote down vote up
def get_action_choices(self, request, default_choices=BLANK_CHOICE_DASH):
        """
        Return a list of choices for use in a form object.  Each choice is a
        tuple (name, description).
        """
        choices = [] + default_choices
        for func, name, description in self.get_actions(request).values():
            choice = (name, description % model_format_dict(self.opts))
            choices.append(choice)
        return choices 
Example #21
Source File: test_enumfield.py    From django-more with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_manual_choices(self):
        members = [TestEnum.VAL1, TestEnum.VAL2]
        field = EnumField(TestEnum, choices=members)
        choices = field.get_choices(blank_choice=BLANK_CHOICE_DASH)
        expected = BLANK_CHOICE_DASH + [(str(em), em.value) for em in members]
        self.assertEqual(choices, expected) 
Example #22
Source File: test_enumfield.py    From django-more with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_default_choices(self):
        field = EnumField(TestEnum)
        choices = field.get_choices(blank_choice=BLANK_CHOICE_DASH)
        expected = BLANK_CHOICE_DASH + [(str(em), em.value) for em in TestEnum]
        self.assertEqual(choices, expected) 
Example #23
Source File: options.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
def get_action_choices(self, request, default_choices=BLANK_CHOICE_DASH):
        """
        Return a list of choices for use in a form object.  Each choice is a
        tuple (name, description).
        """
        choices = [] + default_choices
        for func, name, description in six.itervalues(self.get_actions(request)):
            choice = (name, description % model_format_dict(self.opts))
            choices.append(choice)
        return choices