Beispiel #1
0
 class Meta:
     model = User
     fields = ('username', 'first_name', 'last_name', 'email')
     widgets = {
         'username':
         Input(
             attrs={
                 'class': 'form-control',
                 'placeholder': 'Имя пользователя',
                 'autofocus': ''
             }),
         'first_name':
         Input(attrs={
             'class': 'form-control',
             'placeholder': 'Имя'
         }),
         'last_name':
         Input(attrs={
             'class': 'form-control',
             'placeholder': 'Фамилия'
         }),
         'email':
         Input(attrs={
             'class': 'form-control',
             'placeholder': 'Электронная почта'
         }),
     }
Beispiel #2
0
 class Meta:
     model = User
     fields = ['username', 'email']
     widgets = {
         'username': Input(attrs={'class': "form-control"}),
         'email': Input(attrs={'class': "form-control"})
     }
Beispiel #3
0
    class Meta:
        model = AnonymousVul
        fields = ('title', 'category', 'detail', 'attachment', 'email')
        labels = {
            'title': '漏洞标题',
            'category': '漏洞类型',
            'detail': '漏洞细节',
            'attachment': '附件',
            'email': '注册邮箱(可选)',
        }

        widgets = {
            'detail':
            Textarea(**bs4_form),
            'title':
            Input(**bs4_form),
            'category':
            Select(**bs4_form),
            'email':
            Input(
                attrs={
                    'class': 'form-control',
                    'placeholder': '跟踪漏洞状态并注册为正式用户,内测版仅支持 @ujs.edu.cn 的邮件地址'
                }),
        }
Beispiel #4
0
class CourseFilter(django_filters.FilterSet):
    Program = django_filters.CharFilter(lookup_expr='icontains', 
                                        label='Program', 
                                        widget = Input(attrs={'placeholder':'Ex: Chem',}) 
                                        )

    ProgramAPPX = django_filters.CharFilter(
                                        lookup_expr='icontains', 
                                        field_name="Program",
                                        label='Program', 
                                        widget = Input(attrs={'placeholder':'Ex: Chem',}) 
                                        )


    CourseID = django_filters.CharFilter(
                                        label='Course Number', 
                                        widget = Input(attrs={'placeholder':'4 Digit Number', 'class': "form-control",}) 
                                        )

    CourseNumA = django_filters.NumberFilter(
                                        field_name="CourseNum",
                                        label='CourseNum Min', 
                                        widget = Input(attrs={'placeholder':'Starting Range', 'class': "form-control",}),
                                        lookup_expr="gt",
                                        )
    CourseNumB = django_filters.NumberFilter(
                                        field_name="CourseNum",
                                        label='CourseNum Max', 
                                        widget = Input(attrs={'placeholder':'Starting Range', 'class': "form-control",}),
                                        lookup_expr="lt",
                                        )

    class Meta:
        model = Course
        fields = ["CourseID", "Program", "CourseNum"]
Beispiel #5
0
class ApplicationForm2(forms.Form):
    # Allow blank choices
    GENDERS = (('', '----'), ) + Application.GENDERS
    RACES = (('', '----'), ) + Application.RACES
    REFERRED_OPTIONS = (('', '----'), ) + Application.REFERRED_OPTIONS

    gender = forms.ChoiceField(widget=Select(attrs={'id': 'id_gender'}),
                               choices=GENDERS)

    race = forms.ChoiceField(widget=Select(attrs={'id': 'id_race'}),
                             choices=RACES)

    race_other = forms.CharField(widget=Input(attrs={'id': 'id_race_other'}),
                                 max_length=120,
                                 required=False)

    referred = forms.ChoiceField(widget=Select(attrs={'id': 'id_referred'}),
                                 choices=REFERRED_OPTIONS)

    referred_other = forms.CharField(
        widget=Input(attrs={'id': 'id_referred_other'}),
        max_length=120,
        required=False)

    veteran = forms.BooleanField(
        widget=CheckboxInput(attrs={'id': 'id_veteran'}), required=False)

    military_service = forms.MultipleChoiceField(
        widget=CheckboxSelectMultiple(attrs={'id': 'id_military_service'}),
        choices=Application.MILITARY_OPTIONS,
        required=False)
