diff --git a/controller/admin.py b/controller/admin.py index 4ea4160..730a37f 100644 --- a/controller/admin.py +++ b/controller/admin.py @@ -19,9 +19,6 @@ def prepare(self): if self.power != "admin": self.redirect("/") - def get(self, *args, **kwargs): - self.home_action(*args, **kwargs) - def post(self, *args, **kwargs): method = ("%s_action" % args[0]) if len(args) > 0 else "home_action" if hasattr(self, method): @@ -29,19 +26,6 @@ def post(self, *args, **kwargs): else: self.home_action(*args, **kwargs) - @tornado.web.asynchronous - @gen.coroutine - def home_action(self, *args, **kwargs): - codes = [] - cursor = self.db.invite.find({ - "used": {"$eq": False}, - "time": {"$gt": (time.time() - self.settings["invite_expire"])} - }) - while (yield cursor.fetch_next): - codes.append(cursor.next_object()["code"]) - codes = "\n".join(codes) - self.render("admin.htm", flash = self.flash, codes = codes) - @tornado.web.asynchronous @gen.coroutine def register_action(self, *args, **kwargs): @@ -112,6 +96,15 @@ def article_action(self, *args, **kwargs): "open": open } }) + elif method in ("top", "notop"): + top = True if method == "top" else False + post = yield self.db.article.find_and_modify({ + "_id": ObjectId(id) + }, { + "$set": { + "top": top + } + }) elif method == "del": post = yield self.db.article.find_and_modify({ "_id": ObjectId(id) diff --git a/controller/main.py b/controller/main.py index ced0d0f..d48c617 100644 --- a/controller/main.py +++ b/controller/main.py @@ -15,7 +15,7 @@ def get(self, *args, **kwargs): page = intval(args[1]) if not page or page <= 0 : page = 1 cursor = self.db.article.find() - cursor.sort([('time', pymongo.DESCENDING)]).limit(limit).skip((page - 1) * limit) + cursor.sort([('top', pymongo.DESCENDING), ('time', pymongo.DESCENDING)]).limit(limit).skip((page - 1) * limit) count = yield cursor.count() posts = yield cursor.to_list(length = limit) sorts = yield self.get_sort() diff --git a/controller/publish.py b/controller/publish.py index fa95ff1..66ce3e3 100644 --- a/controller/publish.py +++ b/controller/publish.py @@ -78,7 +78,8 @@ def post(self, *args, **kwargs): "star": False, "rank": 0, "comment": [], - "open": False + "open": False, + "top": False } model = ArticleModel() if not model(article): diff --git a/static/assets/js/post.js b/static/assets/js/post.js index 96f8d54..adf63b0 100644 --- a/static/assets/js/post.js +++ b/static/assets/js/post.js @@ -97,6 +97,16 @@ $(document).ready(function(){ } return false; }) + $("#top a").on("click", function(){ + if (this.hash == "#top") { + $("#open [name='method']").val('notop'); + $("#open").submit(); + }else if(this.hash == "#notop") { + $("#open [name='method']").val('top'); + $("#open").submit(); + } + return false; + }) $("#rank a").on("click", function(){ var rank = prompt("输入奖励或惩罚的分数"); if (!rank || parseInt(rank) == 0){ diff --git a/templates/admin.htm b/templates/admin.htm deleted file mode 100644 index 9efa1e8..0000000 --- a/templates/admin.htm +++ /dev/null @@ -1,186 +0,0 @@ -{% extends "base.htm" %} - -{% block header_title %}前台管理{% end %} -{% block body %} -{% include "header.htm" %} -
-
-
-
-
-
-
- 增加分类 - -
-
-
- -
-
- {% set alert = flash["addsort"] %} - {% if alert %} -
- {{ alert }} -
- {% end %} -
- {% raw xsrf_form_html() %} -
-
-
-
-
- -
-
-
- - -
-
-
- -
-
- {% set alert = flash["showsort"] %} - {% if alert %} -
- {{ alert }} -
- {% end %} -
- {% raw xsrf_form_html() %} -
-
-
-
-
-
- 删除分类 - -
-
-
- -
-
- {% set alert = flash["delsort"] %} - {% if alert %} -
- {{ alert }} -
- {% end %} -
- {% raw xsrf_form_html() %} -
-
- -
-
-
-
- - - -
-
-
- -
-
- {% set alert = flash["register"] %} - {% if alert %} -
- {{ alert }} -
- {% end %} -
- {% raw xsrf_form_html() %} -
-
-
-
-
- - - - 清理过期邀请码 - -
-
- -
-
- {% set alert = flash["invite"] %} - {% if alert %} -
- {{ alert }} -
- {% end %} -
- {% raw xsrf_form_html() %} -
-
-
-
-
- -
-
-
- - -
-
-
- -
-
- {% set alert = flash["user"] %} - {% if alert %} -
- {{ alert }} -
- {% end %} -
- {% raw xsrf_form_html() %} -
-
-
-
-
- -
-
-
没有使用的邀请码 - × -
-
- -
-
-
- -{% end %} -{% block footer_static %} - -{% end %} \ No newline at end of file diff --git a/templates/post.htm b/templates/post.htm index 7df3114..0380120 100644 --- a/templates/post.htm +++ b/templates/post.htm @@ -182,6 +182,14 @@ {% raw xsrf_form_html() %} +
  • +
    + + +  {% if post.get('top') %} 不置顶{% else %} 置顶{% end %} + {% raw xsrf_form_html() %} +
    +
  • {% end %}