Example #1
0
 def render_POST(self, request):
     username = request.get_argument("username") or None
     nickname = request.get_argument("nickname") or None
     password = request.get_argument("password") or None
     pd_realname = request.get_argument("pd_realname") or None
     pd_email = request.get_argument("pd_email") or None
     pd_address = request.get_argument("pd_address") or None
     pd_phone = request.get_argument("pd_phone") or None
     pd_bunryu = request.get_argument("pd_bunryu") or None
     pd_bio = request.get_argument("pd_bio") or None
     new_user = User(username, nickname, password, pd_realname,
                     pd_email, pd_address, pd_phone, pd_bunryu, pd_bio)
     err = self.check_user_data_valid(request, new_user)
     if not err:
         request.dbsession.add(new_user)
         request.dbsession.commit()
         request.redirect("/welcome")
         return "registered successfully"
     else:
         request.setResponseCode(BAD_REQUEST)
         context = {
             "group_meta": self.bunryu_groups,
             "err": err,
         }
         return render_template("register.html", request, context)
Example #2
0
 def render_GET(self, request):
     articles = request.dbsession.query(Article).filter(
         Article.enabled).order_by(Article.uid.desc()).options(
             subqueryload(Article.user))[0:NEW_ITEM_COUNT]
     replies = request.dbsession.query(Reply).filter(
         Reply.enabled).order_by(Reply.uid.desc()).options(
             subqueryload(Reply.user))[0:NEW_ITEM_COUNT]
     articles_packed = [pack_article(article) for article in articles]
     replies_packed = [pack_reply(reply) for reply in replies]
     items = list()
     items.extend(articles_packed)
     items.extend(replies_packed)
     items = sorted(items, key=lambda i: i["created_at"],
                    reverse=True)[0:NEW_ITEM_COUNT]
     page = request.get_argument_int("page", 1)
     page_total = len(items) / ARTICLE_PER_PAGE
     if len(items) % ARTICLE_PER_PAGE != 0:
         page_total += 1
     start_idx = ARTICLE_PER_PAGE * (page - 1)
     end_idx = start_idx + ARTICLE_PER_PAGE
     items = items[start_idx:end_idx]
     context = {
         "items": items,
         "page": page,
         "page_total": page_total,
     }
     return render_template("new.html", request, context)
Example #3
0
 def render_GET(self, request):
     board_name = request.get_argument("name")
     board = get_board(request, board_name)
     if not can_write(request, board):
         raise Unauthorized()
     context = {"board": board}
     return render_template("article_write.html", request, context)
Example #4
0
 def render_GET(self, request):
     board_name = request.get_argument("name")
     board = get_board(request, board_name)
     if not can_write(request, board):
         raise Unauthorized()
     context = {"board": board}
     return render_template("article_write.html", request, context)
Example #5
0
 def render_GET(self, request):
     articles = request.dbsession\
                       .query(Article)\
                       .filter(Article.enabled)\
                       .order_by(Article.last_modified.desc(),
                                 Article.uid.desc())\
                       .options(
                           subqueryload(Article.user))[0:NEW_ITEM_COUNT]
     replies = request.dbsession\
                      .query(Reply)\
                      .filter(Reply.enabled)\
                      .order_by(Reply.last_modified.desc(),
                                Reply.uid.desc())\
                      .options(subqueryload(Reply.user))[0:NEW_ITEM_COUNT]
     articles_packed = [pack_article(article) for article in articles]
     replies_packed = [pack_reply(reply) for reply in replies]
     items = list()
     items.extend(articles_packed)
     items.extend(replies_packed)
     items = sorted(items, key=lambda i: (i["last_modified"], i["uid"]),
                    reverse=True)[0:NEW_ITEM_COUNT]
     page = request.get_argument_int("page", 1)
     page_total = len(items) / ARTICLE_PER_PAGE
     if len(items) % ARTICLE_PER_PAGE != 0:
         page_total += 1
     start_idx = ARTICLE_PER_PAGE * (page - 1)
     end_idx = start_idx + ARTICLE_PER_PAGE
     items = items[start_idx:end_idx]
     context = {
         "items": items,
         "page": page,
         "page_total": page_total,
     }
     return render_template("new.html", request, context)