Beispiel #6
0
    class Meta:
        model = Book

        fields = ('name', 'description', 'author', 'gender', 'amount_pages',
                  'amount_chapter', 'img_book', 'file_book')

        labels = {
            'name': ('Nombre'),
        }

        widgets = {
            'name':
            Input(attrs={'class': 'form-control'}),
            'description':
            Textarea(attrs={'class': 'form-control'}),
            'author':
            Select(attrs={
                'class': 'form-control',
                'placeholder': 'Autor'
            }),
            'gender':
            SelectMultiple(attrs={'class': 'form-control'}),
            'amount_pages':
            Input(attrs={'class': 'form-control'}),
            'amount_chapter':
            Input(attrs={'class': 'form-control'}),
            'content_adult':
            Input(attrs={'class': 'form-control'}),
            'img_book':
            FileInput(attrs={'class': 'form-control'}),
            'file_book':
            FileInput(attrs={'class': 'form-control'}),
        }
Beispiel #7
0
 class Meta:
     model = Pledging
     exclude = ['expire_date']
     widgets = {
         'user_id':
         forms.HiddenInput(),
         'type_pledging':
         forms.HiddenInput(),
         'cus_id':
         Input(attrs={
             'class': 'form-control',
             'readonly': 'readonly'
         }),
         'pledge_balance':
         Input(attrs={'class': 'shadow-sm form-control'}),
         'contract_term':
         Input(attrs={'class': 'shadow-sm form-control'}),
         'dob':
         Input(attrs={
             'class': 'form-control',
             'type': 'date'
         }),
     }
     labels = {
         'cus_id': 'รหัสลูกค้า',
         'pledge_balance': 'ยอดจำนำ',
         'contract_term': 'เวลาสัญญา ( เป็นวัน )',
         'pledge_date': 'วันเริ่มทำสัญญา',
         'expire_date': 'วันหมดสัญญา'
     }
Beispiel #8
0
 class Meta:
     model = Profile
     fields = ['nickname', 'phone', 'avatar']
     labels = {'avatar': '用户头像', 'nickname': '昵称', 'phone': '手机号码'}
     widgets = {
         'nickname': Input(attrs={'class': "form-control"}),
         'phone': Input(attrs={'class': "form-control"})
     }
Beispiel #9
0
 def test_attrs_with_type(self):
     attrs = {'type': 'date'}
     widget = Input(attrs)
     self.check_html(widget, 'name', 'value', '<input type="date" name="name" value="value" />')
     # reuse the same attrs for another widget
     self.check_html(Input(attrs), 'name', 'value', '<input type="date" name="name" value="value" />')
     attrs['type'] = 'number'  # shouldn't change the widget type
     self.check_html(widget, 'name', 'value', '<input type="date" name="name" value="value" />')
    class Meta:
        model = Expenses
        fields = ['amount', 'exp_note', 'bill']
        widgets = {
            'amount': Input(attrs={'class': 'form-control', 'required': 'required', 'type': 'number'}),
            'exp_note': Input(attrs={'class': 'form-control', 'required': 'required'}),
            'bill': Input(attrs={'class': 'form-control', 'type': 'file', 'required': 'required'}),

        }
Beispiel #11
0
 class Meta:
     model = User
     fields = ['first_name', 'last_name', 'username', 'password']
     widgets = {
         'password': Input(attrs={
             'type': 'password',
             'class': 'form-control'
         }),
         'first_name': Input(attrs={'class': 'form-control'}),
         'last_name': Input(attrs={'class': 'form-control'}),
         'username': Input(attrs={'class': 'form-control'}),
     }
Beispiel #12
0
    def set_value_widget(self):
        """add custom widget for boolean values (after form has been initialized)"""

        # temp store attributes so they can be restored to reset widget
        value_fields = [
            "value", "string_value", "date_value", "datetime_value"
        ]
        widget_attrs = {}
        for f in value_fields:
            self.fields[f].widget.attrs["class"] = "qa-input"
            widget_attrs[f] = self.fields[f].widget.attrs

        test_type = self.unit_test_info.test.type

        if test_type == models.BOOLEAN:
            self.fields["value"].widget = RadioSelect(choices=BOOL_CHOICES)
        elif test_type == models.CONSTANT:
            test = self.unit_test_info.test
            formatted = format_qc_value(test.constant_value, test.formatting)
            self.fields["value"].widget.attrs['title'] = _(
                'Actual value = %(constant_value)s') % {
                    'constant_value': test.constant_value
                }
            self.fields["value"].widget.attrs['data-formatted'] = formatted
        elif test_type == models.MULTIPLE_CHOICE:
            self.fields["string_value"].widget = Select(
                choices=[("", "")] + self.unit_test_info.test.get_choices())
        elif test_type == models.UPLOAD:
            self.fields["string_value"].widget = HiddenInput()
            self.fields["json_value"].widget = HiddenInput()
        elif test_type == models.COMPOSITE:
            self.fields["value"].widget = Input()
            if getattr(self, "instance", None):
                test = self.unit_test_info.test
                formatted = format_qc_value(self.instance.value,
                                            test.formatting)
                self.fields["value"].widget.attrs['data-formatted'] = formatted
        elif test_type in models.STRING_TYPES:
            self.fields['string_value'].widget = Input({'maxlength': 20000})
        else:
            attrs = {"step": "any"}
            if test_type == models.WRAPAROUND:
                attrs['max'] = self.unit_test_info.test.wrap_high
                attrs['min'] = self.unit_test_info.test.wrap_low
            self.fields["value"].widget = NumberInput(attrs=attrs)

        if test_type in (models.BOOLEAN, models.MULTIPLE_CHOICE):
            if hasattr(self, "instance") and self.instance.value is not None:
                self.initial["value"] = int(self.instance.value)

        for f in value_fields:
            self.fields[f].widget.attrs.update(widget_attrs[f])
