Example #1
0
 def test_invalid_ref_number(self, mock_action_get_by_id):
     """ Invalid ref number, cannot find action """
     mock_action_get_by_id.return_value = None
     
     with self.assertRaises(ReplyError) as e:
         Reply.handler("1", "Y", None)
     self.assertEquals("Reply ref num is invalid. Ref num: 1", e.exception.message)
Example #2
0
    def test_invalid_ref_number(self, mock_action_get_by_id):
        """ Invalid ref number, cannot find action """
        mock_action_get_by_id.return_value = None

        with self.assertRaises(ReplyError) as e:
            Reply.handler("1", "Y", None)
        self.assertEquals("Reply ref num is invalid. Ref num: 1",
                          e.exception.message)
Example #3
0
def create_reply(request, article, content):
    reply = Reply()
    reply.article = article
    article.reply_count += 1
    reply.user = request.user
    reply.content = linkify(clean(content, tags=list()), parse_email=True,
                            callbacks=[callbacks.nofollow, callbacks.target_blank])
    return reply
Example #4
0
    def test_invalid_response(self, mock_action_get_by_id):
        """ Response is not Y, y, N, n """
        ref = "1"
        mock_action_get_by_id.return_value = Action()

        with self.assertRaises(ReplyError) as e:
            Reply.handler(ref, ["F"], Player())
        self.assertEquals(e.exception.message, "Reply {} is invalid. Ref num: {}".\
                format("F", ref))
Example #5
0
    def test_invalid_response(self, mock_action_get_by_id):
        """ Response is not Y, y, N, n """
        ref = "1"
        mock_action_get_by_id.return_value = Action()

        with self.assertRaises(ReplyError) as e:
            Reply.handler(ref, ["F"], Player())
        self.assertEquals(e.exception.message, "Reply {} is invalid. Ref num: {}".\
                format("F", ref))
Example #6
0
    def test_disarm(self, mock_action_get_by_id, mock_disarm_handler):
        """ Test disarm """
        ref = "1"
        action = Action()
        action.action = "DISARM"
        mock_action_get_by_id.return_value = action
        mock_disarm_handler.return_value = None  # Don't care about response because handled by other unit tests.

        Reply.handler(ref, ["Y"], Player())
        mock_disarm_handler.assert_called_once_with(action, "Y")
Example #7
0
    def test_valid_kill_no_team_push(selfi, mock_action_get_by_id, mock_kill_handler):
        """ Valid kill, but team not killed """
        ref = "1"
        action = Action()
        action.action = "KILL"
        mock_action_get_by_id.return_value = action
        mock_kill_handler.return_value = None

        Reply.handler(ref, ["Y"], Player())
        mock_kill_handler.assert_called_once_with(action, "Y")
Example #8
0
    def test_disarm(self, mock_action_get_by_id, mock_disarm_handler):
        """ Test disarm """    
        ref = "1"
        action = Action()
        action.action = "DISARM"
        mock_action_get_by_id.return_value = action
        mock_disarm_handler.return_value = None # Don't care about response because handled by other unit tests.

        Reply.handler(ref, ["Y"], Player())
        mock_disarm_handler.assert_called_once_with(action, "Y")
Example #9
0
    def test_valid_kill_no_team_push(selfi, mock_action_get_by_id,
                                     mock_kill_handler):
        """ Valid kill, but team not killed """
        ref = "1"
        action = Action()
        action.action = "KILL"
        mock_action_get_by_id.return_value = action
        mock_kill_handler.return_value = None

        Reply.handler(ref, ["Y"], Player())
        mock_kill_handler.assert_called_once_with(action, "Y")
Example #10
0
def spammer_reset(user_id):
    from model.po import Po, po_rm, reply_rm_if_can
    from zsite_tag import zsite_tag_rm_by_po
    for i in Po.where(user_id=user_id):
        po_rm(user_id, i.id)
        zsite_tag_rm_by_po(i)

    from model.reply import Reply
    for i in Reply.where(user_id=user_id):
        reply_rm_if_can(user_id, i.id)



    from model.wall import Wall
    from model.zsite import Zsite
    z = Zsite.mc_get(user_id)
    total = z.reply_count
    if total:
        reply_list = z.reply_list_reversed(total, 0)
        for reply in reply_list:
            wall = Wall.mc_get(reply.rid)
            if wall:
                wall.reply_rm(reply)


    spammer_new(user_id)
Example #11
0
    def get(self, id):
        link = '/'
        reply = Reply.mc_get(id)
        if reply:
            link = '/wall/%s' % reply.rid

        self.redirect(link, True)
Example #12
0
File: topic.py Project: fy0/Icarus
 def lasted_reply(self):
     from model.reply import Reply, OBJECT_TYPES
     try:
         return Reply.select().where(Reply.related_type==OBJECT_TYPES.TOPIC, Reply.related_id == self.id)\
             .order_by(Reply.time.desc()).get()
     except Reply.DoesNotExist:
         return
Example #13
0
    def get(self, id):
        link = '/'
        reply = Reply.mc_get(id)
        if reply:
            link = '/wall/%s'%reply.rid

        self.redirect(link, True)
