Dear list,
I've a question as to how to approach a particular (architectual)
problem best and would like your advise. I'm using Quixote 2.3, in case
that matters.
For the sake of argument say I'm building a to-do list (of course the
real problem is with something a bit more complex - I've choosen this
example for its simplicity).
I have two model-classes:
- TodoItem -> has_many: Notes
- Note
Furthermore I have four ui classes:
- TodoListUI -> list items, add item
- TodoItemUI -> display item, edit item
- NotesListUI -> list notes, add notes
- NoteUI -> display note, edit note
The Notes part is something I want to keep generic, so that I can easily
associate notes with any type of object - not just with TodoItems.
The user can access the following urls:
- /todo/ -> TodoListUI -> lists all to do items
- /todo/12/ -> TodoItemUI(12) -> shows todo item 12
- /todo/12/update -> TodoItemUI.update(12, ...) -> updates item 12,
redirects to /todo/12/
- /todo/12/notes/ -> NotesListUI -> displays all notes related to item
12
- /todo/12/notes/3/ -> NoteUI -> displays note 3 (which apperently
related to item 12)
- /todo/12/notes/3/update -> ...
This is quite a 'restfull' layout I'd think. Now comes the issue. In
this scenario the user gets a 'todo item view' with a link to 'notes'.
So to view the related notes and work with them, he has to go to another
page. In order to enhance the user interface, I want to offer a way to
show, add, edit and delete notes from the 'todo item view' (i.e.
inline). And there are various ways one could do that.
I could refactor NotesListUI so that I can do something like (all given
code is pseudo code - it's to illustrate, I don't expect it to run):
"""
class TodoItemUI:
def index():
form = Form()
form.add(TextField, 'todoitemlabel')
form.add(TextField, 'todoitemdescription')
form.render()
NotesListUI.show_notes()
"""
This gives scenario A. Now 'show_notes' could Inline a list of notes in
the TodoItem page, showing part of each note, with 'add', 'edit',
'delete' etc. links linking directly to /todo/#/notes/#/edit, etc. This
seems very clean to me, but makes that the user has to go to another
page to edit a note - I'd rather make is so that the user can edit the
notes inline as well.
Meet scenario B: inline a list of forms, one for each note. Now the user
can edit each note and save it. But what if he edits two notes? Or a
note and the description of the item? That doesn't work, because he can
only submit one form at at time.
So lets do some more refactoring to get to scenario C:
"""
class TodoItemUI:
def create_form()
form = Form()
form.add(TextField, 'todoitemlabel')
form.add(TextField, 'todoitemdescription')
NotesListUI.add_notes(form)
return form
def index():
self.create_form().render()
def update():
f = self.create_form()
NotesListUI.update(f)
TodoItem.update()
redirect('to the note')
"""
Now the NotesListUI is refactored so that it exposes a method that will
add a set of HTML form fields for each note (probably delegating the
generation of each individual note-entry to NoteUI). TodoItemUI tunnels
the submitted form values to the NotesListUI, which for each note will
call the NoteUI.
The above approach (scenario C) seems best to me - but perhaps you folks
have better ideas.
Also it has at least one issue. What if I want to have a paragraph of
text between the Todo-fields and the Notes in the 'todoitem' view?
Should I add a 'rawhtml' widget to the forms library and insert that in
between?
Best regards,
Jeroen van Dongen
_______________________________________________
Quixote-users mailing list
[email protected]
http://mail.mems-exchange.org/mailman/listinfo/quixote-users