Exemple #1
0
def NotificationsHandler(request):
    if request.method == 'GET':
        site = GetSite()
        browser = detect(request)
        template_values = {}
        template_values['site'] = site
        template_values['system_version'] = SYSTEM_VERSION
        member = CheckAuth(request)
        l10n = GetMessages(member, site)
        template_values['l10n'] = l10n
        template_values[
            'page_title'] = site.title + u' › ' + l10n.create_new_topic.decode(
                'utf-8')
        if member:
            template_values['member'] = member
            if member.private_token is None:
                member.private_token = hashlib.sha256(
                    str(member.num) + ';' + config.site_key).hexdigest()
                member.save()
            notifications = memcache.get('nn::' + member.username_lower)
            if notifications is None:
                q = Notification.objects.filter(
                    for_member_num=member.num).order_by('-num')[:50]
                notifications = []
                i = 0
                for n in q:
                    if i == 0:
                        if member.notification_position != n.num:
                            member.notification_position = n.num
                            member.save()
                    if n.type == 'reply':
                        n.text = u'<a href="/member/' + n.member.user.username + u'"><strong>' + n.member.user.username + u'</strong></a> 在 <a href="' + n.link1 + '">' + escape(
                            n.label1) + u'</a> 里回复了你'
                        notifications.append(n)
                    if n.type == 'mention_reply':
                        n.text = u'<a href="/member/' + n.member.user.username + u'"><strong>' + n.member.user.username + u'</strong></a> 在回复 <a href="' + n.link1 + '">' + escape(
                            n.label1) + u'</a> 时提到了你'
                        notifications.append(n)
                    if n.type == 'mention_topic':
                        n.text = u'<a href="/member/' + n.member.user.username + u'"><strong>' + n.member.user.username + u'</strong></a> 在创建主题 <a href="' + n.link1 + '">' + escape(
                            n.label1) + u'</a> 时提到了你'
                        notifications.append(n)
                    if n.type == 'follow':
                        n.text = u'<a href="/member/' + n.member.user.username + u'"><strong>' + n.member.user.username + u'</strong></a> 关注了你'
                        notifications.append(n)
                    i = i + 1
                member.notifications = 0
                member.save()
                memcache.set('Member_' + str(member.num), member, 86400)
                memcache.set('nn::' + member.username_lower, notifications,
                             360)
            template_values['notifications'] = notifications
            template_values['title'] = u'提醒系统'
            path = os.path.join('desktop', 'notifications.html')
            return render_to_response(path, template_values)
        else:
            return HttpResponseRedirect('/signin')
Exemple #2
0
def NotificationsHandler(request):
    if request.method == 'GET':
        site = GetSite()
        browser = detect(request)
        template_values = {}
        template_values['site'] = site
        template_values['system_version'] = SYSTEM_VERSION
        member = CheckAuth(request)
        l10n = GetMessages(member, site)
        template_values['l10n'] = l10n
        template_values['page_title'] = site.title + u' › ' + l10n.create_new_topic.decode('utf-8')
        if member:
            template_values['member'] = member
            if member.private_token is None:
                member.private_token = hashlib.sha256(str(member.num) + ';' + config.site_key).hexdigest()
                member.save()
            notifications = memcache.get('nn::' + member.username_lower)
            if notifications is None:
                q = Notification.objects.filter(for_member_num=member.num).order_by('-num')[:50]
                notifications = []
                i = 0
                for n in q:
                    if i == 0:
                        if member.notification_position != n.num:
                            member.notification_position = n.num
                            member.save()
                    if n.type == 'reply':
                        n.text = u'<a href="/member/' + n.member.user.username + u'"><strong>' + n.member.user.username + u'</strong></a> 在 <a href="' + n.link1 + '">' + escape(n.label1) + u'</a> 里回复了你'
                        notifications.append(n)
                    if n.type == 'mention_reply':
                        n.text = u'<a href="/member/' + n.member.user.username + u'"><strong>' + n.member.user.username + u'</strong></a> 在回复 <a href="' + n.link1 + '">' + escape(n.label1) + u'</a> 时提到了你'
                        notifications.append(n)
                    if n.type == 'mention_topic':
                        n.text = u'<a href="/member/' + n.member.user.username + u'"><strong>' + n.member.user.username + u'</strong></a> 在创建主题 <a href="' + n.link1 + '">' + escape(n.label1) + u'</a> 时提到了你'
                        notifications.append(n)
                    if n.type == 'follow':
                        n.text = u'<a href="/member/' + n.member.user.username + u'"><strong>' + n.member.user.username + u'</strong></a> 关注了你'
                        notifications.append(n)
                    i = i + 1
                member.notifications = 0
                member.save()
                memcache.set('Member_' + str(member.num), member, 86400)
                memcache.set('nn::' + member.username_lower, notifications, 360)
            template_values['notifications'] = notifications
            template_values['title'] = u'提醒系统'
            path = os.path.join('desktop', 'notifications.html')
            return render_to_response(path, template_values)
        else:
            return HttpResponseRedirect('/signin')