Suppose I have three different types of users: buyer, distributor, and
reseller.
All buyers, distributors, and resellers have an email, password, and
ratings. Since email and password are already part of auth_user, the
ratings Field will be an extra field in auth_user.
To separate the user roles, we can user auth_membership and auth_group to
designate an auth_user as a 'buyer', 'distributor', or 'reseller'.
Although each user role uses the same backend code for storing email and
password (through auth_user), how would one go about storing a custom
rating mechanism for each user role?
For example, let's say:
A buyer is rated with some combination of # of product reviews written and
credible purchase history.
A reseller is rated with some combination of buyer reviews and warranty
service.
A distributor is rated with reseller reviews.
Assuming I have the following functions which returns on an integer with
range 1 - 100 for ratings:
def buyer_calc_rating(): # Random calcluation for this example
comment_num = len(db(db.comments.user == db.buyer.id).select())
purchase_history = #... some calculation that returns int
return comment_num + purchase_history
def reseller_calc_rating(); # Assume similar calculation returns int
def distributor_calc_rating(); # Assume similar calculation returns int
I have two questions:
- How would I go about assigning these functions to user's ratings Field in
auth_user?
- How would the ratings be dynamically updated each time something changes
pertaining to rating calculation (ie, when a buyer rates a seller, etc)?
Would the preferred way be to stick the above functions in a module
which is then called wherever some controller function changes ratings? I
would always get an update-to-date rating on the user this way (simply by
querying 'db.auth_user.rating'), but that would also be a code-maintanence
nightmare since I would have to keep track of all the places in the code
that manipulates ratings?
Thanks in advance.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.