MarkokraM schrieb:
> Hi,
> 
> i thought this place best to ask this question as i'm developing my
> very first apps with TurboGears. I come from php background and couple
> of months ago i wanted to expand my programming language skills. I met
> and liked python because of its simple and elegant syntax. On php land
> there are a plethora of web frameworks which is cool and not so cool
> at the same. Almost everytime i have found myself developing my own
> framework for the specific app.
> 
> With python its another thing. Since i dont have experience with that
> language, im not interested to create own framework. There seems to be
> just few web frameworks available so i have constructed tutorial app
> with Django, Pylons and TurboGears. At this moment i dont know which
> one to decide (or should i combine them somehow) and i need still more
> exercise apps created.
> 
> Ok, lets that be the forewords and going to the subject and question
> itself.
> 
> I want to create method to retrieve and save user settings depending
> on which storage or placeholder is available at the moment. On my app,
> user can be guest or member type (including all the different members
> as regular member, admin, moderator, superuser etc.). Now if user is
> guest there are three levels of settings inheritance:
> 
> + Application
>    + Cookie
>       + Session
>          (+ POST)
> 
> with member there is one more level between application and cookie:
> 
> + Application
>    + Data (-base or file)
>       + Cookie
>          + Session
>             (+ POST)
> 
> Now if i want to retrieve variable for member i make a call:
> get_user_variable('variable_name') and it seeks through all the
> levels. Upper level overriders lower levels variables so first i get
> an initial value from Application, then seeking data layer, again
> cookie layer and finally session layer.
> 
> When updating values i get data from POST request and move it down to
> data layer if user is member and to cookie (if available) or session
> layer if user is guest.

Something along these lines (untested):


class ConfigWrapper(object):
     def __init__(self, config):
         self._c = config

     def __getattr__(self, name):
         return self._c.get(name)

class CookieWrapper(object):
     def __init__(self, cookie):
         self._c = cookie

     def __getattr__(self, name):
         return self._c[name]


     def __getattr__(self, name):

def get_user_variable(name):
     for context in (cherrypy.request, cherrypy.session, 
CookieWrapper(cherrypy.request.simple_cookie), identity.current.user, 
ConfigWrapper(config)):
          value = getattr(context, name, None)
          if value is not None:
             return value

Diez

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to