Hey Christian, I suspect it could be cleaned up just a tad, but the amateur code in me says that's about the same way I'd handle it. I've been toying with little projects of my own for the past couple years, wanting to put together a set of lego blocks for applications to use. Any chance you'd be interested in talking ( gtalk perhaps) and maybe seeing if we could team up on something?
William 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_security.html > 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/auth_tut/models.py#L53-55 > > > https://github.com/peletiah/pyramid_auth_demo_sqlalchemy/blob/master/auth_tut/views.py#L65 > > > https://github.com/peletiah/pyramid_auth_demo_sqlalchemy/blob/master/auth_tut/security.py#L10 > > > > 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/auth_tut/views.py#L44 > > > https://github.com/peletiah/pyramid_auth_demo_sqlalchemy/blob/master/auth_tut/templates/home.mako#L3-9 > > > 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 > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To view this discussion on the web visit https://groups.google.com/d/msg/pylons-discuss/-/SPWblzZ-XxcJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