Example #6
0
 def render_GET(self, request):
     boards = request.dbsession.query(Board)\
                               .options(subqueryload(Board.write_group))\
                               .options(subqueryload(Board.write_group))\
                               .all()
     context = {"boards": boards}
     return render_template("admin_board.html", request, context)
Example #7
0
 def render_GET(self, request):
     article_id = request.get_argument("id")
     article = get_article(request, article_id)
     if is_author(request, article):
         context = {"article": replaceArticleContentForEdit(article)}
         return render_template("article_edit.html", request, context)
     else:
         raise Unauthorized()
Example #8
0
 def render_GET(self, request):
     with open("page/index") as f:
         context = {
             "site_description": SITE_DESCRIPTION,
             "content": markdown_convert_file(f),
             "is_index": True,
         }
     return render_template("page.html", request, context)
Example #9
0
 def render_login_page(self, request, err):
     redirect = request.get_argument("redirect", "/")
     context = {
         "redirect": redirect
     }
     if err:
         context["err"] = err
     return render_template("login.html", request, context)
Example #10
0
 def render_GET(self, request):
     article_id = request.get_argument("id")
     article = get_article(request, article_id)
     if is_author(request, article):
         context = {"article": replaceArticleContentForEdit(article)}
         return render_template("article_edit.html", request, context)
     else:
         raise Unauthorized()
Example #11
0
 def render_GET(self, request):
     user_id = request.get_argument("user_id")
     query = request.dbsession.query(User).filter(User.uid == user_id)
     result = query.all()
     if not result:
         raise BadRequest()
     user = result[0]
     context = {"user": user}
     return render_template("profile_popup.html", request, context)
Example #12
0
 def render_GET(self, request):
     user_id = request.get_argument("user_id")
     query = request.dbsession.query(User).filter(User.uid == user_id)
     result = query.all()
     if not result:
         raise BadRequest()
     user = result[0]
     context = {"user": user}
     return render_template("profile_popup.html", request, context)
Example #13
0
 def render_GET(self, request):
     content = StringIO()
     with open("page/index") as f:
         md.convertFile(f, content, "utf-8")
         context = {
             "site_description": SITE_DESCRIPTION,
             "content": content.getvalue().decode("utf-8"),
             "is_index": True,
         }
     return render_template("page.html", request, context)
Example #14
0
    def render_GET(self, request):
        query_string = request.get_argument("query")
        search_type = request.get_argument("type", "content")
        target = request.get_argument("target", "article")
        if search_type not in ["user", "content"] or target not in ["article", "reply"]:
            raise BadRequest()

        board_name = request.get_argument("board", None)
        board = get_board(request, board_name) if board_name else None

        page = request.get_argument_int("page", 1)

        if search_type == "content":
            query_words = ["%" + word + "%" for word in query_string.split(" ")]
            expr_list = list()
            if target == "article":
                for word in query_words:
                    expr_list.append(Article.subject.like(word))
                    expr_list.append(Article.content.like(word))
                query = request.dbsession.query(Article).filter(or_(*expr_list)).options(
                    subqueryload(Article.user)).options(subqueryload(Article.board))
            else:
                for word in query_words:
                    expr_list.append(Reply.content.like(word))
                query = request.dbsession.query(Reply).filter(or_(*expr_list)).options(subqueryload(Reply.user))
        else:
            query = request.dbsession.query(User).filter(User.nickname == query_string)
            result = query.all()
            target_user = result[0] if result else None
            if target == "article":
                query = request.dbsession.query(Article).filter(Article.user == target_user).options(
                    subqueryload(Article.board)).options(subqueryload(Article.user))
            else:
                query = request.dbsession.query(Reply).filter(Reply.user == target_user).options(
                    subqueryload(Reply.article).subqueryload(Article.board))

        item_per_page = ARTICLE_PER_PAGE
        start_idx = item_per_page * (page - 1)
        end_idx = item_per_page * page
        items = query[start_idx:end_idx]
        total_item_count = query.count()
        page_total = total_item_count / item_per_page
        if total_item_count % item_per_page != 0:
            page_total += 1
        render_page = "search_article.html" if target == "article" else "search_reply.html"
        context = {
            "query": query_string,
            "type": search_type,
            "target": target,
            "board": board,
            "page": page,
            "page_total": page_total,
            "items": items,
        }
        return render_template(render_page, request, context)
