示例#1
0
文件: views.py 项目: npk/microtype
def removepost(id=None):
    if Post.objects().count() > 1:
        post = Post.objects(id=id)
        post.delete()
        print session.get("page")
        flash("Remove success..",'success')
        return redirect(url_for("main.postlist", page=session.get("page")))
    else:
        flash("Need to be at least one post..", 'error')
示例#2
0
文件: views.py 项目: npk/microtype
def tags(tag = None):
    posts = Post.objects(tag=tag)
    tags = Post._get_collection().aggregate([
        {'$group':{'_id':'$tag','count':{'$sum':1}}},
        {'$sort':{'count': -1}},
        {'$limit': 10}
    ])
    tags = tags["result"]
    return render_template("tags.html", title = "Tags | "+ BLOG_TITLE, posts = posts, tags = tags)
示例#3
0
文件: views.py 项目: npk/microtype
def newpost():
    if request.method == "POST":
        posttitle = request.form.get("title")
        posttag = request.form.get("tag")
        posthtml = request.form.get("content")
        author = User.objects(email=g.user).first()
        if request.form.get("post-id"):
            post = Post.objects(id=request.form.get("post-id")).first()
            post.title = posttitle
            post.tag = posttag
            post.content = posthtml
            post.author = author
            post.created_at = datetime.datetime.now
            post.save()
            flash("Update success..","success")
        else:
            post = Post(title=posttitle, content = posthtml, tag=posttag, author = author)
            post.save()
            flash("Add success..","success")

    return render_template("newpost.html", title = "New Post | "+BLOG_TITLE)
示例#4
0
文件: views.py 项目: npk/microtype
def editpost(id=None):
    post = Post.objects(id=id).first()
    return render_template("editpost.html", title="Editpost | "+BLOG_TITLE, post=post)
示例#5
0
文件: __init__.py 项目: npk/microtype
from flask import Flask
from flask.ext.mongoengine import MongoEngine
from . import config


app = Flask(__name__)
app.config.from_object(config)
db = MongoEngine(app)
from helper_functions import generate_csrf_token
from pytype.models import Post
from pytype.models import User
from .main import main as main_blueprint
from .auth import auth as auth_blueprint
app.register_blueprint(main_blueprint)
app.register_blueprint(auth_blueprint, url_prefix="/auth")
app.jinja_env.globals['csrf_token'] = generate_csrf_token
app.jinja_env.globals['tags'] = Post._get_collection().aggregate([{'$group':{'_id':'$tag','count':{'$sum':1}}},{'$sort':{'count': -1}},{'$limit': 10}])['result']
app.jinja_env.globals['recent_posts'] = Post.objects[:5]
app.jinja_env.globals['about_me'] = User.objects.get(email="*****@*****.**")