Beispiel #1
0
 def _getAnswer(self):
     if self._categ is conference.CategoryManager().getRoot():
         raise ServiceError('ERR-U0', _('Cannot add root category as favorite'))
     self._avatar.linkTo(self._categ, 'favorite')
     if redis_write_client:
         suggestions.unignore(self._avatar, 'category', self._categ.getId())
         suggestions.unsuggest(self._avatar, 'category', self._categ.getId())
Beispiel #2
0
def get_suggested_categories(user):
    """Gets the suggested categories of a user for the dashboard"""
    from MaKaC.conference import CategoryManager

    if not redis_write_client:
        return []
    related = user.favorite_categories | user.get_linked_objects('category', 'manager')
    res = []
    for id_, score in suggestions.get_suggestions(user, 'category').iteritems():
        try:
            categ = CategoryManager().getById(id_)
        except KeyError:
            suggestions.unsuggest(user, 'category', id_)
            continue
        if not categ or categ.isSuggestionsDisabled() or categ in related:
            continue
        if any(p.isSuggestionsDisabled() for p in categ.iterParents()):
            continue
        if not categ.canAccess(AccessWrapper(user.as_avatar)):
            continue
        res.append({
            'score': score,
            'categ': categ,
            'path': truncate_path(categ.getCategoryPathTitles()[:-1], chars=50)
        })
    return res
Beispiel #3
0
 def _process_DELETE(self):
     category = CategoryManager().getById(request.view_args['category_id'])
     if category in self.user.favorite_categories:
         self.user.favorite_categories.remove(category)
         if redis_write_client:
             suggestions.unsuggest(self.user, 'category', category.getId())
     return jsonify(success=True)
Beispiel #4
0
 def _process_DELETE(self):
     category = CategoryManager().getById(request.view_args['category_id'])
     if category in self.user.favorite_categories:
         self.user.favorite_categories.remove(category)
         if redis_write_client:
             suggestions.unsuggest(self.user, 'category', category.getId())
     return jsonify(success=True)
Beispiel #5
0
def get_suggested_categories(user):
    """Gets the suggested categories of a user for the dashboard"""
    if not redis_write_client:
        return []
    related = {cat.id for cat in get_related_categories(user, detailed=False)}
    res = []
    categ_suggestions = suggestions.get_suggestions(user, 'category')
    query = (Category.query
             .filter(Category.id.in_(categ_suggestions),
                     ~Category.id.in_(related),
                     ~Category.is_deleted,
                     ~Category.suggestions_disabled)
             .options(undefer('chain_titles')))
    categories = {c.id: c for c in query}
    for id_, score in categ_suggestions.iteritems():
        try:
            categ = categories[int(id_)]
        except KeyError:
            suggestions.unsuggest(user, 'category', id_)
            continue
        if any(p.suggestions_disabled for p in categ.parent_chain_query):
            suggestions.unsuggest(user, 'category', id_)
            continue
        if not categ.can_access(user):
            continue
        res.append({
            'score': score,
            'categ': categ,
            'path': truncate_path(categ.chain_titles[:-1], chars=50)
        })
    return res
Beispiel #6
0
 def _process_PUT(self):
     if self.category not in self.user.favorite_categories:
         if not self.category.can_access(self.user):
             raise Forbidden()
         self.user.favorite_categories.add(self.category)
         if redis_write_client:
             suggestions.unignore(self.user, 'category', str(self.category.id))
             suggestions.unsuggest(self.user, 'category', str(self.category.id))
     return jsonify(success=True)
Beispiel #7
0
 def _getAnswer(self):
     if self._categ is conference.CategoryManager().getRoot():
         raise ServiceError('ERR-U0',
                            _('Cannot add root category as favorite'))
     self._avatar.linkTo(self._categ, 'favorite')
     if redis_write_client:
         suggestions.unignore(self._avatar, 'category', self._categ.getId())
         suggestions.unsuggest(self._avatar, 'category',
                               self._categ.getId())
Beispiel #8
0
 def _process_PUT(self):
     category = CategoryManager().getById(request.view_args['category_id'])
     if category not in self.user.favorite_categories:
         if not category.canAccess(AccessWrapper(self.user.as_avatar)):
             raise Forbidden()
         self.user.favorite_categories.add(category)
         if redis_write_client:
             suggestions.unignore(self.user, 'category', category.getId())
             suggestions.unsuggest(self.user, 'category', category.getId())
     return jsonify(success=True)
Beispiel #9
0
 def _process_PUT(self):
     category = CategoryManager().getById(request.view_args['category_id'])
     if category not in self.user.favorite_categories:
         if not category.canAccess(AccessWrapper(self.user.as_avatar)):
             raise Forbidden()
         self.user.favorite_categories.add(category)
         if redis_write_client:
             suggestions.unignore(self.user, 'category', category.getId())
             suggestions.unsuggest(self.user, 'category', category.getId())
     return jsonify(success=True)
Beispiel #10
0
 def _getAnswer(self):
     suggestions.unsuggest(self._avatar, 'category', self._categ.getId(), True)
Beispiel #11
0
 def _getAnswer(self):
     self._avatar.unlinkTo(self._categ, 'favorite')
     if redis_write_client:
         suggestions.unsuggest(self._avatar, 'category', self._categ.getId())
Beispiel #12
0
 def _process(self):
     suggestions.unsuggest(self.user, 'category', request.view_args['category_id'], True)
     return jsonify(success=True)
Beispiel #13
0
 def _process_DELETE(self):
     if self.category in self.user.favorite_categories:
         self.user.favorite_categories.remove(self.category)
         if redis_write_client:
             suggestions.unsuggest(self.user, 'category', self.category.id)
     return jsonify(success=True)
Beispiel #14
0
 def _process(self):
     suggestions.unsuggest(self.user, 'category',
                           request.view_args['category_id'], True)
     return jsonify(success=True)
Beispiel #15
0
 def _getAnswer(self):
     suggestions.unsuggest(self._avatar, 'category', self._categ.getId(),
                           True)
Beispiel #16
0
 def _getAnswer(self):
     self._avatar.unlinkTo(self._categ, 'favorite')
     if redis_write_client:
         suggestions.unsuggest(self._avatar, 'category',
                               self._categ.getId())