def edit(): if request.method == "GET": return render_template("admin/edit.html") if request.method == "POST": title, classify, content_md, tag, img,tag_title = map(request.form.get, ("title", "classify", "content_md", "tag", "img","tag_title")) Blog.add_blog(g.db, title=title, content_md=content_md, classify=classify, tag=tag, img=img, tag_title=tag_title) return redirect("/")
def do_action(self): args = self.get_args([ ('text_id', str, None), ]) text_id = args.get('text_id') res = Blog().get_one(text_id) comment = Comment().get_all(text_id) res['comment'] = comment read = res['read'] + 1 Blog().update_read(text_id, read) self.result = res return True
def do_action(self): args = self.get_args([ ('content', str, None), ('user_id', str, None), ('title', str, None), ('subtitle', str, None), ]) text_id = self.get_argument('text_id', None) if text_id: Blog().modify(text_id, args) else: text_id = Blog().create(args) self.result = text_id return True
def edit(): if request.method == "GET": return render_template("admin/edit.html") if request.method == "POST": title, classify, content_md, tag, img, tag_title = map( request.form.get, ("title", "classify", "content_md", "tag", "img", "tag_title")) Blog.add_blog(g.db, title=title, content_md=content_md, classify=classify, tag=tag, img=img, tag_title=tag_title) return redirect("/")
def _user_has_account(self): blog = Database.find_one('blogs', {'author': self.user}) if blog is not None: self.user_blog = Blog.from_mongo(blog['id']) return True else: return False
def _view_blog(self): blog_to_see = input("enter the id of the blog to read") blog = Blog.from_mongo(blog_to_see) posts = blog.get_posts() for post in posts: print("Date: {},title {}\n\n{}".format(post['date'], post['title'], post['content']))
def do_blog_upload(): # 新的博客信息插入 # 将密码加密 try: message = '' status = 0 insert_dict = g.params login_name = insert_dict['login_name'] #判断用户账号是邮件或者手机号 if '@' in login_name: insert_dict['sponsor_email'] = login_name else: insert_dict['sponsor_phone'] = login_name insert_dict.pop('login_name') g.db.add(Blog(**insert_dict)) g.db.commit() except Exception, e: message = repr(e) status = 1 g.db.rollback()
def blog_change(blog_id): if request.method == "GET": return render_template("admin/change.html", blogs=Blog.blog(g.db, blog_id=blog_id)) else: title, classify, content_md, tag, img, status ,tag_title= map( request.form.get, ("title", "classify", "content_md", "tag", "img", "status","tag_title") ) Blog.blog_change(g.db, blog_id=blog_id, title=title, classify=classify, content_md=content_md, tag=tag, img=img, status=status, tag_title=tag_title) return redirect("/")
def blog_change(blog_id): if request.method == "GET": return render_template("admin/change.html", blogs=Blog.blog(g.db, blog_id=blog_id)) else: title, classify, content_md, tag, img, status, tag_title = map( request.form.get, ("title", "classify", "content_md", "tag", "img", "status", "tag_title")) Blog.blog_change(g.db, blog_id=blog_id, title=title, classify=classify, content_md=content_md, tag=tag, img=img, status=status, tag_title=tag_title) return redirect("/")
def do_action(self): args = self.get_args([ ('user_id', str, None), ]) user_id = args.get('user_id') res = Blog().get_list(user_id) for item in res: if 'ctime' in item: ctime = item['ctime'] item['date']=ctime[:4] + '年' + ctime[5:7] + '月' + ctime[8:10] +'日' cres = Comment().get_all(item['text_id']) item['ccount'] = len(cres) self.result = res return True
def api_index(): datas = Blog.index(g.db).all() resp_data = [] for data in datas: resp_data.append( dict( title=data.title, content_md=data.content_md, content_html=data.content_html, date=str(data.date), ) ) return jsonify(blogs=resp_data)
def blog(id): if request.method == 'POST': content = request.form.get('content') user = session['user'] create_reply(content, id, user) return redirect(url_for('.blog', id=id)) reply = [] for r in Reply.objects(blog=id): reply.append(r) b = Blog.objects(id=id).first() return render_template( 'wen/blog.html', reply=reply, blog=b, )
def getBlog(blogId): from model.blog import Blog c = get_db() t = text("SELECT blog_title, blog_text, DATE_FORMAT(date_published,'%m-%d-%Y') as date_published FROM blog WHERE blog_id = :blogId") results = c.execute(t, blogId=blogId) if results is None: return None blogTitle, blogText, blogDate = ("", "", "") for row in results: blogTitle = row['blog_title'] blogText = Markup(markdown.markdown(row['blog_text'])) blogDate = row['date_published'] return Blog(blogTitle, blogText, blogId, blogDate)
def do_action(self): args = self.get_args([ ('text_id', str, None), ('email', str, None), ('subject', str, None), ('comment', str, None), ]) text_id = args.get('text_id') chelper = Comment() chelper.create(args) comments = Comment().get_all(text_id) res = Blog().get_one(text_id) res['comment'] = comments self.result = res return True
def recent_feed(): feed = AtomFeed('Recent Articles', feed_url=request.url, url=request.url_root) articles = Blog.rss_blog(g.db) for article in articles: print article.date dir(article.date) data = get_time(article.date) feed.add(article.title, unicode(article.content_html), content_type='html', author="22too", url=make_external("http://www.22too.com/blog/"+str(article.id)), updated=time(1,1,1,tzinfo=GMT1())) return feed.get_response()
def recent_feed(): feed = AtomFeed('Recent Articles', feed_url=request.url, url=request.url_root) articles = Blog.rss_blog(g.db) for article in articles: print article.date dir(article.date) data = get_time(article.date) feed.add(article.title, unicode(article.content_html), content_type='html', author="22too", url=make_external("http://www.22too.com/blog/" + str(article.id)), updated=time(1, 1, 1, tzinfo=GMT1())) return feed.get_response()
def search(): eq = request.form.getlist("eq") title = Blog.blog_list(g.db, eq) return jsonify(title)
def blog_tag_title(name): return render_template("details.html", blogs=Blog.blog_tag_title(g.db, name))
def api_archs(): dates = Blog.get_arch_dates(g.db) return jsonify(archs=dates)
def api_blog_tag_title(name): return jsonify(blogs=Blog.blog_tag_title(g.db, name))
def blog_classify_by_tag(tag): return render_template("index.html", blogs=Blog.blog_tag(g.db, tag))
def index(): dates = Blog.get_arch_dates(g.db) return render_template("index.html", blogs=Blog.index(g.db), archs=dates)
def set_blog_status(blog_id): if request.method == "POST": data = request.form.get("status", int) if Blog.set_blog_status(g.db, blog_id, status=data): return jsonify(status="success") return jsonify(status="false")
def api_index(): dates = Blog.get_arch_dates(g.db) return jsonify.dumps(blogs = Blog.index(g.db))
def get_blog_from_date(date): if request.method == "GET": return render_template("date_arch.html", blogs=Blog.get_blog_form_data(g.db, date)) return render_template("date_arch.html", blogs=None)
def blog_classify_by_date(date): return render_template("index.html", blogs=Blog.blog_tag(g.db, date))
def api_blog(blog_id): return jsonify(blogs=Blog.blog(g.db, blog_id=blog_id, status=1))
def _prompt_user_for_account(self): title = input("enter blog author") description = input("enter blog description") blog = Blog(author=self.user, title=title, description=description) blog.save_to_mongo()
def blog_classify_by_name(name): return render_template("index.html", blogs=Blog.get_classify(g.db, name))
from model.blog import Blog from database import Database Database.initialize() blog = Blog(author= "adarsh", title = "Sample title", description="Sample Description") blog.new_post() blog.save_to_mongo() from_database = Blog.from_mongo(blog.id) print(blog.get_post())
def create_reply(content, id, user): connect('db2') author = User.objects(username=user).first() blog = Blog.objects(id=id).first() r = Reply(content=content, author=author, blog=blog) r.save()
def create_new_blog(t, c, a): connect('db2') author = User.objects(username=a).first() u = Blog(title=t, author=author, tab='tech', tag='programmer', content=c) u.save()
def get_blog_from_date(date): if request.method == "GET": return render_template("date_arch.html", blogs=Blog.get_blog_form_data(g.db,date)) return render_template("date_arch.html", blogs=None)
def blog(blog_id): return render_template("details.html", blogs=Blog.blog(g.db, blog_id=blog_id, status=1))
def blog_tag_title(name): return render_template("details.html",blogs=Blog.blog_tag_title(g.db,name))
def index(name): t = Tag.objects(name=name).first() blog_list = [b for b in Blog.objects(tag=t.name)] return render_template('wen/wen.html', tag=t, blog_list=blog_list)
def admin_index(): return render_template("admin/admin.html", blogs=Blog.admin_index(g.db))
def set_blog_status(blog_id): if request.method == "POST": data = request.form.get("status",int) if Blog.set_blog_status(g.db,blog_id,status=data): return jsonify(status="success") return jsonify(status="false")