def get(self, cls, bookmark = ''): cls = int(cls) if cls not in range(len(MukioTools.namelist)): self.error(404) return '''Simple paging''' next = None prev = None if bookmark: bookmark = MukioTools.dt_from_str(urllib.unquote(urllib.unquote(bookmark))) arts = Article.all().order('-postdate').filter('classify =',cls).filter('postdate <=',bookmark).fetch(PAGESIZE + 1) else: arts = Article.all().order('-postdate').filter('classify =',cls).fetch(PAGESIZE+1) if len(arts) == PAGESIZE + 1: next = arts[-1].postdate arts = arts[:PAGESIZE] ars = [] for a in arts: a.keyname = a.key().name() a.postdate += timedelta(hours=+8) a.tagname = MukioTools.tagname(a.classify) ars.append(a) if bookmark: arts = Article.all().order('postdate').filter('classify =',cls).filter('postdate >=',bookmark).fetch(PAGESIZE + 1) if len(arts) == PAGESIZE + 1: prev = arts[-1].postdate tmpvars = {'arts':ars,'next':next,'prev':prev,'title':u'分类:' + MukioTools.namelist[cls],'iscls':True,'cls':cls} self.render('articles.html',tmpvars)
def get(self, bookmark=''): '''Simple paging''' next = None prev = None if bookmark: bookmark = MukioTools.dt_from_str( urllib.unquote(urllib.unquote(bookmark))) #self.response.headers['Referer'] = bookmark arts = Article.all().order('-postdate').filter( 'postdate <=', bookmark).fetch(PAGESIZE + 1) else: arts = Article.all().order('-postdate').fetch(PAGESIZE + 1) if len(arts) == PAGESIZE + 1: next = arts[-1].postdate arts = arts[:PAGESIZE] ars = [] for a in arts: a.keyname = a.key().name() a.postdate += timedelta(hours=+8) a.tagname = MukioTools.tagname(a.classify) ars.append(a) if bookmark: arts = Article.all().order('postdate').filter( 'postdate >=', bookmark).fetch(PAGESIZE + 1) if len(arts) == PAGESIZE + 1: prev = arts[-1].postdate tmpvars = {'arts': ars, 'next': next, 'prev': prev} self.render('articles.html', tmpvars)
def get(self, bookmark = ''): '''Simple paging''' next = None prev = None if bookmark: bookmark = MukioTools.dt_from_str(urllib.unquote(urllib.unquote(bookmark))) #self.response.headers['Referer'] = bookmark arts = Article.all().order('-postdate').filter('postdate <=',bookmark).fetch(PAGESIZE + 1) else: arts = Article.all().order('-postdate').fetch(PAGESIZE+1) if len(arts) == PAGESIZE + 1: next = arts[-1].postdate arts = arts[:PAGESIZE] ars = [] for a in arts: a.keyname = a.key().name() a.postdate += timedelta(hours=+8) a.tagname = MukioTools.tagname(a.classify) ars.append(a) if bookmark: arts = Article.all().order('postdate').filter('postdate >=',bookmark).fetch(PAGESIZE + 1) if len(arts) == PAGESIZE + 1: prev = arts[-1].postdate tmpvars = {'arts':ars,'next':next,'prev':prev} self.render('articles.html',tmpvars)
def get(self,email,bookmark = ''): email = urllib.unquote(urllib.unquote(email)) usr = users.User(unicode(email).strip()) next = None prev = None if bookmark: bookmark = MukioTools.dt_from_str(urllib.unquote(urllib.unquote(bookmark))) arts = Article.all().order('-postdate').filter('author = ',usr).filter('postdate <=',bookmark).fetch(PAGESIZE + 1) else: arts = Article.all().order('-postdate').filter('author = ',usr).fetch(PAGESIZE+1) if len(arts) == PAGESIZE + 1: next = arts[-1].postdate arts = arts[:PAGESIZE] ars = [] for a in arts: a.keyname = a.key().name() a.postdate += timedelta(hours=+8) a.tagname = MukioTools.tagname(a.classify) ars.append(a) if bookmark: arts = Article.all().order('postdate').filter('author = ',usr).filter('postdate >=',bookmark).fetch(PAGESIZE + 1) if len(arts) == PAGESIZE + 1: prev = arts[-1].postdate self.render('articles.html',{'arts':ars,'author':usr,'next':next,'prev':prev,'title':usr.nickname() + unicode('的上传列表','utf-8'),'edit':usr == users.get_current_user()})
def post(self): user = users.get_current_user() vkeystr = unicode(self.request.get('videoId')).strip() vkey = db.Key(vkeystr) if not vkey: self.error(404) else: video = Video.get(vkey) path = unicode(self.request.get('path')).strip() if path == '' and self.request.POST.get('localfile') == '': self.redirect('/addvideo/' + video.art.key().name() + '/') else: if video.cblock_set.count(): MukioTools.delete(video.cblock_set)#删除已经存在的外部XML if user != video.art.author: self.error(404)#只有本人才能进行该操作 data = self.getfile() if data: cbk = CBlock(link=path, data=unicode(data,'utf-8'), cid=video) if cbk: cbk.put() self.redirect('/addvideo/' + video.art.key().name() + '/') else: self.error(404)
def post(self): user = users.get_current_user() vkeystr = unicode(self.request.get('videoId')).strip() vkey = db.Key(vkeystr) if not vkey: self.error(404) else: video = Video.get(vkey) path = unicode(self.request.get('path')).strip() if path == '' and self.request.POST.get('localfile') == '': self.redirect('/addvideo/' + video.art.key().name() + '/') else: if video.cblock_set.count(): MukioTools.delete(video.cblock_set) #删除已经存在的外部XML if user != video.art.author: self.error(404) #只有本人才能进行该操作 data = self.getfile() if data: cbk = CBlock(link=path, data=unicode(data, 'utf-8'), cid=video) if cbk: cbk.put() self.redirect('/addvideo/' + video.art.key().name() + '/') else: self.error(404)
def get(self, cls, bookmark=''): cls = int(cls) if cls not in range(len(MukioTools.namelist)): self.error(404) return '''Simple paging''' next = None prev = None if bookmark: bookmark = MukioTools.dt_from_str( urllib.unquote(urllib.unquote(bookmark))) arts = Article.all().order('-postdate').filter( 'classify =', cls).filter('postdate <=', bookmark).fetch(PAGESIZE + 1) else: arts = Article.all().order('-postdate').filter( 'classify =', cls).fetch(PAGESIZE + 1) if len(arts) == PAGESIZE + 1: next = arts[-1].postdate arts = arts[:PAGESIZE] ars = [] for a in arts: a.keyname = a.key().name() a.postdate += timedelta(hours=+8) a.tagname = MukioTools.tagname(a.classify) ars.append(a) if bookmark: arts = Article.all().order('postdate').filter( 'classify =', cls).filter('postdate >=', bookmark).fetch(PAGESIZE + 1) if len(arts) == PAGESIZE + 1: prev = arts[-1].postdate tmpvars = { 'arts': ars, 'next': next, 'prev': prev, 'title': u'分类:' + MukioTools.namelist[cls], 'iscls': True, 'cls': cls } self.render('articles.html', tmpvars)
def get(self, email, bookmark=''): email = urllib.unquote(urllib.unquote(email)) usr = users.User(unicode(email).strip()) next = None prev = None if bookmark: bookmark = MukioTools.dt_from_str( urllib.unquote(urllib.unquote(bookmark))) arts = Article.all().order('-postdate').filter( 'author = ', usr).filter('postdate <=', bookmark).fetch(PAGESIZE + 1) else: arts = Article.all().order('-postdate').filter( 'author = ', usr).fetch(PAGESIZE + 1) if len(arts) == PAGESIZE + 1: next = arts[-1].postdate arts = arts[:PAGESIZE] ars = [] for a in arts: a.keyname = a.key().name() a.postdate += timedelta(hours=+8) a.tagname = MukioTools.tagname(a.classify) ars.append(a) if bookmark: arts = Article.all().order('postdate').filter( 'author = ', usr).filter('postdate >=', bookmark).fetch(PAGESIZE + 1) if len(arts) == PAGESIZE + 1: prev = arts[-1].postdate self.render( 'articles.html', { 'arts': ars, 'author': usr, 'next': next, 'prev': prev, 'title': usr.nickname() + unicode('的上传列表', 'utf-8'), 'edit': usr == users.get_current_user() })
def get(self,articlekey=None): article = Article.get_by_key_name(unicode(articlekey).strip()) if not article: self.redirect('/admin/error') article.keyname = article.key().name() article.tagname = MukioTools.tagname(article.classify) article.postdate += timedelta(hours=+8) article.tagstring = ' '.join(article.tags) videos = article.video_set videos.order('postdate') def addkey(i): i.keyname = i.key().name() return i self.render('admin/article_edit.html',{'title':u'编辑主题','article':article,'videos':map(addkey,videos)})
def get(self, aid, prt): #artkey = aid.strip()#db.Key(str(aid).strip()) #arts = Article.all() #arts.filter('__key__=',artkey) if prt == '': prt = 0 else: prt = int(prt) art = Article.get_by_key_name(unicode(aid).strip()) #arts.get() if not art: self.redirect('/articles.php') else: art.clickstatis += 1 art.put() art.keyname = art.key().name() art.tagname = MukioTools.tagname(art.classify) art.postdate += timedelta(hours=+8) videos = art.video_set if prt > videos.count(): prt = 0 videos.order('postdate') vdlinks = [] if videos.count() > 1: for i in range(videos.count()): vdlinks.append({ 'n': i, 'ptitle': videos[i].parttitle, 'selected': i == prt }) vds = videos.fetch(1, prt) vd = None if len(vds): vd = vds[0] vd.keyname = vd.key().name() tmpvars = { 'art': art, 'video': vd, 'title': art.title, 'links': vdlinks, 'part': prt, 'host': self.request.headers['host'] } self.render('videos.html', tmpvars)
def post(self): title = unicode(self.request.get('title')).strip() abs = unicode(self.request.get('abs')).strip() tags = unicode(self.request.get('tags')).strip() classify = int(self.request.get('classify')) usr = users.get_current_user() if title and abs and usr: art = Article(key_name=MukioTools.rndvid(5), author=usr, title=title, abs=abs, classify=classify, tags=tags.split()) if art: art.put() self.redirect('/addvideo/' + art.key().name() + '/')
def get(self,aid,prt): #artkey = aid.strip()#db.Key(str(aid).strip()) #arts = Article.all() #arts.filter('__key__=',artkey) if prt == '': prt = 0 else: prt = int(prt) art = Article.get_by_key_name(unicode(aid).strip())#arts.get() if not art: self.redirect('/articles.php') else: art.clickstatis += 1 art.put() art.keyname = art.key().name() art.tagname = MukioTools.tagname(art.classify) art.postdate += timedelta(hours=+8) videos = art.video_set if prt > videos.count(): prt = 0 videos.order('postdate') vdlinks = [] if videos.count() > 1: for i in range(videos.count()): vdlinks.append({'n':i,'ptitle':videos[i].parttitle,'selected':i == prt}) vds = videos.fetch(1,prt) vd = None if len(vds): vd = vds[0] vd.keyname = vd.key().name() tmpvars = { 'art':art, 'video':vd, 'title':art.title, 'links':vdlinks, 'part':prt, 'host':self.request.headers['host'] } self.render('videos.html',tmpvars)
def post(self): title = unicode(self.request.get('title')).strip() abs = unicode(self.request.get('abs')).strip() tags = unicode(self.request.get('tags')).strip() classify = int(self.request.get('classify')) usr = users.get_current_user() if title and abs and usr: art = Article(key_name=MukioTools.rndvid(5), author=usr, title=title, abs=abs, classify=classify, tags=tags.split() ) if art: art.put() self.redirect('/addvideo/' + art.key().name() +'/')
def get(self, articlekey=None): article = Article.get_by_key_name(unicode(articlekey).strip()) if not article: self.redirect('/admin/error') article.keyname = article.key().name() article.tagname = MukioTools.tagname(article.classify) article.postdate += timedelta(hours=+8) article.tagstring = ' '.join(article.tags) videos = article.video_set videos.order('postdate') def addkey(i): i.keyname = i.key().name() return i self.render('admin/article_edit.html', { 'title': u'编辑主题', 'article': article, 'videos': map(addkey, videos) })
def delete_user_comment(self, key_name): video = Video.get_by_key_name(key_name) if video: if video.art.author == self.user: MukioTools.delete_comment_by_video_key_name_without_author( key_name)
def delete_permanent_comment(self, key_name): video = Video.get_by_key_name(key_name) if video: if video.art.author == self.user: MukioTools.delete_permanent_comment_by_video_key_name(key_name)
def post(self): parttitle = unicode(self.request.get('parttitle')).strip() #vid = unicode(self.request.get('vid')).strip() fileurl = unicode(self.request.get('fileurl')).strip() typ = unicode(self.request.get('typ')).strip() artkeystr = unicode(self.request.get('articleId')).strip() artkey = db.Key(artkeystr) if not artkey: self.redirect('/') art = Article.get(artkey) usr = users.get_current_user() if art.author == usr: self.redirect('/') if typ == 'bokecc': reg = re.compile(r'http://.*vid=([^&]+)', re.I) res = reg.findall(fileurl) if len(res) == 1: vid = res[0] else: vid = fileurl fileurl = '' keyname = 'vid' + vid elif typ == 'sina' or typ == 'youku' or typ == '6room' or typ == 'qq': vid = fileurl fileurl = '' keyname = 'vid' + vid elif typ == 'video': vid = '' keyname = MukioTools.rndvid(4) else: self.error(404) '''typ = 'sina' if not vid: typ = 'video' if not fileurl: typ = 'none' if typ == 'none': self.redirect('/') else: if typ == 'sina': keyname = 'vid' + vid else: reg = re.compile(r'vid=([^&]+)',re.I) res = reg.findall(fileurl) if len(res) == 1: typ = 'bokecc' vid = res[0] keyname = 'vid' + res[0] else: keyname = MukioTools.rndvid(4)''' video = Video(key_name=keyname, typ=typ, vid=vid, fileurl=fileurl, parttitle=parttitle, art=artkey) if video: video.put() self.redirect('/addvideo/' + artkey.name() + '/') else: self.redirect('/')
def post(self): parttitle = unicode(self.request.get('parttitle')).strip() #vid = unicode(self.request.get('vid')).strip() fileurl = unicode(self.request.get('fileurl')).strip() typ = unicode(self.request.get('typ')).strip() artkeystr = unicode(self.request.get('articleId')).strip() artkey = db.Key(artkeystr) if not artkey: self.redirect('/') art = Article.get(artkey) usr = users.get_current_user() if art.author == usr: self.redirect('/') if typ == 'bokecc': reg = re.compile(r'http://.*vid=([^&]+)',re.I) res = reg.findall(fileurl) if len(res) == 1: vid = res[0] else: vid = fileurl fileurl = '' keyname = 'vid' + vid elif typ == 'sina' or typ == 'youku' or typ == '6room' or typ == 'qq': vid = fileurl fileurl = '' keyname = 'vid' + vid elif typ == 'video': vid = '' keyname = MukioTools.rndvid(4) else: self.error(404) '''typ = 'sina' if not vid: typ = 'video' if not fileurl: typ = 'none' if typ == 'none': self.redirect('/') else: if typ == 'sina': keyname = 'vid' + vid else: reg = re.compile(r'vid=([^&]+)',re.I) res = reg.findall(fileurl) if len(res) == 1: typ = 'bokecc' vid = res[0] keyname = 'vid' + res[0] else: keyname = MukioTools.rndvid(4)''' video = Video(key_name=keyname, typ=typ, vid=vid, fileurl=fileurl, parttitle=parttitle, art=artkey ) if video: video.put() self.redirect('/addvideo/' + artkey.name() + '/') else: self.redirect('/')
def compareAndUpdate(self, article, videos, oldvideos): def addkey(i): i.keyname = i.key().name() return i oldvideos = map(addkey, oldvideos) for video in videos: # logging.info('video:%r' % video) flag = 0 if video[3] != '0': for v in oldvideos: if v.keyname == video[3]: if (v.typ != 'video' and v.typ != 'sound' and v.keyname != video[2] and v.keyname != 'vid' + video[2]) or v.typ != video[1]: MukioTools.delete_video_by_key_name(v.keyname) try: newvideo = Video(key_name='vid' + video[2], parttitle=video[0], fileurl='', vid=video[2], typ=video[1], art=article.key()) newvideo.put() except: logging.info('插入视频失败 %r' % (video)) else: v.parttitle = video[0] v.typ = video[1] if v.typ == 'video' or v.typ == 'sound': v.fileurl = video[2] v.vid = '' else: v.fileurl = '' v.vid = video[2] v.postdate = datetime.now() v.put() oldvideos.remove(v) flag = 1 break if flag != 1: # logging.info('new video:%r' % video) if video[1] == 'video' or video[1] == 'sound': keyname = MukioTools.rndvid(4) fileurl = video[2] vid = '' # logging.info('new video type video or sound:%r' % video[1]) else: keyname = 'vid' + video[2] fileurl = '' vid = video[2] # logging.info('new video type not video or sound:%r' % video[1]) # logging.info('hello') # logging.info('%r %r %r %r %r' % (keyname,video[1],vid,fileurl,video[0])) try: newvideo = Video(key_name=keyname, typ=video[1], vid=vid, fileurl=fileurl, parttitle=video[0], art=article.key()) if not newvideo: logging.info('new video Objected failed:%r' % video[1]) else: # logging.info('new video Objected success:%r' % video[1]) newvideo.put() except: logging.info('插入视频失败 %r' % (video)) for v in oldvideos: MukioTools.delete_video_by_key_name(v.keyname)
def delete_video(self, key_name): video = Video.get_by_key_name(key_name) if video: if video.art.author == self.user: MukioTools.delete_video_by_key_name(key_name)
def delete_user_comment(self, key_name): video = Video.get_by_key_name(key_name) if video: if video.art.author == self.user: MukioTools.delete_comment_by_video_key_name_without_author(key_name)
def delete_article(self, key_name): article = Article.get_by_key_name(key_name) if article: if article.author == self.user: MukioTools.delete_article_by_key_name(key_name)
def compareAndUpdate(self,article,videos,oldvideos): def addkey(i): i.keyname = i.key().name() return i oldvideos = map(addkey,oldvideos) for video in videos: # logging.info('video:%r' % video) flag = 0 if video[3] != '0': for v in oldvideos: if v.keyname == video[3]: if (v.typ !='video' and v.typ !='sound' and v.keyname != video[2] and v.keyname != 'vid'+video[2]) or v.typ != video[1]: MukioTools.delete_video_by_key_name(v.keyname) try: newvideo = Video(key_name = 'vid'+video[2], parttitle = video[0], fileurl = '', vid = video[2], typ = video[1], art = article.key()) newvideo.put() except: logging.info('插入视频失败 %r' % (video)) else: v.parttitle = video[0] v.typ = video[1] if v.typ == 'video' or v.typ == 'sound': v.fileurl = video[2] v.vid = '' else: v.fileurl = '' v.vid = video[2] v.postdate = datetime.now() v.put() oldvideos.remove(v) flag = 1 break if flag != 1: # logging.info('new video:%r' % video) if video[1] == 'video' or video[1] == 'sound': keyname = MukioTools.rndvid(4) fileurl = video[2] vid = '' # logging.info('new video type video or sound:%r' % video[1]) else: keyname = 'vid'+video[2] fileurl = '' vid = video[2] # logging.info('new video type not video or sound:%r' % video[1]) # logging.info('hello') # logging.info('%r %r %r %r %r' % (keyname,video[1],vid,fileurl,video[0])) try: newvideo = Video(key_name = keyname, typ = video[1], vid = vid, fileurl = fileurl, parttitle = video[0], art = article.key()) if not newvideo: logging.info('new video Objected failed:%r' % video[1]) else: # logging.info('new video Objected success:%r' % video[1]) newvideo.put() except: logging.info('插入视频失败 %r' % (video)) for v in oldvideos: MukioTools.delete_video_by_key_name(v.keyname)
def addkey(i): i.keyname = i.key().name() i.tagname = MukioTools.tagname(i.classify) i.postdate += timedelta(hours=+8) return i