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?
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?
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?