def blog_info(catename=None, blog_title=None, datey=None, datem=None, dated=None, users=None, glob=None, bid=None): """ x详细信息 """ ret = def_content.get_ret() ret["login"] = users.is_login_admin(redir=False) if bid != None: row = ModelBlogs.get_by_id(int(bid)) else: query = db.Query(ModelBlogs) query.filter("cate =", catename.decode("utf8")).filter("title =", blog_title.decode("utf8")) # query.filter("title =",blog_title.decode("utf8")) row = query.get() if row: import markdown row.html_content = markdown.markdown(row.content) ret["row"] = row else: raise HTTPError(404, "The page not exists!") return ret
def blog_add(users=None, glob=None): """ blog t添加处理时的逻辑 """ user = users.is_login_admin() if user is None: return "you need login to me!" ret = def_content.get_ret() title = request.forms.getu("title", None) cate = request.forms.getu("cate", None) tags = request.forms.getu("tags", None) content = request.forms.getu("content", None) page_id = int(request.query.getu("bid", 0)) ret["title"] = title ret["cate"] = cate ret["tags"] = tags ret["content"] = content ret["form_url"] = "/blog/add" if page_id > 0: row = ModelBlogs.get_by_id(page_id) if row: ret["title"] = row.title ret["cate"] = row.cate ret["tags"] = " ".join(row.tags) ret["content"] = row.content ret["form_url"] = "/blog/add?bid=%s" % (page_id,) ##### cate 处理 if cate is not None and cate.strip() != "": kwds = {"title": cate, "is_del": False} cate_mode = ModelCategory.get_or_insert(key_name=cate, **kwds) cate_mode.put() if tags is not None and tags.strip() != "": tag = tags.split(" ") tag = filter(lambda x: x != "", tag) for x in tag: kwds = {"title": x, "is_del": False} mtag = ModelTags.get_or_insert(key_name=x, **kwds) mtag.put() if title and content: create_time = datetime.datetime.now() if "tag" not in locals(): tag = [] if page_id > 0: row.title = title row.cate = cate row.tags = tag row.content = content row.edit_time = create_time row.put() redirect("/blog/add?bid=%s" % (page_id,)) else: mblog = ModelBlogs( account=user, title=title, cate=cate, tags=tag, content=content, create_time=create_time, edit_time=create_time, is_del=False, ) mblog.put() # return mblog.key() return ret