Esempio n. 1
0
def publishPost(postId):
	database.execute(sql="""
		UPDATE post SET
			  postStatusId=(SELECT id FROM poststatus WHERE status='Published' LIMIT 1)
			, publishedDateTime=CASE
				WHEN publishedDateTime IS NULL THEN %s
				ELSE publishedDateTime
			END
			, publishedYear=CASE
				WHEN publishedYear IS NULL THEN %s
				ELSE publishedYear
			END
			, publishedMonth=CASE
				WHEN publishedMonth IS NULL THEN %s
				ELSE publishedMonth
			END
		WHERE id=%s
	""", parameters=(
		dthelper.formatDateTime(date=dthelper.utcNow()),
		dthelper.getYear(date=dthelper.utcNow()),
		dthelper.getMonth(date=dthelper.utcNow()),
		postId,
	))

	return database.LAST_NUM_AFFECTED
Esempio n. 2
0
def adminEditPost(id=0):
	success = True
	message = ""
	mode = ""

	if "btnDraft" in request.all:
		mode = "Draft"

	if "btnPublish" in request.all:
		mode = "Published"

	if mode != "":
		post = postservice.updatePost(
			id                = id,
			title             = request.all["postTitle"],
			slug              = request.all["postSlug"],
			content           = request.all["postContent"],
			tags              = request.all["postTags"],
			status            = mode,
			publishedDateTime = dthelper.utcNow() if mode == "Published" else None,
			publishedYear     = dthelper.utcNow() if mode == "Published" else None,
			publishedMonth    = dthelper.utcNow() if mode == "Published" else None
		)

		message = "Your post has been updated and %s successfully." % ("saved as a draft" if mode == "Draft" else "published")
		redirect("/admin/posts/" + message)

	else:
		post = postservice.getPostById(id=id)

	return {
		"title": "Write Post",
		"success": success,
		"message": message,
		"id": post["id"],
		"postTitle": post["title"],
		"postSlug": post["slug"],
		"postTags": post["tagList"],
		"postContent": post["content"],
	}
Esempio n. 3
0
def adminWritePost():
	success = True
	message = ""
	mode = ""

	if "btnDraft" in request.all:
		mode = "draft"

	if "btnPublish" in request.all:
		mode = "publish"

	if mode != "":
		post = postservice.createPost(
			title             = request.all["postTitle"],
			author            = request.session["user"],
			slug              = request.all["postSlug"],
			content           = request.all["postContent"],
			createdDateTime   = dthelper.utcNow(),
			tags              = request.all["postTags"],
			status            = postservice.getPostStatus(status=("Draft" if mode == "draft" else "Published")),
			publishedDateTime = dthelper.utcNow() if mode == "publish" else None,
			publishedYear     = dthelper.utcNow() if mode == "publish" else None,
			publishedMonth    = dthelper.utcNow() if mode == "publish" else None
		)

		message = "Your post has been %s." % ("saved as a draft" if mode == "draft" else "published")
		redirect("/admin/posts/" + message)

	return {
		"title": "Write Post",
		"success": success,
		"message": message,
		"postTitle": "" if not "postTitle" in request.all else request.all["postTitle"],
		"postSlug": "" if not "postSlug" in request.all else request.all["postSlug"],
		"postTags": "" if not "postTags" in request.all else request.all["postTags"],
		"postContent": "" if not "postContent" in request.all else request.all["postContent"],
	}