Example #15
0
 def render_GET(self, request):
     article_id = request.get_argument("id")
     article = get_article(request, article_id)
     page = request.get_argument("page", None)
     if article.board.name == "notice" or is_anybody(request):
         reply_page_total = article.reply_count / REPLY_PER_PAGE
         if article.reply_count % REPLY_PER_PAGE != 0:
             reply_page_total += 1
         context = {"article": article, "page": page, "reply_page_total": reply_page_total}
         return render_template("article_view.html", request, context)
     else:
         raise Unauthorized()
Example #16
0
 def render_GET(self, request):
     board_id = request.get_argument_int("id")
     query = request.dbsession.query(Board).filter(Board.uid == board_id)
     result = query.all()
     if not result:
         raise BadRequest()
     board = result[0]
     groups = request.dbsession.query(Group).all()
     context = {
         "board": board,
         "groups": groups,
     }
     return render_template("admin_board_edit.html", request, context)
Example #17
0
 def render_GET(self, request):
     board_id = request.get_argument_int("id")
     query = request.dbsession.query(Board).filter(Board.uid == board_id)
     result = query.all()
     if not result:
         raise BadRequest()
     board = result[0]
     groups = request.dbsession.query(Group).all()
     context = {
         "board": board,
         "groups": groups,
     }
     return render_template("admin_board_edit.html", request, context)
Example #18
0
 def render_GET(self, request):
     if len(request.path.split("/")) != 3:
         raise BadRequest()
     name = request.path.split("/")[2]
     if not name:
         raise BadRequest()
     file_path = "page/%s" % name
     if not os.path.isfile(file_path):
         raise PageNotFound()
     with open(file_path) as f:
         context = {
             "content": markdown_convert_file(f),
         }
         return render_template("page.html", request, context)
Example #19
0
 def render_GET(self, request):
     article_id = request.get_argument("id")
     article = get_article(request, article_id)
     page = request.get_argument("page", None)
     if article.board.name == "notice" or is_anybody(request):
         reply_page_total = article.reply_count / REPLY_PER_PAGE
         if article.reply_count % REPLY_PER_PAGE != 0:
             reply_page_total += 1
         context = {
             "article": article,
             "page": page,
             "reply_page_total": reply_page_total,
         }
         return render_template("article_view.html", request, context)
     else:
         raise Unauthorized()
Example #20
0
    def render_GET(self, request):
        page = request.get_argument("page", None)
        chat_total_count = request.dbsession.query(ChatModel).count()
        page_total = chat_total_count / CHAT_PER_PAGE
        user_nicknames = request.dbsession.query(UserModel.nickname).all()
        plucked_user_nicknames = [nickname for (nickname, ) in user_nicknames]

        if page_total % CHAT_PER_PAGE != 0:
            page_total += 1
        context = {
            "CHAT_PER_PAGE": CHAT_PER_PAGE,
            "page": page,
            "page_total": page_total,
            "user_nicknames": json.dumps(plucked_user_nicknames)
        }
        return render_template("chat.html", request, context)
