Hi,
I am currently trying to write my own blog and I use parts of ZBlog as a guideline (but I am coming from the pylons-camp, so the controller part is not that important for me since I use the pylons controllers).
Things seem to work very well, but now I have a problem where I am not sure how to deal with it.
The blog is supposed to run for several persons that shall be able to write/edit/... their own posts and create/edit comments to other people's posts. So, amongst other things, I have a Comment class, which gets mapped to my comments table. Fine so far, I guess.
Now, for each comment that is read from the database, I would like to automatically add some additional attributes, as for example: .editable, .destroyable. Depending on the value of these Boolean attributes, my Myghty-templates will decide if they will display an edit/delete-link for each comment. These attributes have different values for each request, depending on the userId of the current visitor (that I store in the Myghty-session object).
So, question 1:
Where in my code would be the right place to assign these attributes? I would like to do this in the __init__ constructor of the Comment class, because then I can simply use the following line:
c.comments = model.Comment.mapper.select_by(...some condition...)
This way, I would not need to call a separate function assign_values(). I could simply pass the list to c.comments and thus to the Myghty-view (Remark for all non-"Pylonists": c.whatever_variable will automatically be passed to the Myghty-template)
Of course, these attributes only makes sense for comment-objects that are passed to the view=Myghty. They don't make any sense for comments that are newly created (after user input), since these attributes aren't mapped to the database.
That's brings me to question 2:
How can I elegantly avoid that these additional attributes are assigned when a new comment object is created in order to store it in the database? (the assignment in the constructor means unnecessary overhead I would like to avoid)
Any input/thoughts would be greatly appreciated!
Thanks, Martin
_________________________________
Schnell und einfach ohne Anschlusswechsel zur Lycos DSL Flatrate wechseln und
3 Monate kostenlos ab effektiven 5,21 EUR pro Monat im ersten Jahr surfen.