コード例 #1
0
def Task_NotificationsReplyHandler(reply_id):
    try:
        reply = Reply.objects.get(id=reply_id)
        topic = GetKindByNum('Topic', reply.topic_num)
        ms = re.findall('(@[a-zA-Z0-9\_]+\.?)\s?', reply.content)
        keys = []
        if (len(ms) > 0):
            for m in ms:
                m_id = re.findall('@([a-zA-Z0-9\_]+\.?)', m)
                if (len(m_id) > 0):
                    if (m_id[0].endswith('.') != True):
                        member_username = m_id[0]
                        member = GetMemberByUsername(member_username)
                        if member:
                            if member.id != topic.member.id and member.id != reply.member.id and member.id not in keys:
                                q = Counter.objects.filter(
                                    name='notification.max')
                                if (len(q) == 1):
                                    counter = q[0]
                                    counter.value = counter.value + 1
                                else:
                                    counter = Counter()
                                    counter.name = 'notification.max'
                                    counter.value = 1
                                q2 = Counter.objects.filter(
                                    name='notification.total')
                                if (len(q2) == 1):
                                    counter2 = q2[0]
                                    counter2.value = counter2.value + 1
                                else:
                                    counter2 = Counter()
                                    counter2.name = 'notification.total'
                                    counter2.value = 1

                                notification = Notification()
                                notification.num = counter.value
                                notification.type = 'mention_reply'
                                notification.payload = reply.content
                                notification.label1 = topic.title
                                notification.link1 = '/t/' + str(
                                    topic.num) + '#reply' + str(topic.replies)
                                notification.member = reply.member
                                notification.for_member_num = member.num

                                keys.append(member.id)

                                counter.save()
                                counter2.save()
                                notification.save()
        ITQM = ITaskQueueManage()
        for k in keys:
            ITQM.add(data='/notifications/check/' + str(k))
    except:
        print "itaskqueue.py - Task_NotificationsReplyHandler error:" + str(
            sys.exc_info())
コード例 #2
0
ファイル: itaskqueue.py プロジェクト: hitigon/woosuko
def Task_NotificationsReplyHandler(reply_id):
    try:
        reply = Reply.objects.get(id=reply_id)
        topic = GetKindByNum('Topic', reply.topic_num)
        ms = re.findall('(@[a-zA-Z0-9\_]+\.?)\s?', reply.content)
        keys = []
        if (len(ms) > 0):
            for m in ms:
                m_id = re.findall('@([a-zA-Z0-9\_]+\.?)', m)
                if (len(m_id) > 0):
                    if (m_id[0].endswith('.') != True):
                        member_username = m_id[0]
                        member = GetMemberByUsername(member_username)
                        if member:
                            if member.id != topic.member.id and member.id != reply.member.id and member.id not in keys:
                                q = Counter.objects.filter(name='notification.max')
                                if (len(q) == 1):
                                    counter = q[0]
                                    counter.value = counter.value + 1
                                else:
                                    counter = Counter()
                                    counter.name = 'notification.max'
                                    counter.value = 1
                                q2 = Counter.objects.filter(name='notification.total')
                                if (len(q2) == 1):
                                    counter2 = q2[0]
                                    counter2.value = counter2.value + 1
                                else:
                                    counter2 = Counter()
                                    counter2.name = 'notification.total'
                                    counter2.value = 1

                                notification = Notification()
                                notification.num = counter.value
                                notification.type = 'mention_reply'
                                notification.payload = reply.content
                                notification.label1 = topic.title
                                notification.link1 = '/t/' + str(topic.num) + '#reply' + str(topic.replies)
                                notification.member = reply.member
                                notification.for_member_num = member.num

                                keys.append(member.id)

                                counter.save()
                                counter2.save()
                                notification.save()
        ITQM = ITaskQueueManage()
        for k in keys:
            ITQM.add(data='/notifications/check/' + str(k))
    except :
        print "itaskqueue.py - Task_NotificationsReplyHandler error:" + str(sys.exc_info())