Example #21
0
 def render_GET(self, request):
     if len(request.path.split("/")) != 3:
         raise BadRequest()
     name = request.path.split("/")[2]
     if not name:
         raise BadRequest()
     file_path = "page/%s" % name
     if not os.path.isfile(file_path):
         raise PageNotFound()
     with open(file_path) as f:
         content = StringIO()
         md.convertFile(f, content, "utf-8")
         context = {
             "content": content.getvalue().decode("utf-8"),
         }
         return render_template("page.html", request, context)
Example #22
0
    def render_POST(self, request):
        if not request.user:
            raise Unauthorized()
        nickname = request.get_argument("nickname") or None
        password = request.get_argument("password") or None
        pd_realname = request.get_argument("pd_realname") or None
        pd_email = request.get_argument("pd_email") or None
        pd_address = request.get_argument("pd_address") or None
        pd_phone = request.get_argument("pd_phone") or None
        pd_bio = request.get_argument("pd_bio") or None
        slack_id = request.get_argument("slack_id") or None

        # error check
        err = None
        if nickname:
            query = request.dbsession.query(User)\
                                     .filter(User.nickname == nickname)
            if request.dbsession.query(query.exists()).scalar():
                err = u"이미 사용되고 있는 별명입니다."
            elif not re.match(u"^[-_a-zA-Z가-힣\\d\\(\\)]{1,}$", nickname):
                err = u"별명은 영문, 한글, 숫자, 붙임표(-), 밑줄(_)과 괄호만 사용할 수 있습니다."

        if err:
            context = {"err": err}
            request.setResponseCode(BAD_REQUEST)
            return render_template("profile_edit.html", request, context)

        if nickname:
            request.user.nickname = nickname
        if password:
            request.user.password = pbkdf2(password)
        if pd_realname:
            request.user.pd_realname = pd_realname
        if pd_email:
            request.user.pd_email = pd_email
        if pd_address:
            request.user.pd_address = pd_address
        if pd_phone:
            request.user.pd_phone = pd_phone
        if pd_bio:
            request.user.pd_bio = markdown_and_linkify(pd_bio)
        if slack_id is not None:
            request.user.slack_id = slack_id

        request.dbsession.commit()
        request.redirect("/profile/view")
        return "profile edit success"
Example #23
0
 def render_GET(self, request):
     name = request.get_argument("name")
     if not (name == "notice" or is_anybody(request)):
         raise Unauthorized()
     page = request.get_argument_int("page", 1)
     board = get_board(request, name)
     articles = get_article_page(request, board, page)
     total_article_count = board.article_count
     page_total = total_article_count / ARTICLE_PER_PAGE
     if total_article_count % ARTICLE_PER_PAGE != 0:
         page_total = total_article_count / ARTICLE_PER_PAGE + 1
     context = {
         "items": articles,
         "board": board,
         "page": page,
         "page_total": page_total,
         "can_write": can_write(request, board),
     }
     return render_template("board.html", request, context)
Example #24
0
 def render_GET(self, request):
     name = request.get_argument("name")
     if not (name == "notice" or is_anybody(request)):
         raise Unauthorized()
     page = request.get_argument_int("page", 1)
     board = get_board(request, name)
     articles = get_article_page(request, board, page)
     total_article_count = board.article_count
     page_total = total_article_count / ARTICLE_PER_PAGE
     if total_article_count % ARTICLE_PER_PAGE != 0:
         page_total = total_article_count / ARTICLE_PER_PAGE + 1
     context = {
         "items": articles,
         "board": board,
         "page": page,
         "page_total": page_total,
         "can_write": can_write(request, board),
     }
     return render_template("board.html", request, context)
Example #25
0
 def render_GET(self, request):
     return render_template("welcome.html", request)
Example #26
0
 def render_GET(self, request):
     context = {"group_meta": self.bunryu_groups}
     return render_template("register.html", request, context)
Example #27
0
 def render_GET(self, request):
     return render_template(SITE_ABOUT, request)
Example #28
0
 def render_GET(self, request):
     context = {"group_meta": self.bunryu_groups}
     return render_template("register.html", request, context)
