Hey Marty,
I don't claim to fully understand what your problem is, but...
I think you're on the right track for putting the properties in the __init__
method for your class. I'm not sure why you're worried about the overhead,
though, since it seems to be something like:
if currentUser.perms == godlike:
self.deletable = True
self.editable = True
but maybe there's more to it then that. Perhaps a quick check to see if the
object is coming from the database, and then doing the various logic branches
would be appropriate? I usually use the existence/value of a primary key
field as a check:
if hasattr(self, 'pk') == True:
if curentUser.perms == godlike...
else:
self.deletable = True...
Otherwise... more information, please? :)
-G
On Tuesday, May 9, 2006, 2:18:18 AM, you wrote:
>
> 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.
>
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users