Python django.db.models.fields 模块,BLANK_CHOICE_DASH 实例源码

我们从Python开源项目中,提取了以下39个代码示例,用于说明如何使用django.db.models.fields.BLANK_CHOICE_DASH

项目:esdc-ce    作者:erigones    | 项目源码 | 文件源码
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
项目:edx-enterprise    作者:edx    | 项目源码 | 文件源码
def test_new_enterprise_customer(self):
        """
        Test that a new blank form can be created and is not valid.
        """
        self.catalog_api.get_all_catalogs.return_value = [
            {
                "id": self.catalog_id,
                "name": "My Catalog"
            },
            {
                "id": 1,
                "name": "Other catalog!"
            }
        ]

        form = EnterpriseCustomerAdminForm()
        assert isinstance(form.fields['catalog'], forms.ChoiceField)
        assert form.fields['catalog'].choices == BLANK_CHOICE_DASH + [
            (self.catalog_id, 'My Catalog'),
            (1, 'Other catalog!'),
        ]
        assert not form.is_valid()
项目:edx-enterprise    作者:edx    | 项目源码 | 文件源码
def get_catalog_options(self):
        """
        Retrieve a list of catalog ID and name pairs.

        Once retrieved, these name pairs can be used directly as a value
        for the `choices` argument to a ChoiceField.
        """
        # TODO: We will remove the discovery service catalog implementation
        # once we have fully migrated customer's to EnterpriseCustomerCatalogs.
        # For now, this code will prevent an admin from creating a new
        # EnterpriseCustomer with a discovery service catalog. They will have to first
        # save the EnterpriseCustomer admin form and then edit the EnterpriseCustomer
        # to add a discovery service catalog.
        if hasattr(self.instance, 'site'):
            catalog_api = CourseCatalogApiClient(self.user, self.instance.site)
        else:
            catalog_api = CourseCatalogApiClient(self.user)
        catalogs = catalog_api.get_all_catalogs()
        # order catalogs by name.
        catalogs = sorted(catalogs, key=lambda catalog: catalog.get('name', '').lower())

        return BLANK_CHOICE_DASH + [
            (catalog['id'], catalog['name'],)
            for catalog in catalogs
        ]
项目:MagiCircles    作者:MagiCircles    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(UserPreferencesForm, self).__init__(*args, **kwargs)
        if not FAVORITE_CHARACTERS:
            for i in range(1, 4):
                self.fields.pop('favorite_character{}'.format(i))
        else:
            for i in range(1, 4):
                self.fields['favorite_character{}'.format(i)] = forms.ChoiceField(
                    required=False,
                    choices=BLANK_CHOICE_DASH + [(name, localized) for (name, localized, image) in FAVORITE_CHARACTERS],
                    label=(_(FAVORITE_CHARACTER_NAME) if FAVORITE_CHARACTER_NAME
                           else _('{nth} Favorite Character')).format(nth=_(ordinalNumber(i))))
        self.fields['birthdate'] = date_input(self.fields['birthdate'])
        if USER_COLORS:
            self.fields['color'].choices = BLANK_CHOICE_DASH + [(name, localized_name) for (name, localized_name, css_color, hex_color) in USER_COLORS]
            if self.instance:
                self.fields['color'].initial = self.instance.color
        else:
            self.fields.pop('color')
        self.fields['language'].choices = [l for l in self.fields['language'].choices if l[0]]
        self.old_location = self.instance.location if self.instance else None
        if 'activity' not in RAW_CONTEXT['all_enabled']:
            del(self.fields['view_activities_language_only'])
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
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
项目:NarshaTech    作者:KimJangHyeon    | 项目源码 | 文件源码
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
项目:Scrum    作者:prakharchoudhary    | 项目源码 | 文件源码
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
项目:django-driver27    作者:SRJ9    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(SeasonAdminForm, self).__init__(*args, **kwargs)
        punctuation_choices = get_punctuation_label_dict()
        self.fields['punctuation'] = forms.ChoiceField(choices=BLANK_CHOICE_DASH + list(punctuation_choices),
                                                       initial=None)
项目:stormtrooper    作者:CompileInc    | 项目源码 | 文件源码
def __init__(self, task, *args, **kwargs):
        super(ChoiceAnswerForm, self).__init__(*args, **kwargs)
        if task:
            qs = task.choices
            widget = forms.RadioSelect
            empty_label = None
            count = task.no_of_choices
            if count > settings.TASK_CHOICE_SELECT_CUTOFF:
                widget = forms.Select
                empty_label = BLANK_CHOICE_DASH[0][1]
            self.fields['answer'] = forms.ModelChoiceField(queryset=qs,
                                                           widget=widget,
                                                           empty_label=empty_label)
