Ejemplo n.º 1
0
class CardForm(StripeCoreForm):

    last_4_digits = fields.CharField(required=True,
                                     min_length=4,
                                     max_length=4,
                                     widget=fields.HiddenInput())

    stripe_token = fields.CharField(required=True, widget=fields.HiddenInput())
    email = fields.EmailField(required=True, widget=fields.HiddenInput())
    name = fields.CharField(required=True, widget=fields.HiddenInput())
Ejemplo n.º 2
0
class ResetPasswordByTokenForm(models.ModelForm):
    confirm_password = fields.CharField(label=_('Confirm password'),
                                        widget=widgets.PasswordInput,
                                        required=True)
    token = fields.HiddenInput(attrs={'type': 'hidden'})
    recaptcha = ReCaptchaField()

    class Meta:
        model = User
        fields = ['password']
        widgets = {'password': widgets.PasswordInput()}
Ejemplo n.º 3
0
class FormComment(forms.ModelForm):
    parent_id = fields.CharField(required=False, widget=fields.HiddenInput())
    content_type_id = fields.CharField(required=False,
                                       widget=fields.HiddenInput())
    object_id = fields.CharField(required=False, widget=fields.HiddenInput())

    class Meta:
        model = Comment
        fields = ['comment', 'content_type_id', 'object_id']
        # widgets = {
        #     # 'comment': forms.Textarea(attrs={'cols': 80, 'rows': 5, 'class': 'span8'}),
        #     'comment': MarkItUpWidget()
        # }

    def __init__(self, *a, **kw):
        retorno = super(FormComment, self).__init__(*a, **kw)

        # id_ = self.instance.id if self.instance else ''

        self.fields['comment'].widget = MarkItUpWidget()
        return retorno

    def save(self, user=None, *args, **kwargs):
        comment = super(FormComment, self).save(commit=False, *args, **kwargs)
        update = False
        if user and not user.is_anonymous():
            comment.author_id = user.id
            update = True
        if self.cleaned_data.get('content_type_id', None):
            comment.content_type_id = self.cleaned_data['content_type_id']
            update = True
        if self.cleaned_data['parent_id']:
            comment.parent = Comment.objects.get(
                pk=self.cleaned_data['parent_id'])
            update = True
        if update:
            comment.save()

        send_notifications.send(sender=self, instance=comment)
        return comment
Ejemplo n.º 4
0
class FormModeration(forms.ModelForm):
    content_type_id = fields.CharField(required=False, widget=fields.HiddenInput())
    object_id = fields.CharField(required=False, widget=fields.HiddenInput())

    class Meta:
        model = Moderation
        fields = ['comment', 'type_', 'content_type_id', 'object_id']
        widgets = {
            'comment': forms.Textarea(attrs={'cols': 80, 'rows': 5, 'class': 'span8'}),
        }

    def save(self, user=None, *args, **kwargs):
        moderation = super(FormModeration, self).save(*args, **kwargs)
        update = False
        if user and not user.is_anonymous():
            moderation.author_id = user.id
            update = True
        if self.cleaned_data.get('content_type_id', None):
            moderation.content_type_id = self.cleaned_data['content_type_id']
            update = True
        if update:
            moderation.save()
        return moderation
Ejemplo n.º 5
0
def test_nonfield_errors(form, request_factory):
    request = request_factory().get('some?__submit=siteform&some=hmm')

    frm = form(
        composer=Composer,
        some=fields.DateField(widget=fields.HiddenInput())
    )(src='GET', request=request)

    frm.is_valid()

    frm.add_error(None, 'Errr1')
    frm.add_error(None, 'Errr2')

    form_html = f'{frm}'
    assert '<div ><div>Errr1</div>\n<div>Errr2</div>' in form_html
    assert 'Hidden field "some": Enter a valid date.' in form_html
Ejemplo n.º 6
0
    def add_fields(self, form, index):
        super(BaseShoeShoeAttributesFormSet, self).add_fields(form, index)

        # this depends on value of extra, which is currently assumed to be 1
        if index is not None and index != self.queryset.count():
            ordered_fields = collections.OrderedDict()
            for k, v in form.fields.items():
                if k == "quantity":
                    v.widget = form_fields.HiddenInput()
                ordered_fields.update({k: v})
                if k == "id":
                    ordered_fields.update({
                        'new_quantity':
                        form_fields.IntegerField(
                            label="Quantity",
                            initial=(form.instance.quantity -
                                     form.instance.dispensed()))
                    })

            form.fields = ordered_fields