예제 #1
0
def create_work():
    if not request.is_xhr:
        return url_for("login")

    user = UserPrivateDAL.getUserByUserID(1)  # TODO Should use the logged-in user
    form = request.form
    title = form.get("title", "")
    subtitle = form.get("subtitle", "")
    content = form.get("content", "")
    summary = form.get("summary", "")
    excerpt = ""  # TODO Need a better way to extract text from the HTML content
    metadata = form.get("metadata", "")
    post = PostPrivateDAL.addPost(user.id, title, excerpt, content, "", "", "")
    # TODO Add tags and categories to the post

    cover_image = request.files.get("cover-image", None)
    cover_image_url = ""
    if cover_image:
        filename = secure_filename(cover_image.filename)
        # NOTE There's a race condition
        # http://stackoverflow.com/questions/273192/create-directory-if-it-doesnt-exist-for-file-write
        if not os.path.exists(app.config["UPLOAD_FOLDER"]):
            os.makedirs(app.config["UPLOAD_FOLDER"])
        # TODO Make sure the filename is unique and won't overwrite existing files
        cover_image.save(os.path.join(app.config["UPLOAD_FOLDER"], filename))
        cover_image_url = url_for("uploaded_file", filename=filename)
    # TODO Default value of cover_image_url
    work = PostPrivateDAL.addWork(post.id, subtitle, summary, cover_image_url, metadata)
    return render(jsonify, ajax.payload("success"))
예제 #2
0
def browse_portfolio():
    works = PostPrivateDAL.getWorks(limit=None)
    data = {"works": works}
    return render(browse_views.browse_portfolio, data)
예제 #3
0
def work(work_id):
    work = PostPrivateDAL.getWorkByWorkID(work_id)
    if not work:
        pass
    data = {"work": work}
    return render(post_views.work, data)