Example #14
0
    def get(self, cid, n=1):
        cid = int(cid)
        qs = Reply.where('cid = %s', cid)
        total = qs.count()
        page, limit, offset = page_limit_offset(
            '/reply_list/%s-%%s'%cid,
            total,
            n,
            PAGE_LIMIT,
        )
        li = qs.order_by('id desc')[offset: offset + limit]
        txt_bind(li)
        #print cid == CID_USER
        if cid == CID_USER:
            Wall.mc_bind(li, 'wall', 'rid')
            wall_list = [i.wall for i in li]
            Zsite.mc_bind(wall_list, 'from_user', 'from_id')
            Zsite.mc_bind(wall_list, 'to_user', 'to_id')
        else:
            Po.mc_bind(li, 'po', 'rid')

        Zsite.mc_bind(li, 'user', 'user_id')
        self.render(
            reply_list=li,
            page=page,
        )
Example #15
0
    def inner_handler(cls, message):
        """ Return [(number, msg),...]"""
        action, params = CommandHandler.get_command(message.Body)
        attacker = Util.get_attacker(message.From)

        if action == "KILL":
            return Kill.handler(attacker, params)
        elif action[1:] == "REPLY":
            ref = params.pop(0)[:-1]
            return Reply.handler(ref, params, attacker)
        elif action == "BOMB":
            return Bomb.handler(attacker, params)
        elif action == "INVUL":
            return Invul.handler(attacker, params)
        elif action == "DISARM":
            return Disarm.handler(attacker, params)
        elif action == "SNIPE":
            if message.From != WEI_HAN:
                raise CommandError(action)
            sniper = Player.query(Player.codename == params[0]).get()
            if sniper == None:
                raise DbError(params[0])
            return Snipe.handler(sniper, params[1])
        elif action == "?":
            msg = "Guide for SAMSU Assassins:\n"
            msg += "KILL <target codename>\n"
            msg += "BOMB <mm> <dd> <hour> <min> <place>\n"
            msg += "INVUL <target codename> <mm> <dd> <hour> <min>\n"
            msg += "DISARM <target codename>\n"
            msg += "SNIPE - send message and picture to {}\n".format(WEI_HAN)
            msg += "REPLY - [REPLY <number>] Y or [REPLY <number>] N\n"
            msg += "If you receive an UNKNOWN ERROR or don't get a message that you expect, contact Wei Han at 312-731-0539."
            return [(attacker.key.id(), msg)]
        else:
            raise CommandError(action)
Example #16
0
File: board.py Project: fy0/Icarus
 def lasted_reply(cls, board):
     from model.reply import Reply
     from model.common import OBJECT_TYPES
     try:
         return Reply.select().where(Reply.related_type==OBJECT_TYPES.TOPIC, Reply.extra_id == board.id)\
             .order_by(Reply.time.desc()).get()
     except Reply.DoesNotExist:
         return
def notice_reply():
    pre_pos = kv_int.get(KV_REPLY_NUM)

    #print pre_pos; pre_pos = 0

    c = Reply.raw_sql( 'select max(id) from reply where cid = %s', CID_NOTE)

    pos = c.fetchone()[0]

    if pos > pre_pos:
        d = defaultdict(set)

        for i in Reply.where(cid=CID_NOTE).where( 'id>%s and id<=%s', pre_pos, pos):
            po_id = i.rid
            user_id = i.user_id
            d[po_id].add(user_id)

        for po_id, li in d.iteritems():
            reply_notice_mail(po_id, li)

        kv_int.set(KV_REPLY_NUM, pos)
Example #18
0
File: user.py Project: fy0/Icarus
 def get(self, username):
     user = User.get_by_username(username)
     if user:
         page = self.get_argument('p', '1')
         page = int(page) if page.isdigit() else 1
         count, query = Reply.get_list_by_user(user)
         pagination_ret = pagination(count, query, config.REPLY_PAGE_SIZE, page)
         self.render('user/user_page.html', user=user, tab={'user_reply_page': 'active'}, count=count,
                     avatar_html=avatar_generate(username, user.avatar_color, 167),
                     pagination=pagination_ret, page_url=self.request.path)
     else:
         self.write_error(404)
Example #19
0
def notice_reply():
    pre_pos = kv_int.get(KV_REPLY_NUM)

    #print pre_pos; pre_pos = 0

    c = Reply.raw_sql('select max(id) from reply where cid = %s', CID_NOTE)

    pos = c.fetchone()[0]

    if pos > pre_pos:
        d = defaultdict(set)

        for i in Reply.where(cid=CID_NOTE).where('id>%s and id<=%s', pre_pos,
                                                 pos):
            po_id = i.rid
            user_id = i.user_id
            d[po_id].add(user_id)

        for po_id, li in d.iteritems():
            reply_notice_mail(po_id, li)

        kv_int.set(KV_REPLY_NUM, pos)
