def get(self, member_username): site = GetSite() one = GetMemberByUsername(member_username) if one: if one.avatar_mini_url: if (one.avatar_mini_url[0:1] == '/'): one.avatar_mini_url = 'http://' + site.domain + one.avatar_mini_url one.avatar_normal_url = 'http://' + site.domain + one.avatar_normal_url one.avatar_large_url = 'http://' + site.domain + one.avatar_large_url template_values = {} template_values['site'] = site template_values['one'] = one path = os.path.join(os.path.dirname(__file__), 'tpl', 'api', 'member.json') self.response.headers['Content-type'] = 'application/json;charset=UTF-8' output = template.render(path, template_values) self.response.out.write(output) else: self.error(404)
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())
def get(self, member_username): site = GetSite() one = GetMemberByUsername(member_username) if one: if one.avatar_mini_url: if (one.avatar_mini_url[0:1] == '/'): one.avatar_mini_url = 'http://' + site.domain + one.avatar_mini_url one.avatar_normal_url = 'http://' + site.domain + one.avatar_normal_url one.avatar_large_url = 'http://' + site.domain + one.avatar_large_url template_values = {} template_values['site'] = site template_values['one'] = one path = os.path.join(os.path.dirname(__file__), 'tpl', 'api', 'member.json') self.response.headers[ 'Content-type'] = 'application/json;charset=UTF-8' output = template.render(path, template_values) self.response.out.write(output) else: self.error(404)
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))
def MemberHandler(request, member_username): if request.method == 'GET': site = GetSite() browser = detect(request) session = request.session template_values = {} template_values['site'] = site template_values['system_version'] = SYSTEM_VERSION member = CheckAuth(request) template_values['member'] = member template_values['show_extra_options'] = False if member: if member.num == 1: template_values['show_extra_options'] = True l10n = GetMessages(member, site) template_values['l10n'] = l10n one = False one = GetMemberByUsername(member_username) if one is not False: if one.followers_count is None: one.followers_count = 0 template_values['one'] = one template_values[ 'page_title'] = site.title + u' › ' + one.user.username template_values[ 'canonical'] = 'http://' + site.domain + '/member/' + one.user.username if one is not False: blog = Topic.objects.filter( node_name='blog', member_num=one.num).order_by('-created') if len(blog) > 0: template_values['blog'] = blog[0] q2 = Topic.objects.filter( member_num=one.num).order_by('-created')[:10] template_values['topics'] = q2 replies = memcache.get('member::' + str(one.num) + '::participated') if replies is None: q3 = Reply.objects.filter( member_num=one.num).order_by('-created')[0:100] ids = [] replies = [] i = 0 for reply in q3: if reply.topic.num not in ids: i = i + 1 if i > 10: break replies.append(reply) ids.append(reply.topic.num) if len(replies) > 0: memcache.set('member::' + str(one.num) + '::participated', replies, 7200) if len(replies) > 0: template_values['replies'] = replies template_values['show_block'] = False template_values['show_follow'] = False template_values['favorited'] = False if one and member: if one.num != member.num: template_values['show_follow'] = True template_values['show_block'] = True try: blocked = pickle.loads(member.blocked.encode('utf-8')) except: blocked = [] if one.num in blocked: template_values['one_is_blocked'] = True else: template_values['one_is_blocked'] = False if member.hasFavorited(one): template_values['favorited'] = True else: template_values['favorited'] = False if 'message' in session: template_values['message'] = session['message'] del session['message'] if one is not False: if browser['ios']: path = os.path.join('mobile', 'member_home.html') else: path = os.path.join('desktop', 'member_home.html') else: if browser['ios']: path = os.path.join('mobile', 'member_not_found.html') else: path = os.path.join('desktop', 'member_not_found.html') return render_to_response(path, template_values)
def MemberHandler(request, member_username): if request.method == 'GET': site = GetSite() browser = detect(request) session = request.session template_values = {} template_values['site'] = site template_values['system_version'] = SYSTEM_VERSION member = CheckAuth(request) template_values['member'] = member template_values['show_extra_options'] = False if member: if member.num == 1: template_values['show_extra_options'] = True l10n = GetMessages(member, site) template_values['l10n'] = l10n one = False one = GetMemberByUsername(member_username) if one is not False: if one.followers_count is None: one.followers_count = 0 template_values['one'] = one template_values['page_title'] = site.title + u' › ' + one.user.username template_values['canonical'] = 'http://' + site.domain + '/member/' + one.user.username if one is not False: blog = Topic.objects.filter(node_name='blog',member_num=one.num).order_by('-created') if len(blog) > 0: template_values['blog'] = blog[0] q2 = Topic.objects.filter(member_num=one.num).order_by('-created')[:10] template_values['topics'] = q2 replies = memcache.get('member::' + str(one.num) + '::participated') if replies is None: q3 = Reply.objects.filter(member_num=one.num).order_by('-created')[0:100] ids = [] replies = [] i = 0 for reply in q3: if reply.topic.num not in ids: i = i + 1 if i > 10: break replies.append(reply) ids.append(reply.topic.num) if len(replies) > 0: memcache.set('member::' + str(one.num) + '::participated', replies, 7200) if len(replies) > 0: template_values['replies'] = replies template_values['show_block'] = False template_values['show_follow'] = False template_values['favorited'] = False if one and member: if one.num != member.num: template_values['show_follow'] = True template_values['show_block'] = True try: blocked = pickle.loads(member.blocked.encode('utf-8')) except: blocked = [] if one.num in blocked: template_values['one_is_blocked'] = True else: template_values['one_is_blocked'] = False if member.hasFavorited(one): template_values['favorited'] = True else: template_values['favorited'] = False if 'message' in session: template_values['message'] = session['message'] del session['message'] if one is not False: if browser['ios']: path = os.path.join('mobile', 'member_home.html') else: path = os.path.join('desktop', 'member_home.html') else: if browser['ios']: path = os.path.join('mobile', 'member_not_found.html') else: path = os.path.join('desktop', 'member_not_found.html') return render_to_response(path, template_values)