Example #29
0
 def render_GET(self, request):
     return render_template("admin.html", request)
Example #30
0
 def render_GET(self, request):
     groups = request.dbsession.query(Group).all()
     context = {
         "groups": groups,
     }
     return render_template("admin_board_add.html", request, context)
Example #31
0
    def render_GET(self, request):
        query_string = request.get_argument("query")
        search_type = request.get_argument("type", "content")
        target = request.get_argument("target", "article")
        if search_type not in ["user", "content"] or\
           target not in ["article", "reply"]:
            raise BadRequest()

        board_name = request.get_argument("board", None)
        board = get_board(request, board_name) if board_name else None

        page = request.get_argument_int("page", 1)

        if search_type == "content":
            query_words = ["%" + word + "%"
                           for word in query_string.split(" ")]
            expr_list = list()
            if target == "article":
                for word in query_words:
                    expr_list.append(Article.subject.like(word))
                    expr_list.append(Article.content.like(word))
                query = request.dbsession.query(Article)\
                                         .filter(or_(*expr_list))\
                                         .options(subqueryload(Article.user))\
                                         .options(subqueryload(Article.board))
            else:
                for word in query_words:
                    expr_list.append(Reply.content.like(word))
                query = request.dbsession.query(Reply)\
                                         .filter(or_(*expr_list))\
                                         .options(subqueryload(Reply.user))
        else:
            query = request.dbsession.query(User)\
                                     .filter(User.nickname == query_string)
            result = query.all()
            target_user = result[0] if result else None
            if target == "article":
                query = request.dbsession.query(Article)\
                                         .filter(Article.user == target_user)\
                                         .options(subqueryload(Article.board))\
                                         .options(subqueryload(Article.user))
            else:
                query = request.dbsession.query(Reply)\
                                         .filter(Reply.user == target_user)\
                                         .options(subqueryload(Reply.article)
                                                  .subqueryload(Article.board))

        item_per_page = ARTICLE_PER_PAGE
        start_idx = item_per_page * (page - 1)
        end_idx = item_per_page * page
        items = query[start_idx:end_idx]
        total_item_count = query.count()
        page_total = total_item_count / item_per_page
        if total_item_count % item_per_page != 0:
            page_total += 1
        render_page = "search_article.html"\
            if target == "article" else "search_reply.html"
        context = {
            "query": query_string,
            "type": search_type,
            "target": target,
            "board": board,
            "page": page,
            "page_total": page_total,
            "items": items,
        }
        return render_template(render_page, request, context)
Example #32
0
 def render_GET(self, request):
     YuzukiResource.__init__(self)
     users = get_not_anybody_user(request)
     context = {"users": users}
     return render_template("admin_approve.html", request, context)
Example #33
0
 def render_GET(self, request):
     boards = request.dbsession.query(Board).options(subqueryload(Board.write_group)).options(
         subqueryload(Board.write_group)).all()
     context = {"boards": boards}
     return render_template("admin_board.html", request, context)
Example #34
0
 def render_GET(self, request):
     YuzukiResource.__init__(self)
     users = get_not_anybody_user(request)
     context = {"users": users}
     return render_template("admin_approve.html", request, context)
Example #35
0
 def render_GET(self, request):
     return render_template("admin.html", request)
Example #36
0
 def render_GET(self, request):
     with open("page/index") as f:
         context = {"site_description": SITE_DESCRIPTION, "content": markdown_convert_file(f), "is_index": True}
     return render_template("page.html", request, context)
Example #37
0
 def render_GET(self, request):
     if not request.user:
         raise Unauthorized()
     return render_template("profile_edit.html", request)
Example #38
0
 def render_GET(self, request):
     context = {"SITE_DESCRIPTION": SITE_DESCRIPTION}
     return render_template(SITE_INDEX, request, context)
Example #39
0
 def render_GET(self, request):
     if not request.user:
         raise Unauthorized()
     return render_template("profile_edit.html", request)