コード例 #3
0
def Task_NotificationsTopicHandler(topic_id):
    topic = Topic.objects.get(id=topic_id)
    combined = topic.title + " " + topic.content
    ms = re.findall('(@[a-zA-Z0-9\_]+\.?)\s?', combined)
    keys = []
    if (len(ms) > 0):
        for m in ms:
            m_id = re.findall('@([a-zA-Z0-9\_]+\.?)', m)
            if (len(m_id) > 0):
                if (m_id[0].endswith('.') != True):
                    member_username = m_id[0]
                    member = GetMemberByUsername(member_username)
                    if member:
                        if member.id != topic.member.id and member.id not in keys:
                            q = Counter.objects.filter(name='notification.max')
                            if (len(q) == 1):
                                counter = q[0]
                                counter.value = counter.value + 1
                            else:
                                counter = Counter()
                                counter.name = 'notification.max'
                                counter.value = 1
                            q2 = Counter.objects.filter(
                                name='notification.total')
                            if (len(q2) == 1):
                                counter2 = q2[0]
                                counter2.value = counter2.value + 1
                            else:
                                counter2 = Counter()
                                counter2.name = 'notification.total'
                                counter2.value = 1

                            notification = Notification()
                            notification.num = counter.value
                            notification.type = 'mention_topic'
                            notification.payload = topic.content
                            notification.label1 = topic.title
                            notification.link1 = '/t/' + str(
                                topic.num) + '#reply' + str(topic.replies)
                            notification.member = topic.member
                            notification.for_member_num = member.num

                            keys.append(member.id)

                            counter.save()
                            counter2.save()
                            notification.save()
    ITQM = ITaskQueueManage()
    for k in keys:
        ITQM.add(data='/notifications/check/' + str(k))
コード例 #4
0
ファイル: itaskqueue.py プロジェクト: hitigon/woosuko
def Task_NotificationsTopicHandler(topic_id):
        topic = Topic.objects.get(id=topic_id)
        combined = topic.title + " " + topic.content
        ms = re.findall('(@[a-zA-Z0-9\_]+\.?)\s?', combined)
        keys = []
        if (len(ms) > 0):
            for m in ms:
                m_id = re.findall('@([a-zA-Z0-9\_]+\.?)', m)
                if (len(m_id) > 0):
                    if (m_id[0].endswith('.') != True):
                        member_username = m_id[0]
                        member = GetMemberByUsername(member_username)
                        if member:
                            if member.id != topic.member.id and member.id not in keys:
                                q = Counter.objects.filter(name='notification.max')
                                if (len(q) == 1):
                                    counter = q[0]
                                    counter.value = counter.value + 1
                                else:
                                    counter = Counter()
                                    counter.name = 'notification.max'
                                    counter.value = 1
                                q2 = Counter.objects.filter(name='notification.total')
                                if (len(q2) == 1):
                                    counter2 = q2[0]
                                    counter2.value = counter2.value + 1
                                else:
                                    counter2 = Counter()
                                    counter2.name = 'notification.total'
                                    counter2.value = 1

                                notification = Notification()
                                notification.num = counter.value
                                notification.type = 'mention_topic'
                                notification.payload = topic.content
                                notification.label1 = topic.title
                                notification.link1 = '/t/' + str(topic.num) + '#reply' + str(topic.replies)
                                notification.member = topic.member
                                notification.for_member_num = member.num

                                keys.append(member.id)

                                counter.save()
                                counter2.save()
                                notification.save()
        ITQM = ITaskQueueManage()
        for k in keys:
            ITQM.add(data='/notifications/check/' + str(k))
