Exemplo n.º 1
0
    def formfield_for_choice_field(self, db_field, request, **kwargs):
        """
        Get a form Field for a database Field that has declared choices.
        """
        # If the field is named as a radio_field, use a RadioSelect
        if db_field.name in self.radio_fields:
            # Avoid stomping on custom widget/choices arguments.
            if "widget" not in kwargs:

                # BEGIN CUSTOMIZATION
                kwargs["widget"] = SemanticRadioSelect(attrs={
                    "class":
                    get_ul_class(self.radio_fields[db_field.name]),
                })
                # END CUSTOMIZATION

            if "choices" not in kwargs:
                kwargs["choices"] = db_field.get_choices(
                    include_blank=db_field.blank,
                    blank_choice=[("", _("None"))])

        # BEGIN CUSTOMIZATION
        if "widget" not in kwargs:
            kwargs["widget"] = SemanticSelect()
        # END CUSTOMIZATION

        return db_field.formfield(**kwargs)
Exemplo n.º 2
0
    def formfield_for_foreignkey(self, db_field, request, **kwargs):
        """
        Get a form Field for a ForeignKey.
        """
        db = kwargs.get('using')

        if db_field.name in self.get_autocomplete_fields(request):
            kwargs['widget'] = AutocompleteSelect(db_field.remote_field,
                                                  self.admin_site,
                                                  using=db)
        elif db_field.name in self.raw_id_fields:
            kwargs['widget'] = FixedForeignKeyRawIdWidget(
                db_field.remote_field, self.admin_site, using=db)
        elif db_field.name in self.radio_fields:
            kwargs['widget'] = widgets.AdminRadioSelect(
                attrs={
                    'class': get_ul_class(self.radio_fields[db_field.name]),
                })
            kwargs['empty_label'] = _('None') if db_field.blank else None

        if 'queryset' not in kwargs:
            queryset = self.get_field_queryset(db, db_field, request)
            if queryset is not None:
                kwargs['queryset'] = queryset

        return db_field.formfield(**kwargs)
Exemplo n.º 3
0
    def formfield_for_foreignkey(self, db_field, request, **kwargs):
        db = kwargs.get('using')

        if db_field.name in self.get_autocomplete_fields(request):
            kwargs['widget'] = AutocompleteSelect(db_field.remote_field,
                                                  self.admin_site,
                                                  using=db)
        elif db_field.name in self.raw_id_fields:
            kwargs['widget'] = widgets.ForeignKeyRawIdWidget(
                db_field.remote_field, self.admin_site, using=db)
        elif db_field.name in self.radio_fields:
            kwargs['widget'] = widgets.AdminRadioSelect(
                attrs={
                    'class': get_ul_class(self.radio_fields[db_field.name]),
                })
            kwargs['empty_label'] = gettext('None') if db_field.blank else None

        if db_field.name == 'image':
            kwargs['widget'] = widgets.ForeignKeyRawIdWidget(
                db_field.remote_field, self.admin_site, using=db)

        if 'queryset' not in kwargs:
            queryset = self.get_field_queryset(db, db_field, request)
            if queryset is not None:
                kwargs['queryset'] = queryset
        return super(PlaceArticleInline,
                     self).formfield_for_foreignkey(db_field, request,
                                                    **kwargs)
Exemplo n.º 4
0
 def formfield_for_choice_field(self, db_field, request=None, **kwargs):
     """
     Get a form Field for a database Field that has declared choices.
     """
     # If the field is named as a radio_field, use a RadioSelect
     if db_field.name == 'redirect_type':
         kwargs['widget'] = AdminRadioSelect(attrs={'class': get_ul_class(admin.VERTICAL)})
     return db_field.formfield(**kwargs)
Exemplo n.º 5
0
class ItemStatusForm(ModelForm):
    status = ChoiceField(label=u"Статус",
                         widget=widgets.AdminRadioSelect(
                             attrs={'class': get_ul_class(admin.HORIZONTAL)}),
                         choices=ITEM_STATUS_CHOICES)

    class Meta:
        model = Item
        fields = '__all__'
Exemplo n.º 6
0
 def formfield_for_choice_field(self, db_field, request=None, **kwargs):
     """
     Get a form Field for a database Field that has declared choices.
     """
     # If the field is named as a radio_field, use a RadioSelect
     if db_field.name == 'redirect_type':
         kwargs['widget'] = AdminRadioSelect(
             attrs={'class': get_ul_class(admin.VERTICAL)})
     return db_field.formfield(**kwargs)
