def get_by_user(self, user, see=False): notifis = models.Notifi.objects.filter(user=user).order_by('-id') dicts = tools._make_dicts(notifis) if see: for notifi in notifis: notifi.seen = True notifi.save() return dicts
def provide_expl(self, expl_str, word, user): init_score = point.PROVIDE_EXPL_INIT_POINT expl = self._mgr.explain.add(expl_str=expl_str, word=word, init_score=init_score, source='U%d' % user.id) if not expl: return [] return tools._make_dicts([expl])
def get_expls(self, word, gag_id, user, excl_expl_ids): expls = self._mgr.prefer.query(word, gag_id, user) if not expls: self._get_expls_from_web(word, gag_id) expls = self._mgr.prefer.query(word, gag_id, user) expls = filter(lambda expl: expl.id not in excl_expl_ids, expls)[:5] self._mgr.notifi.hit_word(word, gag_id, user) self._mgr.recomm.going_up(word, gag_id, user) self._mgr.notifi.accum_word(user) res = tools._make_dicts(expls) for i, item in enumerate(res): expl = self._mgr.explain.get(expl_id=item['id']) res[i]['liked'] = self._mgr.prefer.is_liked(user, expl) return res
def get_recomm(self, gag_id, user, excl_recomm_ids): words = self._mgr.recomm.query(gag_id, user) words = filter(lambda word: word.id not in excl_recomm_ids, words)[:5] return tools._make_dicts(words)