コード例 #5
0
ファイル: favorite.py プロジェクト: hitigon/woosuko
def FollowMemberHandler(request, one_num):
    if request.method == 'GET':
        if 'HTTP_REFERER' in request.META:
            go = request.META['HTTP_REFERER']
        else:
            go = '/'
        member = CheckAuth(request)
        if member:
            one = GetKindByNum('Member', int(one_num))
            if one is not False:
                if one.num != member.num:
                    q = MemberBookmark.objects.filter(one=one, member_num=member.num)
                    if len(q) == 0:
                        member = Member.objects.get(id=member.id)
                        member.favorited_members = member.favorited_members + 1
                        if member.favorited_members > 30:
                            session = request.session
                            session['message'] = '最多只能添加 30 位特别关注'
                        else:
                            bookmark = MemberBookmark()
                            bookmark.one = one
                            bookmark.member_num = member.num
                            bookmark.save()
                            member.save()
                            memcache.set('Member_' + str(member.num), member, 86400)
                            n = 'r/m' + str(one.num) + '/m' + str(member.num)
                            memcache.set(n, True, 86400 * 14)
                            one = Member.objects.get(id=one.id)
                            one.followers_count = one.followers_count + 1
                            memcache.set('Member_' + str(one.num), one, 86400)
                            memcache.set('Member::' + str(one.username_lower), one, 86400)
                            session = request.session
                            session['message'] = '特别关注添加成功,还可以添加 ' + str(30 - member.favorited_members) + ' 位'
                            # Send notification to following
                            q = Counter.objects.filter(name='notification.max')
                            if (len(q) == 1):
                                counter = q[0]
                                counter.value = counter.value + 1
                            else:
                                counter = Counter()
                                counter.name = 'notification.max'
                                counter.value = 1
                            q2 = Counter.objects.filter(name='notification.total')
                            if (len(q2) == 1):
                                counter2 = q2[0]
                                counter2.value = counter2.value + 1
                            else:
                                counter2 = Counter()
                                counter2.name = 'notification.total'
                                counter2.value = 1

                            notification = Notification()
                            notification.num = counter.value
                            notification.type = 'follow'
                            notification.payload = ''
                            notification.label1 = ''
                            notification.link1 = ''
                            notification.member = member
                            notification.for_member_num = one.num

                            one.notifications = one.notifications + 1

                            one.save()
                            counter.save()
                            counter2.save()
                            notification.save()
        return HttpResponseRedirect(go)
コード例 #6
0
ファイル: favorite.py プロジェクト: minisin/woosuko
def FollowMemberHandler(request, one_num):
    if request.method == 'GET':
        if 'HTTP_REFERER' in request.META:
            go = request.META['HTTP_REFERER']
        else:
            go = '/'
        member = CheckAuth(request)
        if member:
            one = GetKindByNum('Member', int(one_num))
            if one is not False:
                if one.num != member.num:
                    q = MemberBookmark.objects.filter(one=one,
                                                      member_num=member.num)
                    if len(q) == 0:
                        member = Member.objects.get(id=member.id)
                        member.favorited_members = member.favorited_members + 1
                        if member.favorited_members > 30:
                            session = request.session
                            session['message'] = '最多只能添加 30 位特别关注'
                        else:
                            bookmark = MemberBookmark()
                            bookmark.one = one
                            bookmark.member_num = member.num
                            bookmark.save()
                            member.save()
                            memcache.set('Member_' + str(member.num), member,
                                         86400)
                            n = 'r/m' + str(one.num) + '/m' + str(member.num)
                            memcache.set(n, True, 86400 * 14)
                            one = Member.objects.get(id=one.id)
                            one.followers_count = one.followers_count + 1
                            memcache.set('Member_' + str(one.num), one, 86400)
                            memcache.set('Member::' + str(one.username_lower),
                                         one, 86400)
                            session = request.session
                            session['message'] = '特别关注添加成功,还可以添加 ' + str(
                                30 - member.favorited_members) + ' 位'
                            # Send notification to following
                            q = Counter.objects.filter(name='notification.max')
                            if (len(q) == 1):
                                counter = q[0]
                                counter.value = counter.value + 1
                            else:
                                counter = Counter()
                                counter.name = 'notification.max'
                                counter.value = 1
                            q2 = Counter.objects.filter(
                                name='notification.total')
                            if (len(q2) == 1):
                                counter2 = q2[0]
                                counter2.value = counter2.value + 1
                            else:
                                counter2 = Counter()
                                counter2.name = 'notification.total'
                                counter2.value = 1

                            notification = Notification()
                            notification.num = counter.value
                            notification.type = 'follow'
                            notification.payload = ''
                            notification.label1 = ''
                            notification.link1 = ''
                            notification.member = member
                            notification.for_member_num = one.num

                            one.notifications = one.notifications + 1

                            one.save()
                            counter.save()
                            counter2.save()
                            notification.save()
        return HttpResponseRedirect(go)