def get(self, n=1): zsite_id = self.zsite_id cid = self.cid page_template = self.page_template total = fav_po_count_by_user_id_cid(zsite_id, cid) n = int(n) page, limit, offset = page_limit_offset( page_template, total, n, PAGE_LIMIT ) if n != 1 and offset >= total: return self.redirect(page_template[:-3]) li = fav_po_list_by_user_id_cid(zsite_id, cid, limit, offset) if cid == CID_WORD: rid_po_list = [i for i in li if i.rid] Po.mc_bind(rid_po_list, 'question', 'rid') Zsite.mc_bind([i.target for i in rid_po_list], 'user', 'user_id') self.render( cid=cid, total=total, li=li, page=page, back_a='/fav', )
def __init__(self, pid, event_list): self.pid = pid self.place = place_name(pid) self.province_id = pid_province(pid) event_list.sort(key=lambda x: x.begin_time) Po.mc_bind(event_list, 'po', 'id') self.event_list = event_list
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, )
def get(self, n=1): qs = Po.where("state>%s", STATE_RM).where("zsite_id=user_id") total = qs.count() page, limit, offset = page_limit_offset("/po/zsite-%s", total, n, PAGE_LIMIT) li = qs.order_by("id desc")[offset : offset + limit] Po.mc_bind(li, "question", "rid") self.render(po_list=li, page=page)
def rec_read_po_rm_fix(): for i in redis.keys(REDIS_TAG_CID % ('*', '*')): tag_id = i[7:15] cid = int(i.split(":")[-1]) for j in redis.zrange(i, 0, -1): po = Po.mc_get(j) if po.state < STATE_ACTIVE: _tag_rm_by_user_id_list(po, po.user_id, [tag_id]) print "po_tag_rm_by_po(po)", tag_id, j for i in redis.keys(REDIS_REC_TAG_NEW % '*'): for j in redis.smembers(i): po = Po.mc_get(j) if po.state < STATE_ACTIVE: redis.srem(i, j) print po.link print i, j for i in redis.keys(REDIS_REC_TAG_OLD % '*'): for j in redis.zrange(i, 0, -1): po = Po.mc_get(j) if po.state < STATE_ACTIVE: print po.link redis.zrem(i, j) for i in redis.keys(REDIS_REC_USER_LOG % '*'): for j in redis.zrange(i, 0, -1): po = Po.mc_get(j) if po.state < STATE_ACTIVE: print po.link redis.zrem(i, j) for i in redis.keys(REDIS_REC_USER_PO_TO_REC % ('*', '*')): print i redis.delete(i)
def get(self, n=1): zsite_id = self.zsite_id user_id = self.current_user_id zsite = self.zsite zsite_cid = zsite.cid if zsite_cid == CID_SITE: self.template = '/ctrl/zsite/po_view/site_po_page.htm' else: self.template = '/ctrl/zsite/po_view/po_page.htm' cid = self.cid page_template = self.page_template n = int(n) if zsite_cid == CID_SITE: total = po_cid_count_by_zsite_id(zsite_id, cid) else: is_self = zsite_id == user_id total = po_list_count(zsite_id, cid, is_self) page, limit, offset = page_limit_offset( page_template, total, n, PAGE_LIMIT ) if n != 1 and offset >= total: return self.redirect(page_template[:-3]) if zsite_cid == CID_SITE: po_list = feed_po_list_by_zsite_id(user_id, zsite_id, cid, limit, offset) back_a = None total = 0 else: po_list = po_view_list(zsite_id, cid, is_self, limit, offset) if cid == CID_WORD: rid_po_list = [i for i in po_list if i.rid] Po.mc_bind(rid_po_list, 'question', 'rid') Zsite.mc_bind([i.target for i in rid_po_list], 'user', 'user_id') if is_self: back_a = '/feed' else: back_a = '/' self.render( cid=cid, total=total, li=po_list, page=page, back_a=back_a, )
def sync_recommend(id, po_id): from po import Po p = Po.mc_get(po_id) s = state_oauth_id_by_zsite_id_cid(id, SYNC_CID_SHARE) for oauth_id in s: rec_po = Po.mc_get(p.rid) if rec_po: txt = cnencut(p.name_, 20) if txt: txt = '%s -> '%txt else: txt = txt+"分享: " sync_by_oauth_id(oauth_id, txt + cnencut(rec_po.name_,50) , 'http:%s'%rec_po.link)
def sync_recommend(id, po_id): from po import Po p = Po.mc_get(po_id) s = state_oauth_id_by_zsite_id_cid(id, SYNC_CID_SHARE) for oauth_id in s: rec_po = Po.mc_get(p.rid) if rec_po: txt = cnencut(p.name_, 20) if txt: txt = '%s -> ' % txt else: txt = txt + "分享: " sync_by_oauth_id(oauth_id, txt + cnencut(rec_po.name_, 50), 'http:%s' % rec_po.link)
def get(self, n=1): qs = Po.where('state>%s', STATE_RM).where('zsite_id=user_id') total = qs.count() page, limit, offset = page_limit_offset( '/po/zsite-%s', total, n, PAGE_LIMIT, ) li = qs.order_by('id desc')[offset:offset + limit] Po.mc_bind(li, 'question', 'rid') self.render( po_list=li, page=page, )
def rss_tag(): from model.rss import RSS_PO_ID_STATE_NOTAG, CID_USER, RssPoId, RSS_PO_ID_STATE_AUTOTAG from zweb.orm import ormiter from zdata.idf.tfidf import tag_id_rank_list_by_txt, ID2NAME from model.po import Po from operator import itemgetter from model.po_tag_user import tag2idlist_po_user, rss_po_new from zkit.algorithm.unique import unique for rss_po_id in ormiter( RssPoId, 'user_cid=%s and state=%s' % (CID_USER, RSS_PO_ID_STATE_NOTAG)): po = Po.mc_get(rss_po_id.po_id) if not po: continue #print po.name_ txt = '%s\n%s' % (po.name_, po.txt) tag_id_rank_list = tag_id_rank_list_by_txt(txt)[:7] tag_id_list = map(itemgetter(0), tag_id_rank_list) user_tag_id_list = map( int, tag2idlist_po_user.tag_id_list_by_id(po.user_id)) id_list = user_tag_id_list[:] id_list.extend(tag_id_list) rss_po_id.tag_id_list = ' '.join(map(str, unique(id_list))) #for i in tag_id_list: # i.append_id_tag_id_list #print i.tag_id_list #raise rss_po_id.state = RSS_PO_ID_STATE_AUTOTAG rss_po_id.save() rss_po_new(po, user_tag_id_list)
def post(self, po_id=0): cid = CID_AUDIO name = self.get_argument("name", None) txt = self.get_argument("txt", None) link = "/feed" if po_id: po_id = int(po_id) po = Po.mc_get(po_id) if po and po.user_id == self.current_user_id: po.name_ = name po.txt_set(txt) po.save() link = "/po/tag/%s" % po_id else: audio = self._audio() if audio: user_id = self.current_user_id zsite_id = zsite_id_by_zsite_user_id(self.zsite, user_id) if zsite_id: state = STATE_PO_ZSITE_SHOW_THEN_REVIEW else: state = STATE_ACTIVE po = po_audio_new(user_id, name, txt, audio, state, zsite_id=zsite_id) if po: po_id = po.id link = "/po/tag/%s" % po_id return self.redirect(link)
def get(self, id): po = Po.mc_get(id) if po: link = po.link else: link = '/' self.redirect(link)
def get(self, zsite_tag_id, n=1): tag = ZsiteTag.mc_get(zsite_tag_id) zsite_id = self.zsite_id user_id = self.current_user_id cid = self.cid is_self = zsite_id == user_id n = int(n) total = zsite_tag_cid_count(zsite_tag_id, cid) page, limit, offset = page_limit_offset( '/tag/%s'%zsite_tag_id + self.page_template, total, n, PAGE_LIMIT ) if n != 1 and offset >= total: return self.redirect(self.page_template[:-3]) po_list = Po.mc_get_list(po_id_list_by_zsite_tag_id_cid(zsite_tag_id, cid, limit, offset)) self.render( cid=cid, is_self=is_self, total=total, li=po_list, page=page, tag_name=Tag.get(tag.tag_id), back_a='/tag/%s'%zsite_tag_id )
def get(self, id): from model.rss import rss_link_by_po_id link = rss_link_by_po_id(id) if not link: po = Po.mc_get(id) link = po.link self.redirect(link, True)
def get(self, id): # data = { # "zsite":{ # "name":"w", # "unit":"xx", # "title":"zz" # }, # "name":"2011年第2次BPUG活动", # "id":1234, # "fav":True, # "reply_count":1, # "tag_id":232, # "tag_name":"sss" # } po = Po.mc_get(id) user = po.user result = [id] result.extend(feed_tuple_by_db(id)) result.pop() result.pop() result.append(po.htm) zsite = [user.name, user.link] zsite.extend(career_current(po.user_id)) result.append(zsite) self.finish(dumps(result))
def get(self, id): po = Po.mc_get(id) if po: link = po.link else: link = '/' return self.redirect(link, True)
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)
def post(self, po_id=0): cid = CID_PHOTO name = self.get_argument('name', None) txt = self.get_argument('txt', None) user_id = self.current_user_id link = '/feed' if po_id: po_id = int(po_id) po = Po.mc_get(po_id) if po and po.user_id == user_id: po.name_ = name po.txt_set(txt) po.save() link = '/po/tag/%s' % po_id else: img = self._img() if img: zsite_id = zsite_id_by_zsite_user_id(self.zsite, user_id) if zsite_id: state = STATE_PO_ZSITE_SHOW_THEN_REVIEW else: state = STATE_ACTIVE po = po_photo_new(user_id, name, txt, img, state, zsite_id) if po: po_id = po.id link = '/po/tag/%s' % po_id return self.redirect(link)
def post(self, po_id=0): cid = CID_VIDEO url = self.get_argument('video', None) name = self.get_argument('name', None) txt = self.get_argument('txt', None) link = '/feed' if po_id: po_id = int(po_id) po = Po.mc_get(po_id) if po and po.user_id == self.current_user_id: po.name_ = name po.txt_set(txt) po.save() link = '/po/tag/%s' % po_id else: if url: video, video_site = video_filter(url) if video: user_id = self.current_user_id zsite_id = zsite_id_by_zsite_user_id(self.zsite, user_id) if zsite_id: state = STATE_PO_ZSITE_SHOW_THEN_REVIEW else: state = STATE_ACTIVE po = po_video_new(user_id, name, txt, video, video_site, state, zsite_id) if po: po_id = po.id link = '/po/tag/%s' % po_id return self.redirect(link)
def get(self, n=1): qs = Event.where() total = qs.count() page, limit, offset = page_limit_offset( '/event-%s', total, n, PAGE_LIMIT, ) li = qs.order_by('id desc')[offset: offset + limit] Po.mc_bind(li, 'po', 'id') self.render( 'god/event/event_page.htm', stat=0, li=li, page=page, )
def post(self, id): current_user_id = self.current_user_id rec_po = Po.mc_get(id) if rec_po and rec_po.cid == CID_REC and rec_po.user_id == current_user_id: name = self.get_argument('txt', '') rec_po.name_ = name rec_po.save() self.finish('{}')
def get(self, n=1): qs = Event.where() total = qs.count() page, limit, offset = page_limit_offset( '/event-%s', total, n, PAGE_LIMIT, ) li = qs.order_by('id desc')[offset:offset + limit] Po.mc_bind(li, 'po', 'id') self.render( 'god/event/event_page.htm', stat=0, li=li, page=page, )
def get(self, state, n=1): state = int(state) qs = Event.where(state=state) total = qs.count() page, limit, offset = page_limit_offset( '/event/%s-%%s' % state, total, n, PAGE_LIMIT, ) li = qs.order_by('id desc')[offset: offset + limit] Po.mc_bind(li, 'po', 'id') self.render( stat=state, li=li, page=page, )
def get(self, state, n=1): state = int(state) qs = Event.where(state=state) total = qs.count() page, limit, offset = page_limit_offset( '/event/%s-%%s' % state, total, n, PAGE_LIMIT, ) li = qs.order_by('id desc')[offset:offset + limit] Po.mc_bind(li, 'po', 'id') self.render( stat=state, li=li, page=page, )
def get(self, id): next = self.request.headers.get('Referer', '') po = Po.mc_get(id) if po: self.render( po=po, next=next, )
def _site_po_goto_direct(sql): c = Po.raw_sql( sql, site_id, site_id, STATE_PO_ZSITE_SHOW_THEN_REVIEW, ).fetchone() return c[0] if c is not None else 0
def po(self, id): po = Po.mc_get(id) if po: if po.cid in PO_SHARE_FAV_CID and po.can_view(self.current_user_id): if po.user_id == self.zsite_id or not po.user_id: return po return self.redirect(po.link) return self.redirect('/')
def po(self, id): po = Po.mc_get(id) if po: self._po = po if po.user_id == self.zsite_id: return po return self.redirect(po.link) return self.redirect('/')
def site_po_iter(id_list, limit=MAXINT, begin_id=MAXINT): id_list = list(merge_iter(id_list, limit, begin_id)) po_list = Po.mc_get_list(id_list) zsite_set = set() for i in po_list: zsite_set.add(i.zsite_id) zsite_set.add(i.user_id) zsite_dict = Zsite.mc_get_dict(zsite_set) result = [] pre_zsite_id = None m = [] zsite_set = set() if po_list: last_id = po_list[-1].id for i in po_list: if pre_zsite_id != i.zsite_id: if pre_zsite_id: result.append([pre_zsite_id, m]) zsite_set.add(zsite_dict[pre_zsite_id]) m = [] pre_zsite_id = i.zsite_id cid = i.cid t = [] t.append(i.id) t.append(cid) if cid == CID_WORD: t.append(i.htm) else: t.append(i.name) if i.zsite_id != i.user_id: user = zsite_dict[i.user_id] t.append(user.link) t.append(user.name) m.append(t) result.append([i.zsite_id, m]) zsite_set.add(zsite_dict[i.zsite_id]) else: last_id = 0 ico_url_bind_with_default(zsite_set) for i in result: id = i[0] zsite = zsite_dict[id] i[0] = [id, zsite.name, zsite.link, zsite.ico] return result, last_id
def post(self, id): po = Po.mc_get(id) name = self.get_argument('name', None) txt = self.get_argument('txt', None) if name: po.name_ = name po.save() if txt: po.txt_set(txt) self.redirect('/event')
def _sync_site_po(begin_id): ss = SiteSync.where('id>%s', begin_id).order_by('id')[0] if ss: begin_id = ss.id zsite = Zsite.mc_get(ZSITE_BIND_FOR_SYNC) if zsite: po = Po.mc_get(ss.po_id) if po: sync_site_po(po, zsite) return begin_id
def get(self, id): po = Po.mc_get(id) user_id = self.current_user_id result = [] if po and po.can_view(user_id): for reply in po.reply_list(): user = reply.user result.append((url_or_id(user.id), reply.htm, user.name)) return self.finish(dumps(result))
def get(self, id): po = Po.mc_get(id) current_user_id = self.current_user_id if po: link = po.link_reply pos, state = po_pos_get(current_user_id, id) if pos > 0: link = '%s#reply%s' % (link, pos) else: link = '/' self.redirect(link)
def post(self, id): po = Po.mc_get(id) next = self.get_argument("next", "/po") broad = self.get_argument("broad", None) site = self.get_argument("site", None) sync = self.get_argument("sync", None) if po: _edit(broad, sync, site, po, id) return self.redirect(next) self.render(po=po, next=next)
def rank_update(po_id): up = vote_up_count(po_id) down = vote_down_count(po_id) po = Po.mc_get(po_id) _hot = hot(up, down, po.create_time) _confidence = confidence(up, down) for r in Rank.where(po_id=po_id): r.hot = _hot r.confidence = _confidence r.save() mc_flush_cid(r.to_id, r.cid)
def post(self, id): po = Po.mc_get(id) next = self.get_argument("next", "/po") name = self.get_argument("name", None) txt = self.get_argument("txt", None) if name: po.name_ = name po.save() if txt: po.txt_set(txt) self.redirect(next)
def _po(self, id): current_user = self.current_user current_user_id = self.current_user_id po = Po.mc_get(id) if not po: self.redirect('/') return if not po.can_admin(current_user_id): self.redirect(po.link) return return po
def reply_notice_mail(po_id, li): po = Po.mc_get(po_id) if not (po and po.zsite_id != po.user_id): return li = Zsite.mc_get_list(li) if not li: return pos, state = po_pos_get(po.user_id, po_id) #print pos if pos != -1: return zsite = Zsite.mc_get(po.user_id) if zsite and zsite.cid == CID_USER: mail = mail_by_user_id(po.user_id) if mail: li0 = li[0] name_list = [li0.name] name_list.extend(career_current(li0.id)) name_title = ' , '.join(filter(bool, name_list)) if len(li) > 1: subject = '%s人 回复 %s ( %s 等 )' % (len(li), po.name, name_title) else: subject = '%s 回复 %s' % (name_title, po.name) rendermail('/mail/notice/notice_reply.htm', mail, zsite.name, format='html', subject=subject, reply_list=li, po=po, zsite=zsite) mail = '*****@*****.**' rendermail('/mail/notice/notice_reply.htm', mail, zsite.name, format='html', subject=subject, reply_list=li, po=po, zsite=zsite)
def buzz_po_reply_rm(po_id, reply_id): from po_pos import PoPos, STATE_BUZZ from model.po import Po po = Po.mc_get(po_id) if not po: return reply_id_last = po.reply_id_last if po and reply_id >= reply_id_last: for user_id in PoPos.where(po_id=po_id, state=STATE_BUZZ).where('pos>=%s', reply_id_last).col_list(col='user_id'): BuzzReply.where(po_id=po_id, user_id=user_id, state=BUZZ_REPLY_STATE_SHOW).update(state=BUZZ_REPLY_STATE_HIDE) mc_flush(user_id) buzz_at_reply_rm(reply_id)
def _po(self, user_id, id): self.po = po = Po.mc_get(id) if po: if po.can_admin(user_id): cid = po.cid self.cid = cid if cid == CID_WORD and po.rid == 0: return self.redirect(po.link) return po return self.redirect(po.link) return self.redirect('/')