Example #20
0
    def post(self, id):
        current_user_id = self.current_user_id
        r = Reply.mc_get(id)
        can_admin = r.can_admin(current_user_id)

        wall = Wall.mc_get(r.rid)
        if r:
            zsite_id_list = wall.zsite_id_list()
            if wall:
                if can_admin is False and (current_user_id in zsite_id_list):
                    can_admin = True

        if can_admin:
            wall.reply_rm(r)
        self.finish({'success':can_admin})
Example #21
0
    def post(self, id):
        current_user_id = self.current_user_id
        r = Reply.mc_get(id)
        can_admin = r.can_admin(current_user_id)

        wall = Wall.mc_get(r.rid)
        if r:
            zsite_id_list = wall.zsite_id_list()
            if wall:
                if can_admin is False and (current_user_id in zsite_id_list):
                    can_admin = True

        if can_admin:
            wall.reply_rm(r)
        self.finish({'success': can_admin})
Example #22
0
def buzz_at_list(user_id, limit, offset):
    po_id_list = []
    reply_id_list = []
    user_id_list = []
    id_list = []
    for id, from_id, po_id, reply_id in buzz_at_col_list(user_id, limit, offset):
        id_list.append(id)
        po_id_list.append(po_id)
        reply_id_list.append(reply_id)
        user_id_list.append(from_id)

    from model.zsite import Zsite
    from model.po import Po
    from model.reply import Reply
    return tuple(zip(
        id_list,
        Zsite.mc_get_list(user_id_list),
        Po.mc_get_list(po_id_list),
        Reply.mc_get_list(reply_id_list),
    ))
Example #23
0
def post_reply(self, id):
    user = self.current_user

    if not user_can_reply(user):
        self.finish('{"can_not_reply":1}')
    else:
        result = []
        txt = self.get_argument('txt', None)

        reply_id = None
        if txt:
            user_id = self.current_user_id
            po = Po.mc_get(id)
            if po.can_view(user_id):
                reply_id = po.reply_new(user, txt, po.state)
                if reply_id:
                    reply = Reply.mc_get(reply_id)
                    reply.user = user
                    result = _reply_list_dump([reply], True, user.id)
        self.finish(dumps(result))
        return reply_id
Example #24
0
def post_reply(self, id):
    user = self.current_user

    if not user_can_reply(user):
        self.finish('{"can_not_reply":1}')
    else:
        result = []
        txt = self.get_argument('txt', None)

        reply_id = None
        if txt:
            user_id = self.current_user_id
            po = Po.mc_get(id)
            if po.can_view(user_id):
                reply_id = po.reply_new(user, txt, po.state)
                if reply_id:
                    reply = Reply.mc_get(reply_id)
                    reply.user = user
                    result = _reply_list_dump([reply], True, user.id)
        self.finish(dumps(result))
        return reply_id
Example #25
0
def po_list_by_buzz_reply_user_id(user_id):
    from model.po import Po
    from model.po_pos import po_pos_get_last_reply_id
    from model.reply import Reply
    from model.buzz_po_bind_user import buzz_po_bind_user

    id_list = po_id_list_by_buzz_reply_user_id(user_id)
    po_list = Po.mc_get_list(id_list)

    po_user_id = []
    for i in po_list:
        pos = po_pos_get_last_reply_id(user_id, i.id)
        new_reply_id_list = []
        for reply_id in i.reply_id_list():
            if reply_id > pos:
                new_reply_id_list.append(reply_id)

        user_id_list = []
        for reply in Reply.mc_get_list(reversed(new_reply_id_list)):
            user_id_list.append(reply.user_id)
        po_user_id.append(user_id_list)

    return buzz_po_bind_user(po_list, po_user_id, user_id)
Example #26
0
def spammer_reset(user_id):
    from model.po import Po, po_rm, reply_rm_if_can
    from zsite_tag import zsite_tag_rm_by_po
    for i in Po.where(user_id=user_id):
        po_rm(user_id, i.id)
        zsite_tag_rm_by_po(i)

    from model.reply import Reply
    for i in Reply.where(user_id=user_id):
        reply_rm_if_can(user_id, i.id)

    from model.wall import Wall
    from model.zsite import Zsite
    z = Zsite.mc_get(user_id)
    total = z.reply_count
    if total:
        reply_list = z.reply_list_reversed(total, 0)
        for reply in reply_list:
            wall = Wall.mc_get(reply.rid)
            if wall:
                wall.reply_rm(reply)

    spammer_new(user_id)
Example #27
0
File: board.py Project: fy0/Icarus
    def reply_count(cls, board, start_time=0):
        from model.reply import Reply
        from model.common import OBJECT_TYPES

        return Reply.select().where(Reply.time>=start_time, Reply.related_type==OBJECT_TYPES.TOPIC,
                             Reply.extra_id == board.id).count()
Example #28
0
 def get(self, id):
     r = Reply.mc_get(id)
     if r:
         r.rm()
     self.finish('{}')
Example #29
0
File: topic.py Project: fy0/Icarus
 def reply_count(self):
     from model.reply import Reply
     from model.common import OBJECT_TYPES
     return Reply.get_count(OBJECT_TYPES.TOPIC, self.id)