Exemple #1
0
class ImpactHandler(BaseHandler):
    impact_manager = None

    def prepare(self):
        self.impact_manager = ImpactManager(self.db)

    def get(self, aid):
        """查看用户印象"""
        impacts = self.impact_manager.list_impact(aid)
        total = self.impact_manager.total_impact_num(aid)
        name = self.get_cookie('i_%s' % aid, None)
        if name:
            try:
                name = "".join([(len(i) > 0 and unichr(int(i, 16)) or "") for i in name.split('%u')])
            except ValueError:
                name = None
        self.render('front/impact.html', impacts=impacts, total=total, name=name, aid=aid)

    def post(self, *args, **kwargs):
        """用户添加印象"""
        result = {'r': 0}
        aid = args[0]
        has = self.get_cookie('i_%s' % aid, None)
        if has:
            result['error'] = '已经添加过印象了~'
            self.write(result)
            return
        _id = self.get_argument('id', None)
        if _id:
            self.impact_manager.vote_to_impact(int(_id))
        result['r'] = 1
        self.write(result)
Exemple #2
0
 def prepare(self):
     self.impact_manager = ImpactManager(self.db)