def post(self): # add new post or edit existed post t_values = {} current_post_id = self.request.POST["current_post_id"] post_title = self.request.POST["blog_title"] post_slug = get_safe_slug(self.request.POST["blog_slug"]) post_content = self.request.POST["blog_content"] # find category blog_category_id = self.request.POST["blog_category_id"] post_category = Category.get_by_id(long(blog_category_id)) if post_category: logging.info("find category %s for id %s" % (post_category.name, blog_category_id)) else: logging.error("category id %s can't be located" % (blog_category_id)) if current_post_id: logging.info("PostManager: post : edit post current_post_id = %s" % (current_post_id)) # update existed post post = Entry.get_by_id(long(current_post_id)) if post: t_values['alert_message'] = "Post %s has been updated!" % (post.title) post.title = post_title post.slug = post_slug post.content = post_content post.entrytype = "post" # update category count if this post is public if post.is_external_page and post.category != post_category: if post.category and (post.category.entrycount > 0): post.category.entrycount -= 1 post.category.put() post_category.entrycount += 1 post.category.put() post.category = post_category post.put() else: logging.info("PostManager: post : new post title %s" % (self.request.POST['blog_title'])) # create new post post = Entry() post.title = post_title post.slug = post_slug post.content = post_content post.entrytype = 'post' post.category = post_category # save as public or private? operation = self.request.POST["submit_action"] if operation == "save_publish": post.is_external_page = True # update category count post.category.entrycount += 1 post.category.put() else: # "save" operation post.is_external_page = False # save the post post.put() t_values['alert_message'] = "Post %s has been created!" % (post.title) # show all posts posts = Entry.all().filter("entrytype =", 'post') t_values['posts'] = posts return self.response.out.write(render_template("posts.html", t_values, "", True))
def get(self): '''i=0 n = self.request.get('n') if not n: n='1' csvfile='data/data'+n+'.csv' self.response.headers['Content-Type'] = 'text/html' csvreader = csv.reader(file(os.path.join(os.path.dirname(__file__),csvfile))) for line in csvreader: e = Entry() e.title = line[0].decode('utf-8') e.url = line[1].decode('utf-8') e.content = line[2].decode('utf-8') e.private = False tag_name=line[3].decode('utf-8') t_q = Tag.all() t_q = t_q.filter('name =',tag_name) if(t_q.count(1)>0): t = t_q.get() t.count_link+=1 t.usetime=datetime.datetime.now() t.put() else: t = Tag() t.name = tag_name t.count_link=1 t.usetime=datetime.datetime.now() t.put() e.tags.append(db.Category(tag_name)) e.put() i +=1 self.response.out.write('%d ' % i) self.response.out.write('%s ' % e.key()) self.response.out.write('%s <br />' % line[0]) ''' n = self.request.get('n') if not n: n = 0 else: n = int(n) for i in range(1, 1000): e = Entry() e.title = str(i + n * 999) e.pageid = n e.put() self.response.out.write('%d ' % i) self.response.out.write('%s <br />' % e.key())
def get(self): '''i=0 n = self.request.get('n') if not n: n='1' csvfile='data/data'+n+'.csv' self.response.headers['Content-Type'] = 'text/html' csvreader = csv.reader(file(os.path.join(os.path.dirname(__file__),csvfile))) for line in csvreader: e = Entry() e.title = line[0].decode('utf-8') e.url = line[1].decode('utf-8') e.content = line[2].decode('utf-8') e.private = False tag_name=line[3].decode('utf-8') t_q = Tag.all() t_q = t_q.filter('name =',tag_name) if(t_q.count(1)>0): t = t_q.get() t.count_link+=1 t.usetime=datetime.datetime.now() t.put() else: t = Tag() t.name = tag_name t.count_link=1 t.usetime=datetime.datetime.now() t.put() e.tags.append(db.Category(tag_name)) e.put() i +=1 self.response.out.write('%d ' % i) self.response.out.write('%s ' % e.key()) self.response.out.write('%s <br />' % line[0]) ''' n = self.request.get('n') if not n: n=0 else: n=int(n) for i in range(1,1000): e = Entry() e.title=str(i+n*999) e.pageid=n e.put() self.response.out.write('%d ' % i) self.response.out.write('%s <br />' % e.key())
def post(self): t_values = {} # add new post or edit existed post current_post_id = self.request.POST["current_post_id"] if current_post_id: logging.info("PageManager: post : current_post_id = %s" % (current_post_id)) # update existed post post = Entry.get_by_id(long(current_post_id)) if post: t_values['alert_message'] = "Post %s has been updated!" % (post.title) post.title = self.request.POST["blog_title"] post.slug = get_safe_slug(self.request.POST["blog_slug"]) post.content = self.request.POST["blog_content"] post.entrytype = 'page' post.put() else: logging.info("PageManager: post : new post title %s" % (self.request.POST['blog_title'])) # create new post post = Entry() post.title = self.request.POST["blog_title"] post.slug = get_safe_slug(self.request.POST["blog_slug"]) post.content = self.request.POST["blog_content"] # post.categories = self.request.POST["blog_categories"] operation = self.request.POST["submit_action"] logging.info("operation = %s" % (operation)) if operation == "save_publish": post.is_external_page = True else: # "save" operation post.is_external_page = False post.entrytype = 'page' post.put() t_values['alert_message'] = "Page %s: %s has been created!" % (post.title, post.entrytype) # show all posts posts = Entry.all().filter("entrytype =", 'page') t_values['posts'] = posts return self.response.out.write(render_template("pages.html", t_values, "", True))
def post(self): if not self.is_login: self.redirect(users.create_login_url(self.request.uri)) filename=self.param('filename') do_comment=self.paramint('c',0) if filename[:4]=='img/':#处理图片 new_filename=filename.split('/')[1] mtype =new_filename.split('.')[1] bits = self.request.body media=Media.all().filter('name =',new_filename) if media.count()>0: media=media[0] else: media=Media() media.name=new_filename media.mtype=mtype media.bits=bits media.put() bid='_'.join(new_filename.split('_')[:-1]) entries=Entry.all().filter('slug =',bid) if entries.count()>0: entry=entries[0] entry.content=entry.content.replace(filename,'/media/'+str(media.key())) entry.put() return if filename=="index.html" or filename[-5:]!='.html': return #处理html页面 bid=filename[:-5] try: soup=BeautifulSoup(self.request.body) bp=soup.find(id='bp') title=self.getChineseStr( soup.title.text) logging.info(bid) pubdate=self.getdate( bp.find(id='bp-'+bid+'-publish').text) body=bp.find('div','blogpost') entries=Entry.all().filter('title = ',title) if entries.count()<1: entry=Entry() else: entry=entries[0] ## entry=Entry.get_by_key_name(bid) ## if not entry: ## entry=Entry(key_name=bid) entry.slug=bid entry.title=title entry.author_name=self.login_user.nickname() entry.date=pubdate entry.settags("") entry.content=unicode(body) entry.author=self.login_user entry.save(True) if do_comment>0: comments=soup.find('div','comments','div') if comments: for comment in comments.contents: name,date=comment.h5.text.split(' - ') # modify by lastmind4 name_date_pair = comment.h5.text if name_date_pair.index('- ') == 0: name_date_pair = 'Anonymous ' + name_date_pair name,date=name_date_pair.split(' - ') key_id=comment.h5['id'] date=self.getdate(date) content=comment.contents[1].text comment=Comment.get_or_insert(key_id,content=content) comment.entry=entry comment.date=date comment.author=name comment.save() except Exception,e : logging.info("import error: %s"%e.message)
def post(self): if not self.is_login: self.redirect(users.create_login_url(self.request.uri)) filename = self.param('filename') do_comment = self.paramint('c', 0) if filename[:4] == 'img/': #处理图片 new_filename = filename.split('/')[1] mtype = new_filename.split('.')[1] bits = self.request.body media = Media.all().filter('name =', new_filename) if media.count() > 0: media = media[0] else: media = Media() media.name = new_filename media.mtype = mtype media.bits = bits media.put() bid = '_'.join(new_filename.split('_')[:-1]) entries = Entry.all().filter('slug =', bid) if entries.count() > 0: entry = entries[0] entry.content = entry.content.replace( filename, '/media/' + str(media.key())) entry.put() return if filename == "index.html" or filename[-5:] != '.html': return #处理html页面 bid = filename[:-5] try: soup = BeautifulSoup(self.request.body) bp = soup.find(id='bp') title = self.getChineseStr(soup.title.text) logging.info(bid) pubdate = self.getdate(bp.find(id='bp-' + bid + '-publish').text) body = bp.find('div', 'blogpost') entries = Entry.all().filter('title = ', title) if entries.count() < 1: entry = Entry() else: entry = entries[0] ## entry=Entry.get_by_key_name(bid) ## if not entry: ## entry=Entry(key_name=bid) entry.slug = bid entry.title = title entry.author_name = self.login_user.nickname() entry.date = pubdate entry.settags("") entry.content = unicode(body) entry.author = self.login_user entry.save(True) if do_comment > 0: comments = soup.find('div', 'comments', 'div') if comments: for comment in comments.contents: name, date = comment.h5.text.split(' - ') # modify by lastmind4 name_date_pair = comment.h5.text if name_date_pair.index('- ') == 0: name_date_pair = 'Anonymous ' + name_date_pair name, date = name_date_pair.split(' - ') key_id = comment.h5['id'] date = self.getdate(date) content = comment.contents[1].text comment = Comment.get_or_insert(key_id, content=content) comment.entry = entry comment.date = date comment.author = name comment.save() except Exception, e: logging.info("import error: %s" % e.message)
def post(self): if users.is_current_user_admin(): key = self.request.get('key') if key: e = db.get(key) else: e = Entry() type = self.request.get('type') if not type: type = 'link' title = self.request.get('title') e.title = title.replace('&', '&').replace('<', '<').replace( '>', '>') url = self.request.get('url') purl = self.request.get('purl') if type == 'pic' and not key: e.url = purl.replace('&', '&').replace('<', '<').replace( '>', '>') else: e.url = url.replace('&', '&').replace('<', '<').replace( '>', '>') content = self.request.get('content') e.content = content if not key: e.addtime += datetime.timedelta(hours=+8) e.private = bool(int(self.request.get('private'))) e.type = type if type == 'pic' and not key: if url: try: result = urlfetch.fetch(url) if result.status_code == 200: e.image = db.Blob(result.content) except: self.response.out.write('获取图片超时!') return else: myfile = self.request.get("myfile") if not myfile: self.response.out.write('没有选择文件!') return try: e.image = db.Blob(myfile) except: self.response.out.write('文件上传失败!') return if key: #更新数据 for oldtag in e.tags: tag = Tag.all().filter('name', oldtag) if (tag.count(1) > 0): t = tag.get() if type == 'link': t.count_link -= 1 if type == 'note': t.count_note -= 1 if type == 'pic': t.count_pic -= 1 t.put() else: #新增数据 max_pageCount = 900 #超过此数据,则pageid递增 entry = Entry.all().order('-addtime') if entry.count() > 0: cur_pageid = entry.get().pageid else: cur_pageid = 0 cur_pageCount = entry.filter('pageid =', cur_pageid).count(1000) if cur_pageCount >= max_pageCount: e.pageid = cur_pageid + 1 else: e.pageid = cur_pageid e.tags = [] tag_names = self.request.get('tags').split() for tag_name in tag_names: tag = Tag.all().filter('name', tag_name) if (tag.count(1) > 0): t = tag.get() if type == 'link': t.count_link += 1 if type == 'note': t.count_note += 1 if type == 'pic': t.count_pic += 1 t.usetime = datetime.datetime.now() t.put() else: t = Tag() t.name = tag_name if type == 'link': t.count_link = 1 if type == 'note': t.count_note = 1 if type == 'pic': t.count_pic = 1 t.usetime = datetime.datetime.now() t.put() e.tags.append(db.Category(tag_name)) e.put() self.redirect('/' + type + '/') else: self.redirect(users.create_login_url(self.request.uri))
def post(self): if users.is_current_user_admin(): key = self.request.get('key') if key : e = db.get(key) else: e = Entry() type = self.request.get('type') if not type: type = 'link' title = self.request.get('title') e.title = title.replace('&','&').replace('<','<').replace('>','>') url = self.request.get('url') purl= self.request.get('purl') if type == 'pic' and not key: e.url = purl.replace('&','&').replace('<','<').replace('>','>') else: e.url = url.replace('&','&').replace('<','<').replace('>','>') content = self.request.get('content') e.content = content if not key: e.addtime +=datetime.timedelta(hours=+8) e.private = bool(int(self.request.get('private'))) e.type = type if type =='pic' and not key: if url: try: result = urlfetch.fetch(url) if result.status_code == 200: e.image = db.Blob(result.content) except : self.response.out.write('获取图片超时!') return else: myfile = self.request.get("myfile") if not myfile: self.response.out.write( '没有选择文件!') return try: e.image = db.Blob(myfile) except : self.response.out.write( '文件上传失败!') return if key:#更新数据 for oldtag in e.tags: tag = Tag.all().filter('name',oldtag) if(tag.count(1)>0): t = tag.get() if type == 'link': t.count_link -=1 if type == 'note': t.count_note -=1 if type == 'pic': t.count_pic -=1 t.put() else:#新增数据 max_pageCount =900 #超过此数据,则pageid递增 entry = Entry.all().order('-addtime') if entry.count()>0: cur_pageid = entry.get().pageid else: cur_pageid = 0 cur_pageCount = entry.filter('pageid =',cur_pageid).count(1000) if cur_pageCount>=max_pageCount: e.pageid = cur_pageid+1 else: e.pageid = cur_pageid e.tags = [] tag_names = self.request.get('tags').split() for tag_name in tag_names: tag = Tag.all().filter('name',tag_name) if(tag.count(1)>0): t = tag.get() if type == 'link': t.count_link +=1 if type == 'note': t.count_note +=1 if type == 'pic': t.count_pic +=1 t.usetime = datetime.datetime.now() t.put() else: t = Tag() t.name = tag_name if type == 'link': t.count_link =1 if type == 'note': t.count_note =1 if type == 'pic': t.count_pic =1 t.usetime = datetime.datetime.now() t.put() e.tags.append(db.Category(tag_name)) e.put() self.redirect('/'+type+'/') else: self.redirect(users.create_login_url(self.request.uri))
def post(self): #********************** User Auth **************************# user = users.get_current_user() nickname = '' if user: nickname=user.nickname() if nickname: key = self.request.get('key') if key : e = db.get(key) if e.user != nickname: e = Entry() e.user = nickname else: e = Entry() e.user = nickname type = self.request.get('type') if not type: type = 'link' tz = self.request.get('tz') if tz[0:1]=='-': tz = int(tz[1:]) tz = -tz else: tz = int(tz[1:]) tz = +tz title = self.request.get('title') e.title = title.replace('&','&').replace('<','<').replace('>','>') url = self.request.get('url') purl= self.request.get('purl') if type == 'pic' and not key: e.url = purl.replace('&','&').replace('<','<').replace('>','>') else: e.url = url.replace('&','&').replace('<','<').replace('>','>') content = self.request.get('content') e.content = content if not key: e.addtime +=datetime.timedelta(hours=tz) e.private = bool(int(self.request.get('private'))) e.type = type if type =='pic' and not key: if url: try: result = urlfetch.fetch(url) if result.status_code == 200: e.image = db.Blob(result.content) except : self.response.out.write('Fetch picture fail! You can <a href="/add?type=pic">upload</a> it manually') return else: myfile = self.request.get("myfile") if not myfile: self.response.out.write( 'No file specified!') return try: e.image = db.Blob(myfile) except : self.response.out.write( 'Uploading fail!') return if key:#更新数据 for oldtag in e.tags: tag = Tag.all().filter("user",nickname).filter('name',oldtag) if(tag.count(1)>0): t = tag.get() if type == 'link': t.count_link -=1 if type == 'note': t.count_note -=1 if type == 'pic': t.count_pic -=1 t.put() else:#新增数据 max_pageCount =900 #超过此数据,则pageid递增 entry = Entry.all().order('-addtime') if entry.count()>0: cur_pageid = entry.get().pageid else: cur_pageid = 0 cur_pageCount = entry.filter('pageid =',cur_pageid).count(1000) if cur_pageCount>=max_pageCount: e.pageid = cur_pageid+1 else: e.pageid = cur_pageid e.tags = [] tag_names = self.request.get('tags').split() for tag_name in tag_names: tag = Tag.all().filter("user",nickname).filter('name',tag_name) if(tag.count(1)>0): t = tag.get() if type == 'link': t.count_link +=1 if type == 'note': t.count_note +=1 if type == 'pic': t.count_pic +=1 t.user = nickname t.usetime = datetime.datetime.now() t.put() else: t = Tag() t.name = tag_name if type == 'link': t.count_link =1 if type == 'note': t.count_note =1 if type == 'pic': t.count_pic =1 t.user = nickname t.usetime = datetime.datetime.now() t.put() e.tags.append(db.Category(tag_name)) e.put() self.redirect('/'+type+'/'+nickname) else: self.redirect(users.create_login_url(self.request.uri))
def post(self): """Parsing queued feeds""" doc = feedparser.parse(self.request.body) # Bozo feed handling # stealed from PubSubHubbub subscriber repo if doc.bozo: logging.error("Bozo feed data. %s: %r", doc.bozo_exception.__class__.__name__, doc.bozo_exception) if hasattr(doc.bozo_exception, "getLineNumber") and hasattr(doc.bozo_exception, "getMessage"): line = doc.bozo_exception.getLineNumber() logging.error("Line %d: %s", line, doc.bozo_exception.getMessage()) segment = self.request.body.split("\n")[line - 1] logging.info("Body segment with error: %r", segment.decode("utf-8")) return # fail fast # WORKER['parser'] + `key` key = self.request.path[len(WORKER["parser"]) :] # Try to get the channel by key; # fallback to feed id, if not found; # and at last we'll resort to entry source id, # to find out the associated channel channel = None uid = doc.feed.id try: channel = Channel.get(key) except: channel = Channel.all().filter("uid =", uid).get() else: # First time get the notification, # so update channel's properties if channel and not channel.uid: channel.title = doc.feed.title.split(" - ")[0] channel.uid = uid # Fallback to topic feed, if no link found channel.link = doc.feed.get("link", channel.topic) channel.put() updates = [] for e in doc.entries: author = e.author if e.get("author") else None content = e.content[0].value if e.get("content") else e.summary # Fallback to published if no updated field. t = e.updated_parsed if e.get("updated_parsed") else e.published_parsed updated = datetime(t[0], t[1], t[2], t[3], t[4], t[5]) # If we have this entry already in datastore, then the entry # should be updated instead of inserted. ent = Entry.all().filter("uid =", e.id).get() if not ent: if not channel: uid = e.source.id channel = Channel.all().filter("uid =", uid).get() ent = Entry( title=e.title, link=e.link, content=content, author=author, updated=updated, uid=e.id, channel=channel, ) logging.info("Get new entry: %s" % e.id) else: ent.title = e.title ent.link = e.link ent.content = content ent.author = author ent.updated = updated logging.info("Get updated entry: %s" % e.id) updates.append(ent) db.put(updates)
def post(self): #********************** User Auth **************************# user = users.get_current_user() nickname = '' if user: nickname = user.nickname() if nickname: key = self.request.get('key') if key: e = db.get(key) if e.user != nickname: e = Entry() e.user = nickname else: e = Entry() e.user = nickname type = self.request.get('type') if not type: type = 'link' tz = self.request.get('tz') if tz[0:1] == '-': tz = int(tz[1:]) tz = -tz else: tz = int(tz[1:]) tz = +tz title = self.request.get('title') e.title = title.replace('&', '&').replace('<', '<').replace( '>', '>') url = self.request.get('url') purl = self.request.get('purl') if type == 'pic' and not key: e.url = purl.replace('&', '&').replace('<', '<').replace( '>', '>') else: e.url = url.replace('&', '&').replace('<', '<').replace( '>', '>') content = self.request.get('content') e.content = content if not key: e.addtime += datetime.timedelta(hours=tz) e.private = bool(int(self.request.get('private'))) e.type = type if type == 'pic' and not key: if url: try: result = urlfetch.fetch(url) if result.status_code == 200: e.image = db.Blob(result.content) except: self.response.out.write( 'Fetch picture fail! You can <a href="/add?type=pic">upload</a> it manually' ) return else: myfile = self.request.get("myfile") if not myfile: self.response.out.write('No file specified!') return try: e.image = db.Blob(myfile) except: self.response.out.write('Uploading fail!') return if key: #更新数据 for oldtag in e.tags: tag = Tag.all().filter("user", nickname).filter('name', oldtag) if (tag.count(1) > 0): t = tag.get() if type == 'link': t.count_link -= 1 if type == 'note': t.count_note -= 1 if type == 'pic': t.count_pic -= 1 t.put() else: #新增数据 max_pageCount = 900 #超过此数据,则pageid递增 entry = Entry.all().order('-addtime') if entry.count() > 0: cur_pageid = entry.get().pageid else: cur_pageid = 0 cur_pageCount = entry.filter('pageid =', cur_pageid).count(1000) if cur_pageCount >= max_pageCount: e.pageid = cur_pageid + 1 else: e.pageid = cur_pageid e.tags = [] tag_names = self.request.get('tags').split() for tag_name in tag_names: tag = Tag.all().filter("user", nickname).filter('name', tag_name) if (tag.count(1) > 0): t = tag.get() if type == 'link': t.count_link += 1 if type == 'note': t.count_note += 1 if type == 'pic': t.count_pic += 1 t.user = nickname t.usetime = datetime.datetime.now() t.put() else: t = Tag() t.name = tag_name if type == 'link': t.count_link = 1 if type == 'note': t.count_note = 1 if type == 'pic': t.count_pic = 1 t.user = nickname t.usetime = datetime.datetime.now() t.put() e.tags.append(db.Category(tag_name)) e.put() self.redirect('/' + type + '/' + nickname) else: self.redirect(users.create_login_url(self.request.uri))
last_section = None double_backslash_count = 0 for line in f: line = line.strip() if is_new_entry(line): if entry is not None: entry.save() entry = Entry() last_section = None double_backslash_count = 0 elif is_arxiv_id(line): entry.arxiv_id = get_arxiv_id(line) last_section = None # elif is_title(line): entry.title = get_title(line) last_section = 'title' elif is_date(line): entry.date = get_date(line) elif is_authors(line): entry.authors = get_authors(line) last_section = 'authors' elif is_categories(line): entry.categories = get_categories(line) last_section = 'categories' elif is_empty(line): last_section = None elif is_double_backslash(line): last_section = None double_backslash_count += 1 elif is_section(line):