Beispiel #13
0
 class Meta:
     model = Redeemed
     exclude = ['redeem_date']
     widgets = {
         'pledging_id': forms.HiddenInput(),
         'first_name': Input(attrs={'class': 'form-control'}),
         'last_name': Input(attrs={'class': 'form-control'}),
         'citizen_id': Input(attrs={'class': 'form-control'}),
     }
     labels = {
         'first_name': 'ชื่อ',
         'last_name': 'นามสกุล',
         'citizen_id': 'รหัสประชาชน',
     }
Beispiel #14
0
 class Meta:
     model = Application
     fields = ('written_username', 'written_phone', 'written_cover_letter')
     widgets = {
         'written_username':
         Input(attrs={'class': 'form-control'}),
         'written_phone':
         Input(attrs={'class': 'form-control'}),
         'written_cover_letter':
         Textarea(attrs={
             'rows': 8,
             'class': 'form-control'
         }),
     }
Beispiel #15
0
 class Meta:
     model = Resume
     fields = ('name', 'surname', 'status', 'salary', 'specialty', 'grade',
               'education', 'experience')
     widgets = {
         'name': Input(attrs={'class': 'form-control'}),
         'surname': Input(attrs={'class': 'form-control'}),
         'status': Select(attrs={'class': 'custom-select mr-sm-2'}),
         'salary': NumberInput(attrs={'class': 'form-control'}),
         'specialty': Select(attrs={'class': 'custom-select mr-sm-2'}),
         'grade': Select(attrs={'class': 'custom-select mr-sm-2'}),
         'education': Textarea(attrs={'class': 'form-control'}),
         'experience': Textarea(attrs={'class': 'form-control'})
     }
Beispiel #16
0
    class Meta:
        model = WhiteHat
        fields = ('bio', 'site', 'department', 'public')
        labels = {
            'bio': '一句话简介',
            'department': '部门',
            'site': '个人首页',
            'public': '公开展示个人资料',
        }

        widgets = {
            'bio': Input(**bs4_form),
            'department': Input(**bs4_form),
            'site': Input(**bs4_form),
        }
Beispiel #17
0
    def render(self, name, value, attrs=None):
        substitutions = {
            #uncomment to get 'Currently'
            'initial_text': "", # self.initial_text,
            #'input_text': self.input_text,
            'clear_template': '',
            #'clear_checkbox_label': self.clear_checkbox_label,
            }
        template = '%(input)s'
        substitutions['input'] = Input.render(self, name, value, attrs)

        if value and hasattr(value, "url"):
            #template = self.template_with_initial
            substitutions['initial'] = (
                        '<img src="%s" alt="%s" width="80" height="80"/>'
                                        % (escape(value.url),
                                           escape(force_text(value))))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = conditional_escape(
                                                            checkbox_name)
                substitutions['clear_checkbox_id'] = conditional_escape(
                                                            checkbox_id)
                substitutions['clear'] = CheckboxInput().render(
                            checkbox_name, False, attrs={'id': checkbox_id})
                substitutions['clear_template'] = (self.template_with_clear
                                                        % substitutions)

        return mark_safe(template % substitutions)