Exemplo n.º 7
0
 class Meta:
     model = Subscription
     fields = '__all__'
     widgets = {
         'subscribed':
         widgets.AdminRadioSelect(
             choices=[(True, _('Subscribed')), (False, _('Unsubscribed'))],
             attrs={'class': options.get_ul_class(options.HORIZONTAL)})
     }
Exemplo n.º 8
0
 def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
     """
     Get a form Field for a ForeignKey.
     """
     db = kwargs.get("using")
     if db_field.name in self.raw_id_fields:
         kwargs["widget"] = UnicodeForeignKeyRawIdWidget(db_field.rel, self.admin_site, using=db)
     elif db_field.name in self.radio_fields:
         kwargs["widget"] = AdminRadioSelect(attrs={"class": get_ul_class(self.radio_fields[db_field.name])})
         kwargs["empty_label"] = db_field.blank and _("None") or None
     return db_field.formfield(**kwargs)
Exemplo n.º 9
0
    def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
        db = kwargs.get('using')
        if db_field.name in self.raw_id_fields:
            kwargs['widget'] = widgets.ForeignKeyRawIdWidget(
                db_field.rel, self.admin_site, using=db)
        elif db_field.name in self.radio_fields:
            kwargs['widget'] = AdminRadioSelect(attrs={
                'class': get_ul_class(self.radio_fields[db_field.name]),
            })
            kwargs['empty_label'] = db_field.blank and _('None') or None

        return db_field.formfield(**kwargs)
Exemplo n.º 10
0
    def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
        db = kwargs.get('using')
        if db_field.name in self.raw_id_fields:
            kwargs['widget'] = widgets.ForeignKeyRawIdWidget(
                db_field.rel, self.admin_site, using=db)
        elif db_field.name in self.radio_fields:
            kwargs['widget'] = AdminRadioSelect(attrs={
                'class': get_ul_class(self.radio_fields[db_field.name]),
            })
            kwargs['empty_label'] = db_field.blank and _('None') or None

        return db_field.formfield(**kwargs)
Exemplo n.º 11
0
    def formfield_for_foreignkey(self, prop, field, view, **kwargs):
        """
        Get a form Field for a ForeignKey.
        """
        request = kwargs.pop('request', None)
        if prop.name in self.raw_id_fields:
            kwargs['widget'] = widgets.ForeignKeyRawIdWidget(rel=None)
        elif prop.name in self.radio_fields:
            kwargs['widget'] = widgets.AdminRadioSelect(attrs={
                'class': get_ul_class(self.radio_fields[prop.name]),
            })
            kwargs['empty_label'] = prop.blank and _('None') or None

        return prop.formfield(**kwargs)
Exemplo n.º 12
0
 def formfield_for_choice_field(self, db_field, request=None, **kwargs):
     """
     Get a form Field for a database Field that has declared choices.
     """
     # If the field is named as a radio_field, use a RadioSelect
     if db_field.name in self.radio_fields:
         # Avoid stomping on custom widget/choices arguments.
         if 'widget' not in kwargs:
             kwargs['widget'] = widgets.AdminRadioSelect(attrs={
                 'class': get_ul_class(self.radio_fields[db_field.name]),
             })
         if 'choices' not in kwargs:
             kwargs['choices'] = db_field.get_choices(
                 include_blank=db_field.blank,
                 blank_choice=[('', _('None'))]
             )
     return formfield(db_field, **kwargs)
Exemplo n.º 13
0
 def formfield_for_choice_field(self, db_field, request=None, **kwargs):
     """
     Get a form Field for a database Field that has declared choices.
     """
     # If the field is named as a radio_field, use a RadioSelect
     if db_field.name in self.radio_fields:
         # Avoid stomping on custom widget/choices arguments.
         if 'widget' not in kwargs:
             kwargs['widget'] = widgets.AdminRadioSelect(attrs={
                 'class': get_ul_class(self.radio_fields[db_field.name]),
             })
         if 'choices' not in kwargs:
             kwargs['choices'] = db_field.get_choices(
                 include_blank = db_field.blank,
                 blank_choice=[('', _('None'))]
             )
     return formfield(db_field, **kwargs)
Exemplo n.º 14
0
    def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
        # copied from django.contrib.admin.wigets so we can override the label_for_value function
        # for the test raw id widget
        db = kwargs.get('using')
        if db_field.name == "test":
            widget = widgets.ForeignKeyRawIdWidget(db_field.rel,
                                                   self.admin_site, using=db)
            widget.label_for_value = self.label_for_value
            kwargs['widget'] = widget

        elif db_field.name in self.raw_id_fields:
            kwargs['widget'] = widgets.ForeignKeyRawIdWidget(db_field.rel,
                                                             self.admin_site, using=db)
        elif db_field.name in self.radio_fields:
            kwargs['widget'] = widgets.AdminRadioSelect(attrs={
                'class': options.get_ul_class(self.radio_fields[db_field.name]),
            })
            kwargs['empty_label'] = db_field.blank and _('None') or None
        return db_field.formfield(**kwargs)
