Пример #1
0
 def get_rating(self):
     annotations = storage(self.context)
     username = api.user.get_current().getUserName()
     if username in list(annotations.keys()):
         return json.dumps(
             {"current_value": annotations[username]["rating_value"]})
     else:
         return json.dumps({"current_value": 0})
Пример #2
0
 def delete_rating(self):
     annotations = storage(self.context)
     username = api.user.get_current().getUserName()
     if username in list(annotations.keys()):
         del annotations[username]
         return json.dumps({"ok": True})
     else:
         return json.dumps({"ok": False})
Пример #3
0
 def avg_rating(self):
     annotations = storage(self.context)
     if annotations:
         num_rating = len(list(annotations.keys()))
         sum_rating = reduce(
             (lambda x, y: float(x) + float(y)),
             self.rating_list(annotations),
         )
         return float(float(sum_rating) / num_rating)
     else:
         return 0
Пример #4
0
 def max_rating(self, value):
     if self.context.max_rating != value:
         annotations = storage(self.context)
         for user in annotations.keys():
             annotations[user] = {
                 "rating_value":
                 self._new_vote(annotations[user]["rating_value"], value),
                 "user":
                 user,
             }
         self.context.max_rating = value
Пример #5
0
 def update_rating(self, obj, value):
     if obj.max_rating != value:
         annotations = storage(obj)
         for user in annotations.keys():
             annotations[user] = {
                 "rating_value":
                 self._new_vote(annotations[user]["rating_value"], value,
                                obj),
                 "user":
                 user,
             }
         obj.max_rating = value
Пример #6
0
    def update_rating(self):
        current_rating = self.request.get("current_rating", None)
        if current_rating:
            annotations = storage(self.context)
            username = api.user.get_current().getUserName()
            annotations[username] = {
                "user": username,
                "rating_value": current_rating,
            }

        # call catalog to update avg rating of obj
        pc = api.portal.get().portal_catalog
        pc.catalog_object(self.context, idxs=["avg-rating"])
Пример #7
0
 def num_rating(self):
     annotations = storage(self.context)
     return len(list(annotations.keys()))