项目:Gypsy    作者:benticarlos    | 项目源码 | 文件源码
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
项目:DjangoBlog    作者:0daybug    | 项目源码 | 文件源码
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
项目:wanblog    作者:wanzifa    | 项目源码 | 文件源码
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
项目:tabmaster    作者:NicolasMinghetti    | 项目源码 | 文件源码
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
项目:trydjango18    作者:lucifer-yqh    | 项目源码 | 文件源码
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
项目:CinderellaProducers    作者:MagiCircles    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(FilterEvents, self).__init__(*args, **kwargs)
        self.fields['i_kind'].choices = BLANK_CHOICE_DASH + self.fields['i_kind'].choices
        self.fields['i_kind'].initial = None
项目:trydjango18    作者:wei0104    | 项目源码 | 文件源码
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
项目:ims    作者:ims-team    | 项目源码 | 文件源码
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
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
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
项目:django-open-lecture    作者:DmLitov4    | 项目源码 | 文件源码
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
项目:wagtail-inventory    作者:cfpb    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(PageBlockQueryForm, self).__init__(*args, **kwargs)
        block_choices = BLANK_CHOICE_DASH + [
            (b, b) for b in
            PageBlock.objects.values_list('block', flat=True).distinct()
        ]
        self.fields['block'].choices = block_choices
项目:travlr    作者:gauravkulkarni96    | 项目源码 | 文件源码
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
项目:logo-gen    作者:jellene4eva    | 项目源码 | 文件源码
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
项目:liberator    作者:libscie    | 项目源码 | 文件源码
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
项目:edx-enterprise    作者:edx    | 项目源码 | 文件源码
def test_interface_displays_selected_option(self):
        self.catalog_api.get_all_catalogs.return_value = [
            {
                "id": self.catalog_id,
                "name": "My Catalog"
            },
            {
                "id": 1,
                "name": "Other catalog!"
            }
        ]

        customer = EnterpriseCustomerFactory(
            catalog=99,
        )
        form = EnterpriseCustomerAdminForm(
            {
                'catalog': '',
                'enforce_data_sharing_consent': customer.enforce_data_sharing_consent,
                'site': customer.site.id,
                'name': customer.name,
                'active': customer.active
            },
            instance=customer,
        )
        assert isinstance(form.fields['catalog'], forms.ChoiceField)
        assert form.fields['catalog'].choices == BLANK_CHOICE_DASH + [
            (self.catalog_id, 'My Catalog'),
            (1, 'Other catalog!'),
        ]
项目:edx-enterprise    作者:edx    | 项目源码 | 文件源码
def test_with_mocked_get_edx_data(self):
        self.catalog_api.get_all_catalogs.return_value = [
            {
                "id": self.catalog_id,
                "name": "My Catalog"
            },
            {
                "id": 1,
                "name": "Other catalog!"
            }
        ]

        customer = EnterpriseCustomerFactory(
            catalog=99,
        )
        form = EnterpriseCustomerAdminForm(
            {
                'catalog': '',
                'enforce_data_sharing_consent': customer.enforce_data_sharing_consent,
                'site': customer.site.id,
                'name': customer.name,
                'active': customer.active
            },
            instance=customer,
        )
        assert isinstance(form.fields['catalog'], forms.ChoiceField)
        assert form.fields['catalog'].choices == BLANK_CHOICE_DASH + [
            (self.catalog_id, 'My Catalog'),
            (1, 'Other catalog!'),
        ]
项目:gmail_scanner    作者:brandonhub    | 项目源码 | 文件源码
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
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
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
项目:adhocracy4    作者:liqd    | 项目源码 | 文件源码
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
项目:CSCE482-WordcloudPlus    作者:ggaytan00    | 项目源码 | 文件源码
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
项目:tissuelab    作者:VirtualPlants    | 项目源码 | 文件源码
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
项目:producthunt    作者:davidgengler    | 项目源码 | 文件源码
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
项目:django-rtc    作者:scifiswapnil    | 项目源码 | 文件源码
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
项目:geekpoint    作者:Lujinghu    | 项目源码 | 文件源码
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
项目:django-next-train    作者:bitpixdigital    | 项目源码 | 文件源码
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
项目:LatinSounds_AppEnviaMail    作者:G3ek-aR    | 项目源码 | 文件源码
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
项目:DjangoZeroToHero    作者:RayParra    | 项目源码 | 文件源码
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
项目:Roboism    作者:markroxor    | 项目源码 | 文件源码
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
项目:MagiCircles    作者:MagiCircles    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(FilterReports, self).__init__(*args, **kwargs)
        self.fields['status'].required = False
        self.fields['status'].initial = models.REPORT_STATUS_PENDING
        self.fields['staff'].required = False
        self.fields['staff'].queryset = self.fields['staff'].queryset.filter(is_staff=True)
        self.fields['reported_thing'].choices = BLANK_CHOICE_DASH + [(name, c['plural_title']) for name, c in ENABLED_COLLECTIONS.items() if name != 'report']
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
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