Beispiel #18
0
    def render(self, name, value, attrs=None):
        substitutions = {
            'initial_text': self.initial_text, 
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': '',
            }
        template = '%(input)s'
        substitutions['input'] = Input.render(self, name, value, attrs)
        clear_template = '<div class="remove-image"><div class="remove-image btn btn-primary">Remove image</div></div><div class="image-removed">Image removed. Please click Submit to save your changes.</div>' + self.template_with_clear

        if value and hasattr(value, "url"):
            template = self.template_with_initial
            substitutions['initial'] = ('<div class="logo-image-container"><img class="logo-image" src="%s" alt="%s"/></div>'
                                        % (escape(value.url),
                                           escape(force_unicode(value))))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = conditional_escape(checkbox_name)
                substitutions['clear_checkbox_id'] = conditional_escape(checkbox_id)
                substitutions['clear'] = CheckboxInput().render(checkbox_name, False, attrs={'id': checkbox_id})
                substitutions['clear_template'] = clear_template % substitutions

        return mark_safe(template % substitutions)
Beispiel #19
0
    def render(self, name, value, attrs=None):
        id_for_label = self.id_for_label(attrs.get('id'))
        substitutions = {
            'initial_text': self.initial_text,
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': self.clear_checkbox_label,
            # We need the id, so that clicking in the image triggers the "Open file" native window
            'id_for_label': id_for_label,
            #
            'img_id': id_for_label + '_img',
            'initial': self.format_value(value),
        }
        template = '%(input)s'
        substitutions['input'] = Input.render(
            self, name, value, attrs)  # call Input.render directly

        if self.is_initial(value):
            template = self.template_with_initial
            # substitutions.update(self.get_template_substitution_values(value))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = conditional_escape(
                    checkbox_name)
                substitutions['clear_checkbox_id'] = conditional_escape(
                    checkbox_id)
                substitutions['clear'] = CheckboxInput().render(
                    checkbox_name, False, attrs={'id': checkbox_id})
                substitutions[
                    'clear_template'] = self.template_with_clear % substitutions
                # substitutions['initial'] = conditional_escape(self.format_value(value))

        return mark_safe(template % substitutions)
Beispiel #20
0
    def render(self, name, value, attrs=None):
        """Render the custom widget."""
        substitutions = {
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': self.clear_checkbox_label,
        }
        template = '%(input)s'
        substitutions['input'] = Input.render(self, name, value, attrs)

        if value and hasattr(value, "url"):
            template = ('%(initial)s %(clear_template)s<br />%(input_text)s: '
                        '%(input)s')
            substitutions['initial'] = (
                '<img class="img-responsive" src="%s" alt="%s"/>' %
                (escape(value.url), escape(force_unicode(value))))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = conditional_escape(
                    checkbox_name)
                substitutions['clear_checkbox_id'] = conditional_escape(
                    checkbox_id)
                substitutions['clear'] = CheckboxInput().render(
                    checkbox_name, False, attrs={'id': checkbox_id})
                substitutions['clear_template'] = \
                    self.template_with_clear % substitutions
        return mark_safe(template % substitutions)
Beispiel #21
0
    def render(self, name, value, attrs=None):
        substitutions = {
            'initial_text': self.initial_text, 
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': '',
            }
        template = '%(input)s'
        substitutions['input'] = Input.render(self, name, value, attrs)
        clear_template = '<div class="remove-image"><div class="remove-image btn btn-primary">Remove image</div></div><div class="image-removed">Image removed. Please click Submit to save your changes.</div>' + self.template_with_clear

        if value and hasattr(value, "url"):
            template = self.template_with_initial
            substitutions['initial'] = ('<div class="logo-image-container"><img class="logo-image" src="%s" alt="%s"/></div>'
                                        % (escape(value.url),
                                           escape(force_unicode(value))))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = conditional_escape(checkbox_name)
                substitutions['clear_checkbox_id'] = conditional_escape(checkbox_id)
                substitutions['clear'] = CheckboxInput().render(checkbox_name, False, attrs={'id': checkbox_id})
                substitutions['clear_template'] = clear_template % substitutions

        return mark_safe(template % substitutions)
