Opened 8 years ago

Closed 8 years ago

#3295 closed enhancement (wontfix)

[patch] newforms: I'd like to have a group functionality in forms

Reported by: ivan Owned by: nobody
Component: Forms Version:
Severity: normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by adrian)

I use my custom group fields in my class forms.

I set an attribute in my form class:

 class myform(forms):
     field1 = ...
     field2 = ...
     group_myfields = ['field1','field2']

field1 and field2 are fields sets in my custom form class.

I can retrive html output, writing this:

myform().myfields.as_p()
myform().myfields.as_table()

and retrive only fileds listed in group_myfields.

Attachments (2)

forms.diff (12.1 KB) - added by ivan 8 years ago.
groups_in_forms.patch (1.8 KB) - added by Honza Král <Honza.Kral@…> 8 years ago.
proper patch format

Download all attachments as: .zip

Change History (7)

Changed 8 years ago by ivan

comment:1 Changed 8 years ago by ivan

  • Summary changed from I'd like to have a group functionality in forms. to [patch] newforms: I'd like to have a group functionality in forms

Changed 8 years ago by Honza Král <Honza.Kral@…>

proper patch format

comment:2 Changed 8 years ago by Honza Král <Honza.Kral@…>

I just created a patch using svn diff for easier review by others...

The code seems to be working - all tests pass and it doesn't interfere with rest of the code. On the other hand I feel like more work needs to be done on this - its not systematic and rather hackish...

comment:3 Changed 8 years ago by adrian

  • Triage Stage changed from Unreviewed to Design decision needed

I'm not sure whether this functionality is worth adding...

comment:4 Changed 8 years ago by adrian

  • Description modified (diff)

Fixed formatting in description.

comment:5 Changed 8 years ago by jacob

  • Resolution set to wontfix
  • Status changed from new to closed

There's really no reason to add this as a built-in -- it's easy to do yourself:

class MyForm(Form):
   field1 = ...
   field2 = ...

   @property
   def mygroup(self):
      return {'field1': self.field1, 'field2': self.field2}

This gets you the same {{ form.mygroup.field1 }} behavior you're looking for. It could be further abstracted out into an abstract Form subclass if you need to do this often.

Note: See TracTickets for help on using tickets.
Back to Top