Monday, March 28, 2016

Re: Django Forms vs Angularjs


I was working on it last couple of days. Basically I came up with what Fabio's solution. Thanks Daniel for 'disabled' field comment as well.  

On Saturday, March 26, 2016 at 8:49:17 AM UTC-4, Daniel Hepper wrote:
Fabio,

if you are using Django 1.9, you can use the newly introduced disabled attribute on forms.Field, see https://docs.djangoproject.com/ja/1.9/ref/forms/fields/#disabled

On Tuesday, March 22, 2016 at 3:36:34 PM UTC+1, Fabio Caritas Barrionuevo da Luz wrote:

self.fields[name].widget.attrs['disabled'] = 'disabled'
self.fields[name].widget.attrs['readonly']=True

is not make real readonly to field, because if user can edit the html on client side, and remove disabled="disabled" and readonly input atributtes

to problem of readonly fields, i currently use this:

https://github.com/luzfcb/django-simple-history/blob/wip-generic-views2/simple_history/forms.py


I prevent it here https://github.com/luzfcb/django-simple-history/blob/wip-generic-views2/simple_history/forms.py#L24

Usage:

class FooBar(models.Model):
    foo = models.TextField(blank=True)
    bar = models.TextField(blank=True)

class MyFooBarForm(forms.ModelForm):
    class Meta:
        object = FooBar
        fields = ('foo', 'bar')

class MyReadOnlyBarForm(ReadOnlyFieldsMixin, forms.ModelForm):
    readonly_fields = ('bar')
    class Meta:
        object = FooBar
        fields = ('foo', 'bar')

my_all_field_readonly_foobarForm = new_readonly_form_class(MyFooBarForm)

my_foo_field_readonly_foobarForm = new_readonly_form_class(MyFooBarForm, readonly_fields=('foo',))


I do not know if this is the best approach, but it was what I got so far.





On Tue, Mar 22, 2016 at 10:57 AM, Gorkem Tolan <gorke...@gmail.com> wrote:
Actually I do to set permission to each field. A field in the form can be viewable and editable, only viewable, or hidden.  So if user has a permission to see the form, but edit some fields in the form, it gets very tricky especially for validation.
For example I used these statements to make readonly field :
self.fields[name].widget.attrs['disabled'] = 'disabled'
self.fields[name].widget.attrs['readonly']=True
Then the problem rises not to be able send disabled fields in the post. 

On Tuesday, March 22, 2016 at 9:31:43 AM UTC-4, bobhaugen wrote:
Maybe you already know this, but you can do a lot of form tinkering in __init__, like so:

    def __init__(self, permissions_parameter=None, *args, **kwargs):
        super(FormName, self).__init__(*args, **kwargs)
        if permissions_parameter:
            #do a bunch of form tinkering

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/877bb8f8-4b59-4353-a0e5-99e95f55811b%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Fábio C. Barrionuevo da Luz
Palmas - Tocantins - Brasil - América do Sul


Blog colaborativo sobre Python e tecnologias Relacionadas, mantido totalmente no https://github.com/pythonclub/pythonclub.github.io .

Todos são livres para publicar. É só fazer fork, escrever sua postagem e mandar o pull-request. Leia mais sobre como publicar em README.md e contributing.md.
Regra básica de postagem:
"Você" acha interessante? É útil para "você"? Pode ser utilizado com Python ou é útil para quem usa Python? Está esperando o que? Publica logo, que estou louco para ler...

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7342bff0-ddc5-4f6d-ab51-9a664a245d3c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment