Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #259 (closed enhancement: fixed)

Opened 13 years ago

Last modified 12 years ago

[PATCH] Add widgets reordering/selection capabilities to the view using forms

Reported by: Luca <luca@…> Owned by: anonymous
Priority: normal Milestone: 0.9
Component: TG Widgets Version:
Severity: normal Keywords: form widget fastdata datacontroller order select formmaker sqlwidgets patch
Cc:

Description

It would be really nice to have more view-level options to do with forms, one of them is reorder the form (specially for automagic fastdata forms, so you don't have to mix up the view with the model). Another cool feature could be to specify a set of fields to show in a form, so you can reuse the form for different things.

I've mixed this two features together in a new fields parameter that can be used with TableForm? (maybe this can go in the, now useless, parent class Form) insert (and render) method. You can specify the fields to show, and it's order:

class Person(SQLObject):
    name = StringCol(length=255)
    age = IntCol()

class PersonDataController(DataController):
    sql_class = Person
    form_template = 'my.template'

class SomeController:
    person = PersonDataController()

In the controller, and then in the template (my.template):

${form.insert(obj, action=action, fields=['age', 'name'])}

Even for forms defined completely by the user, it could be really nice to define the ordering (presentation issue) in the view and not the controller (the programmer doesn't have to know what is the best way to present the information to the user).

You can also select which fields to show:

${form.insert(obj, action=action, fields=['name'])}

This will only show the name field.

Attachments

tg-r359-form-fields-param.patch Download (1.3 KB) - added by Luca <luca@…> 13 years ago.
patch
tg-r381-form-datacontroller-fields-selection.patch Download (4.3 KB) - added by Luca <luca@…> 13 years ago.
Patch updated to [381] and features added

Change History

Changed 13 years ago by Luca <luca@…>

patch

comment:1 Changed 13 years ago by Luca <luca@…>

  • Summary changed from [patch] Add widgets reordering/selection capabilities to the view using forms to [PATCH] Add widgets reordering/selection capabilities to the view using forms

It looked ugly in the pending patches list =)

Changed 13 years ago by Luca <luca@…>

Patch updated to [381] and features added

comment:2 Changed 13 years ago by Luca <luca@…>

  • Keywords form widget fastdata datacontroller order select formmaker sqlwidgets patch added

The patch was updated for revision [381], merged #260 (mostly because #260 is harmless but it could be separated again if necessary), and added a new feature.

Now you have a new place for selecting what fields to use (and in what order). With previos patch you allready could change how the form was displayed (view), selecting fields and their order. Now you can change how forms are created (controller), selecting fields and their order.

You can now do:

class Person(SQLObject):
    name = StringCol(length=255)
    age = IntCol()
    tel = StringCol(length=20)
    birth = DateCol()

class SomeController:
    person = DataController(Person, form_fields=['name', 'age', 'tel'])

and your form will be created with just the name, age and tel fields, then you can even be more picky in the view and select which fields to show:

class SomeController:
    person = DataController(Person, form_fields=['name', 'age', 'tel'], form_template='my.template')

And in my.template:

${form.insert(obj, action=action, fields=['name', 'tel'])}

The form will still be created with name, age and tel fields, but in the view only name and tell will be shown.

I think this gives great flexibility, easy of use (because you still can write no templates at all and have great control over how the controller is constructed) and keeps view and controller (and model) well separated.

I thought DataController was using Catwalk DataGrid, so you can select which fields to show (and in what order) from CatWalk, but I just realized that DataController has its own DataGrid, so maybe I can add an extra parameter to the DataGrid (list_fields or grid_fields) to select which fields to show in the grid (and in what order). This will solve #268 in a way you don't have to mess the model with presentation stuff.

comment:3 Changed 13 years ago by Jorge Godoy <jgodoy@…>

Indeed, this is better than the "mix" I've done on #268. BUT, you'll still have the 'title' on the model unless you use dictionaries and put the column names as keys and the text that should be shown as values.

I am still in doubt of what is better: having everything that will be related to DB interaction -- including DataController and DataGrid -- with the model or putting this with the controller.

comment:4 Changed 13 years ago by kevin

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

applied in [382]. Thanks!

Note: See TracTickets for help on using tickets.