Beispiel #22
0
    def render(self, name, value, attrs=None):
        substitutions = {
            #uncomment to get 'Currently'
            'initial_text': "",  # self.initial_text,
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': self.clear_checkbox_label,
        }
        template = '%(input)s'
        substitutions['input'] = Input.render(self, name, value, attrs)

        if value and hasattr(value, "url"):
            template = self.template_with_initial
            substitutions['initial'] = (
                '<img src="%s" alt="%s"/>' %
                (escape(value.url), escape(force_unicode(value))))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = conditional_escape(
                    checkbox_name)
                substitutions['clear_checkbox_id'] = conditional_escape(
                    checkbox_id)
                substitutions['clear'] = CheckboxInput().render(
                    checkbox_name, False, attrs={'id': checkbox_id})
                substitutions[
                    'clear_template'] = self.template_with_clear % substitutions

        return mark_safe(template % substitutions)
    def render(self, name, value, attrs=None):
        """Render the custom widget."""
        substitutions = {
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': self.clear_checkbox_label,
            }
        template = '%(input)s'
        substitutions['input'] = Input.render(self, name, value, attrs)

        if value and hasattr(value, "url"):
            template = ('%(initial)s %(clear_template)s<br />%(input_text)s: '
                        '%(input)s')
            substitutions['initial'] = (
                '<img class="img-responsive" src="%s" alt="%s"/>' % (
                    escape(value.url), escape(force_unicode(value))))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = conditional_escape(
                    checkbox_name)
                substitutions['clear_checkbox_id'] = conditional_escape(
                    checkbox_id)
                substitutions['clear'] = CheckboxInput().render(
                    checkbox_name, False, attrs={'id': checkbox_id})
                substitutions['clear_template'] = \
                    self.template_with_clear % substitutions
        return mark_safe(template % substitutions)
Beispiel #24
0
    class Meta:
        model = MemberVul
        fields = ('title', 'category', 'detail', 'attachment')
        labels = {
            'title': '漏洞标题',
            'category': '漏洞类型',
            'detail': '漏洞细节',
            'attachment': '附件',
        }

        widgets = {
            'detail': Textarea(**bs4_form),
            'title': Input(**bs4_form),
            'category': Select(**bs4_form),
        }

        error_messages = {
            'title': {
                'required': '标题不能为空',
            },
            'category': {
                'required': '请选择一个分类',
            },
            'detail': {
                'required': '请填写漏洞细节',
            }
        }
Beispiel #25
0
    def _get_form(self, field_name):
        """
        Returns form with from and to fields. The '__alt' fields are alternative
        fields with the correct non localized dateform needed for Django, 
        handled by jsTree.
        """
        from_name = self.parameter_name + '__gte'
        to_name = self.parameter_name + '__lte'

        display_widget = Input(attrs={'class': 'filtrate_date'})
        hidden_widget = HiddenInput(attrs={'class': 'filtrate_date_hidden'})

        def add_fields(fields, name, label):
            fields[name + '__alt'] = f.CharField(label=label,
                                                 widget=display_widget,
                                                 required=False)
            fields[name] = f.CharField(widget=hidden_widget, required=False)

        def add_data(data, name, request):
            date = request.GET.get(name)

            if date:
                data[name + '__alt'] = date

        class DateRangeForm(f.Form):
            def __init__(self, *args, **kwargs):
                super(DateRangeForm, self).__init__(*args, **kwargs)
                add_fields(self.fields, from_name, _('From'))
                add_fields(self.fields, to_name, _('To'))

        data = {}
        add_data(data, from_name, self.request)
        add_data(data, to_name, self.request)
        return DateRangeForm(data=data)
 def test_attr_false_not_rendered(self):
     html = '<input type="None" name="name" value="value">'
     self.check_html(Input(),
                     'name',
                     'value',
                     html=html,
                     attrs={'readonly': False})
Beispiel #27
0
def field_to_widget(field):
    if type(field) is CharField:
        if field.choices:
            return Select(attrs={"class": "form-control"})
        return TextInput(attrs={"class": "form-control", "rows": 1})
    if type(field) is TextField:
        return Textarea(attrs={"class": "form-control", "rows": 1})
    if type(field) is AutoField:
        return HiddenInput(attrs={"class": "form-control", "rows": 1})
    if type(field) is IntegerField or type(field) is FloatField:
        return NumberInput(attrs={"class": "form-control"})
    if type(field) is EmailField:
        return EmailInput(attrs={"class": "form-control"})
    if type(field) is ForeignKey:
        return Select(attrs={"class": "form-control"})
    if type(field) is ManyToManyField:
        return CheckboxSelectMultiple(attrs={"class": ""})
    if type(field) is BooleanField:
        return CheckboxInput(attrs={"class": "form-control"})
    if type(field) is FileField:
        return FileInput(attrs={"class": "form-control"})
    if type(field) is DateField:
        return DateInput(attrs={"class": "form-control date", "type": "date"})
    if type(field) is DateTimeField:
        return DateTimeInput(attrs={"class": "form-control datetimepicker"})

    return Input(attrs={"class": "form-control"})
