示例#1
0
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("/")
示例#2
0
 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
示例#3
0
 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
示例#4
0
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("/")
示例#5
0
 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
示例#6
0
 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']))
示例#7
0
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()
示例#8
0
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("/")
示例#9
0
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("/")
示例#10
0
 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
示例#11
0
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)
示例#12
0
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)
示例#13
0
文件: wen.py 项目: Tonyqu123/V2EX
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,
    )
示例#14
0
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)
示例#15
0
 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
示例#16
0
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()
示例#17
0
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()
示例#18
0
def search():
    eq = request.form.getlist("eq")
    title = Blog.blog_list(g.db, eq)
    return jsonify(title)
示例#19
0
def blog_tag_title(name):
    return render_template("details.html",
                           blogs=Blog.blog_tag_title(g.db, name))
示例#20
0
def api_archs():
    dates = Blog.get_arch_dates(g.db)
    return jsonify(archs=dates)
示例#21
0
def api_blog_tag_title(name):
    return jsonify(blogs=Blog.blog_tag_title(g.db, name))
示例#22
0
def blog_classify_by_tag(tag):
    return render_template("index.html", blogs=Blog.blog_tag(g.db, tag))
示例#23
0
def api_archs():
    dates = Blog.get_arch_dates(g.db)
    return jsonify(archs=dates)
示例#24
0
def api_blog_tag_title(name):
    return jsonify(blogs=Blog.blog_tag_title(g.db, name))
示例#25
0
def index():
    dates = Blog.get_arch_dates(g.db)
    return render_template("index.html", blogs=Blog.index(g.db), archs=dates)
示例#26
0
def blog_classify_by_tag(tag):
    return render_template("index.html", blogs=Blog.blog_tag(g.db, tag))
示例#27
0
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")
示例#28
0
def api_index():
    dates = Blog.get_arch_dates(g.db)
    return jsonify.dumps(blogs = Blog.index(g.db))
示例#29
0
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)
示例#30
0
def blog_classify_by_date(date):
    return render_template("index.html", blogs=Blog.blog_tag(g.db, date))
示例#31
0
def blog_classify_by_date(date):
    return render_template("index.html", blogs=Blog.blog_tag(g.db, date))
示例#32
0
def index():
    dates = Blog.get_arch_dates(g.db)
    return render_template("index.html", blogs=Blog.index(g.db), archs=dates)
示例#33
0
def api_blog(blog_id):
    return jsonify(blogs=Blog.blog(g.db, blog_id=blog_id, status=1))
示例#34
0
 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()
示例#35
0
def blog_classify_by_name(name):
    return render_template("index.html", blogs=Blog.get_classify(g.db, name))
示例#36
0
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())

示例#37
0
文件: wen.py 项目: Tonyqu123/V2EX
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()
示例#38
0
def search():
    eq = request.form.getlist("eq")
    title = Blog.blog_list(g.db, eq)
    return jsonify(title)
示例#39
0
文件: wen.py 项目: Tonyqu123/V2EX
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()
示例#40
0
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)
示例#41
0
def api_blog(blog_id):
    return jsonify(blogs=Blog.blog(g.db, blog_id=blog_id, status=1))
示例#42
0
def blog(blog_id):
    return render_template("details.html", blogs=Blog.blog(g.db, blog_id=blog_id, status=1))
示例#43
0
def blog_tag_title(name):
    return render_template("details.html",blogs=Blog.blog_tag_title(g.db,name))
示例#44
0
def blog_classify_by_name(name):
    return render_template("index.html", blogs=Blog.get_classify(g.db, name))
示例#45
0
文件: wen.py 项目: Tonyqu123/V2EX
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)
示例#46
0
def blog(blog_id):
    return render_template("details.html",
                           blogs=Blog.blog(g.db, blog_id=blog_id, status=1))
示例#47
0
def admin_index():
    return render_template("admin/admin.html", blogs=Blog.admin_index(g.db))
示例#48
0
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")