Exemplo n.º 15
0
    def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
        from django.contrib.admin.options import get_ul_class
        from django.utils.translation import ugettext as _
        """
        Get a form Field for a ForeignKey.
        """
        db = kwargs.get('using')
        if db_field.name in self.raw_id_fields:
            kwargs['widget'] = SmartForeignKeyRawIdWidget(
                self.one_label_url, db_field.rel, self.admin_site, using=db)
        elif db_field.name in self.radio_fields:
            kwargs['widget'] = widgets.AdminRadioSelect(attrs={
                'class': get_ul_class(self.radio_fields[db_field.name]),
            })
            kwargs['empty_label'] = _('None') if db_field.blank else None

        if not 'queryset' in kwargs:
            queryset = self.get_field_queryset(db, db_field, request)
            if queryset is not None:
                kwargs['queryset'] = queryset

        return db_field.formfield(**kwargs)
Exemplo n.º 16
0
    def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
        # copied from django.contrib.admin.wigets so we can override the label_for_value function
        # for the test raw id widget
        db = kwargs.get('using')
        if db_field.name == "test":
            widget = widgets.ForeignKeyRawIdWidget(db_field.rel,
                                                   self.admin_site,
                                                   using=db)
            widget.label_for_value = self.label_for_value
            kwargs['widget'] = widget

        elif db_field.name in self.raw_id_fields:
            kwargs['widget'] = widgets.ForeignKeyRawIdWidget(db_field.rel,
                                                             self.admin_site,
                                                             using=db)
        elif db_field.name in self.radio_fields:
            kwargs['widget'] = widgets.AdminRadioSelect(attrs={
                'class':
                options.get_ul_class(self.radio_fields[db_field.name]),
            })
            kwargs['empty_label'] = db_field.blank and _('None') or None
        return db_field.formfield(**kwargs)
Exemplo n.º 17
0
    def formfield_for_foreignkey(self, db_field, request, **kwargs):
        # Overrided from django/contrib/admin/options.py
        # Overrided with the only purpose to use the custom ForeignKeyRawIdWidgetMoreWords widget
        """
        Get a form Field for a ForeignKey.
        """
        db = kwargs.get('using')
        if db_field.name in self.raw_id_fields:
            kwargs['widget'] = ForeignKeyRawIdWidgetMoreWords(
                db_field.remote_field, self.admin_site, using=db)
        elif db_field.name in self.radio_fields:
            kwargs['widget'] = widgets.AdminRadioSelect(
                attrs={
                    'class': get_ul_class(self.radio_fields[db_field.name]),
                })
            kwargs['empty_label'] = _('None') if db_field.blank else None

        if 'queryset' not in kwargs:
            queryset = self.get_field_queryset(db, db_field, request)
            if queryset is not None:
                kwargs['queryset'] = queryset

        return db_field.formfield(**kwargs)
Exemplo n.º 18
0
    def formfield_for_foreignkey(self, db_field, request, **kwargs):
        """
        Get a form Field for a ForeignKey.
        """
        db = kwargs.get("using")

        if db_field.name in self.get_autocomplete_fields(request):
            # BEGIN CUSTOMIZATION

            kwargs["widget"] = SemanticAutocompleteSelect(db_field,
                                                          self.admin_site,
                                                          using=db)

            # END CUSTOMIZATION

        elif db_field.name in self.raw_id_fields:
            # TODO
            kwargs["widget"] = widgets.ForeignKeyRawIdWidget(
                db_field.remote_field, self.admin_site, using=db)
        elif db_field.name in self.radio_fields:
            kwargs["widget"] = SemanticRadioSelect(
                attrs={
                    "class": get_ul_class(self.radio_fields[db_field.name])
                })
            kwargs["empty_label"] = _("None") if db_field.blank else None

        if "queryset" not in kwargs:
            queryset = self.get_field_queryset(db, db_field, request)
            if queryset is not None:
                kwargs["queryset"] = queryset

        # BEGIN CUSTOMIZATION
        if "widget" not in kwargs:
            kwargs["widget"] = SemanticSelect()
        # END CUSTOMIZATION

        return db_field.formfield(**kwargs)