Re: "Per-user" polymorphism -- newbie question

Toni Alatalo <[email protected]>
Newsgroups gmane.comp.web.quixote.user
Message-ID <[email protected]>
Al Pacifico wrote:

>is authorized and what he/she is authorized to do is determined by a lookup
>in an external resource (for this application, an LDAP directory). The level
>  
>
ok.

>I'd like to make my content served by Quixote essentially polymorphic,
>determined by the role the user takes. This points me in the direction of
>  
>
yes,

>subclassing a base class for each role. I imagine q_lookup() would call a
>method within a class determined by the client's role.
>  
>
or just having several instances of the same class, but with different 
parameters?

hm, do you mean something like:

#this is totally untested and not too much thought of either..

class Content:
    """ Basic content class - also defines the interface."""
    def __init__(self, text):
         self.text = text

class PolymorphicContent:
    """ Content that has many versions for e.g. different people based 
on roles / clearance. """
    def __init__(self, role2text):
        self.role2text = role2text

    def get_text(self):
        requester = Requester(quixote.get_request().get_user())
        return self.role2text[requester.role]
    text = property(get_text)

frontpage = PolymorphicContent({ \
    'anonymous': 'Welcome, do %s an accout' % href(register()),
    'user': 'Welcome back, %s' % user,
    'admin': 'Currently logged in are: %s' % users
}

def _q_index():
    return frontpage.text

?

>each class will have a set of stylesheets that are class attributes derived
>from class methods (pardon me if my OO-terminology is a bit off, but what I
>mean is every instance of a given class will share the same set of
>stylesheets, each a singleton). The libxml2 and libxslt modules seem to work
>really well for this.
>  
>
the terminology sounds sane .. if you wanna have some attribute, e.g. 
the stylesheet used, the same for all instances of a class, it makes 
sense to have it as a class attribute. and they can be derived from 
'class methods' .. i guess that's static methods in python (or just 
functions?)

>Is this problem really as trivial as it seems?
>  
>
i don't get that part on xml processing really, but didn't see anything 
that would make this non-trivial :)

>Before experimenting with my own ideas, I'd like to solicit ideas about how
>others would incorporate this into a q_lookup() method?
>Thanks in advance.
>  
>
i didn't really think of that (the code example above is just .. trying 
to illustrate your question)

dunno if it might be relevant or interesting for you or anyone here, but 
i have a related publication draft about some old research we did on 
this a while ago .. really simple basic stuff, 
http://an.org/owla/jodi.html 'Visual specification of adaptive 
hypermedia' but connected to OO design too.

>-al
>
~Toni
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.