Beispiel #28
0
 class Meta:
     model = PostComment
     fields = {'author', 'comment'}
     widgets = {
         'author': Input(attrs={'class': 'form-control'}),
         'comment': Textarea(attrs={'cols': 80, 'rows': 3, 'class': 'form-control'}),
     }
Beispiel #29
0
class FiltresForm(forms.Form):
    types = forms.MultipleChoiceField(choices=Anomalie.type_choix,
                                      required=False)
    date = forms.DateField(widget=Input({'type': 'date'}), required=False)
    individu = forms.ModelMultipleChoiceField(queryset=Individu.objects.all(),
                                              required=False)
    nCommande = forms.ModelMultipleChoiceField(queryset=Commande.objects.all(),
                                               required=False)
Beispiel #30
0
 def test_no_trailing_newline_in_attrs(self):
     self.check_html(
         Input(),
         "name",
         "value",
         strict=True,
         html='<input type="None" name="name" value="value">',
     )
Beispiel #31
0
 class Meta:
     model = Gold
     fields = ['weight', 'goldtype']
     widgets = {
         'weight': Input(attrs={'class': 'shadow-sm form-control'}),
         'goldtype': Select(attrs={'class': 'shadow-sm form-control'}),
     }
     labels = {'weight': 'น้ำหนักทอง', 'goldtype': 'ประเภททอง'}
Beispiel #32
0
 class Meta:
     model = Task
     fields = '__all__'
     widgets = {
         'title': Input(attrs={
             'class': 'input',
         })
     }
Beispiel #33
0
 def test_attrs_with_type(self):
     attrs = {"type": "date"}
     widget = Input(attrs)
     self.check_html(
         widget, "name", "value", '<input type="date" name="name" value="value">'
     )
     # reuse the same attrs for another widget
     self.check_html(
         Input(attrs),
         "name",
         "value",
         '<input type="date" name="name" value="value">',
     )
     attrs["type"] = "number"  # shouldn't change the widget type
     self.check_html(
         widget, "name", "value", '<input type="date" name="name" value="value">'
     )
Beispiel #34
0
    def render(self, name, value, attrs=None):
        substitutions = {
            'initial_text': self.initial_text,
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': '',
            }
        template = '%(input)s'
        substitutions['input'] = Input.render(self, name, value, attrs)

        return mark_safe(template % substitutions)
Beispiel #35
0
    def render(self, name, value, attrs=None):
        substitutions = {
            'initial_text': 'Current choice', 
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': self.clear_checkbox_label,
            }
        template = '%(input)s'
        substitutions['input'] = Input.render(self, name, value, attrs)

        if value and hasattr(value, "url"):
            template = self.template_with_initial
            substitutions['initial'] = ('<img src="%s%s" alt="%s"/>' % (SUBSITE, escape(value.url), escape(force_unicode(value))))
            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = conditional_escape(checkbox_name)
                substitutions['clear_checkbox_id'] = conditional_escape(checkbox_id)
                substitutions['clear'] = CheckboxInput().render(checkbox_name, False, attrs={'id': checkbox_id})
                substitutions['clear_template'] = self.template_with_clear % substitutions

        return mark_safe(template % substitutions)
Beispiel #36
0
    def render(self, name, value, attrs=None):
        substitutions = {
            #uncomment to get 'Currently'
            'input_text': self.input_text,
            'clear_template': '',
            'clear_checkbox_label': self.clear_checkbox_label,
        }
        template = """%(input)s"""

        substitutions['input'] = Input.render(self, name, value, attrs)

        if value and hasattr(value, "url"):
            template = """
                <div class="row">
                    <div class="span3">
                        %(input)s
                    </div>
                </div>
            """

            clear_template = """
                Clear: 
                %(clear)s
                """

            substitutions['initial'] = ''

            if not self.is_required:
                checkbox_name = self.clear_checkbox_name(name)
                checkbox_id = self.clear_checkbox_id(checkbox_name)
                substitutions['clear_checkbox_name'] = conditional_escape(
                    checkbox_name)
                substitutions['clear_checkbox_id'] = conditional_escape(
                    checkbox_id)
                substitutions['clear'] = ''
                substitutions['clear_template'] = ''

        return mark_safe(template % substitutions)
Beispiel #37
0
 def __init__(self, lookup_name, attrs=None):
     Input.__init__(self, attrs)
     AutocompleteWidget.__init__(self, lookup_name, attrs)