Hello,
If, for example, the reputation score is stored in a column of the users'
table as an integer, you could write the following repoze.what predicate
checker:
"""
from repoze.what.predicates import Predicate
class minimum_reputation(Predicate):
message = "Your minimum score reputation must be of at least " \
"%(minimum_score)s, but you have %(current_score)s"
def __init__(self, minimum_score, **kwargs):
super(minimum_reputation, self).__init__(**kwargs)
self.minimum_score = minimum_score
def evaluate(self, environ, credentials):
current_user = get_user_db_object_from_somewhere()
if current_user.score < self.minimum_score:
self.unmet(current_score=current_user.score)
"""
For more info:
http://static.repoze.org/whatdocs/Manual/Predicates/index.html
Then you can use it in your actions, like this:
"""
from repoze.what.plugins.pylonshq import ActionProtector
from somewhere import minimum_reputation
class MyCoolController(BaseController):
@ActionProtector(minimum_reputation(5))
def some_action(self):
# This code is executed if the current user has
# a reputation score of at least 5. If not, authorization
# will be denied and s/he will see a message that reads:
# "Your minimum score reputation must be of at least 5
# but you have X" (where X is her/his current score)
"""
For more info about this, check:
http://code.gustavonarea.net/repoze.what-pylons/Manual/Protecting.html
By the way, if you may want to create the following aliases:
"""
class good_reputation(minimum_reputation):
def __init__(self, **kwargs):
super(good_reputation, self).__init__(3, **kwargs)
class excellent_reputation(minimum_reputation):
def __init__(self, **kwargs):
super(excellent_reputation, self).__init__(5, **kwargs)
"""
HTH,
- Gustavo.
On Thursday April 23, 2009 15:56:22 [email protected] wrote:
> We are developing social networking application in Pylons. We use
> username-password system and permission which comes part of
> repoze.what/who. Now we need to give permission to certain resources
> based on user reputation score.
>
> What is the architecture required using repoze.what? Can some one
> through sample/example code?
>
> We are first time web developers and getting hard into Pylons but
> managing well.. Any help shall be greatly appreciated
>
>
--
Gustavo Narea <xri://=Gustavo>.
| Tech blog: =Gustavo/(+blog)/tech ~ About me: =Gustavo/about |
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---