On Thursday, September 13, 2012 12:00:31 PM UTC-4, Christian Benke wrote:
> Hello!
> Based on
> http://michael.merickel.org/projects/pyramid_auth_demo/object_securit...
> i've adapted the code of the demo to work with SQLAlchemy:
> https://github.com/peletiah/pyramid_auth_demo_sqlalchemy
> I'm new to Pyramid and although i've been scripting with Python for a
> while, OO-programming is still confusing for me.
> The code above works, but i have doubts if the way i implemented it is
> reusable and scalable and if i did it in a "pythonic" way.
> Here are some questions:
> I have to fetch the "user"-object for a "login" so i've added the
> function "get_user" after the User-class-definition in models.py(I use
> this query in "login_view" in views.py and "groupfinder" in
> security.py).
> I did the same with the function "get_page" to fetch the "page"-object
> for an "uri".
> This doesn't seem to be very clean, having arbitrary functions lying
> around in the models-Module. Is there a better place to put such a
> function - or actually another way to do the login-checking?
> Here are the links to the code i've mentioned:
> https://github.com/peletiah/pyramid_auth_demo_sqlalchemy/blob/master/...
> https://github.com/peletiah/pyramid_auth_demo_sqlalchemy/blob/master/...
> https://github.com/peletiah/pyramid_auth_demo_sqlalchemy/blob/master/...
> In "views.home_view" i check if the user is already logged in and
> display information in "templates/home.mako" accordingly. Since a
> query for .one() returns an exception if no match is found, i use
> .first() instead, which returns None. Would it be "cleaner" to reuse
> the "models.get_user"-Function again and then work with try/except to
> return "None" when the user is not logged in?
> https://github.com/peletiah/pyramid_auth_demo_sqlalchemy/blob/master/...
> https://github.com/peletiah/pyramid_auth_demo_sqlalchemy/blob/master/...
> There are some other queries in views(Which only occur once, but might
> be reused multiple times in a larger project) - what is the general
> rule of thumb - where do i put such queries to get a tidy codebase?
> Thanks,
> Christian