def edit_post(context, request): """ Display edit post form """ def edit_post_submit(context, request, deserialized, bind_params): """ Save edited post to database """ bind_params['post'].name = deserialized['title'] bind_params['post'].article = deserialized['body'] return redirect(request, 'thread', threadid=bind_params['post'].thread.id) post = bb.get_post(request.matchdict.get('postid')) if (has_permission('forum_mod_edit', context, request) or post.user == u.show(get_username(request))): result = rapid_deform(context, request, PostSchema, edit_post_submit, thread_name=post.name, body=post.article, post=post) if isinstance(result, dict): message = "Editing Post From " + post.name result.update({"title": message, "header": message}) return result else: raise HTTPForbidden
def check_owner(context, request): page_id = request.matchdict.get('page_id') g = ArticleLib() page = g.show_page(page_id) if (has_permission('article_mod', context, request) or page.user == u.show(get_username(request))): return True else: raise HTTPForbidden
def create_thread_submit(context, request, deserialized, bind_params): """ Add submitted thread and post to database """ user = u.show(get_username(request)) thread = bb.add_thread(deserialized.get("title"), deserialized.get("description"), deserialized.get("body"), user, bind_params['forum']) return redirect(request, 'thread', threadid=thread.id)
def article_create_submit(context, request, deserialized, bind_params): """ Save new article to the database """ name = request.matchdict.get("page_id") display_name = deserialized.get("display_name") article = deserialized.get("article") summary = deserialized.get("summary") tags = deserialized.get("tags") c.create(request, name, display_name, article, summary, u.show(get_username(request)), tags) return redirect(request, "article_read", page_id=name)
def article_update_submit(context, request, deserialized, bind_params): """ Add a article revision to the database """ page = bind_params.get("page") name = request.matchdict.get("page_id") article = deserialized.get("article") summary = deserialized.get("summary") tags = deserialized.get("tags") page.display_name = deserialized.get("display_name") c.update(request, page, article, summary, u.show(get_username(request)), tags) return redirect(request, "article_read", page_id=name)
def check_owner(context, request): page_id = request.matchdict.get('page_id') gamedeptype = request.matchdict.get('type') g = GameDepLib(gamedeptype) try: page = g.show(page_id) if (has_permission('gamedep_mod', context, request) or page.owner == u.show(get_username(request))): return True else: raise HTTPForbidden except GameDepNotFound: return True
def forum_add_vote(context, request): """ Add a vote to a post """ vote_id = request.matchdict.get('vote_id') like = request.matchdict.get('like').lower() == "true" post = bb.get_post(vote_id) try: bb.add_vote(post, u.show(get_username(request)), like) request.session.flash(s.show_setting("INFO_VOTE"), INFO) except AlreadyVoted: request.session.flash(s.show_setting("ERROR_VOTE"), ERROR) return redirect(request, "article_read", page_id=vote_id)
def article_add_vote(context, request): """ Add a vote to an article """ vote_id = request.matchdict.get('vote_id') like = request.matchdict.get('like').lower() == "true" a = ArticleLib() article = a.show_page(vote_id) try: a.add_vote(article, u.show(get_username(request)), like) request.session.flash(s.show_setting("INFO_VOTE"), INFO) except AlreadyVoted: request.session.flash(s.show_setting("ERROR_VOTE"), ERROR) return redirect(request, "article_read", page_id=vote_id)
def gamedep_add_vote(context, request): """ Add a vote to a gamedep """ vote_id = request.matchdict.get('vote_id') like = request.matchdict.get('like').lower() == "true" gamedeptype = request.matchdict.get('type') gd_lib = GameDepLib(gamedeptype) gd = gd_lib.show(vote_id, no_revision_error=False)[0] try: gd_lib.add_vote(gd, u.show(get_username(request)), like) request.session.flash(s.show_setting("INFO_VOTE"), INFO) except AlreadyVoted: request.session.flash(s.show_setting("ERROR_VOTE"), ERROR) return redirect(request, "article_read", page_id=vote_id)
def article_revert(context, request): """ Revert an old revision, basically makes a new revision with old contents """ check_owner(context, request) c = ArticleLib() matchdict_get = request.matchdict.get try: page = c.show_page(matchdict_get('page_id')) c.revert(request, page, c.show_revision(page, matchdict_get('revision')), u.show(get_username(request))) request.session.flash(s.show_setting("INFO_REVERT") % page.name, INFO) return redirect(request, "article_read", page_id=page.name) except PageNotFound: request.session.flash( s.show_setting("ERROR_NOT_FOUND") % matchdict_get('page_id'), ERROR) return redirect(request, "article_list")
def gamedep_edit_submit(context, request, deserialized, bind_params): page_id = get_pageid_revision(request)[0] gamedeptype = request.matchdict.get('type') g = GameDepLib(gamedeptype) name = deserialized.get("name") display_name = deserialized.get("display_name") description = deserialized.get("description") tags = deserialized.get("tags") if g.exists(page_id): g.update(page_id, name, display_name, description, tags) request.session.flash(s.show_setting("INFO_UPDATED") % page_id, INFO) else: g.create(name, display_name, description, tags, u.show(get_username(request)), request) request.session.flash(s.show_setting("INFO_CREATED") % page_id, INFO) return redirect(request, "gamedep_item", page_id=name, type=gamedeptype)
def delete_post(context, request): """ Delete a post """ postid = request.matchdict.get('postid') post = bb.get_post(postid) thread = post.thread forum = thread.forum if (has_permission('forum_mod_delete', context, request) or post.user == u.show(get_username(request))): result = bb.delete_post(post) if result == 1: return HTTPFound( location=route_url('thread', request, threadid=thread.id)) elif result == 2: return HTTPFound( location=route_url('thread_list', request, forumid=forum.id)) else: raise HTTPForbidden
def gamedep_edit_submit(context, request, deserialized, bind_params): page_id = get_pageid_revision(request)[0] gamedeptype = request.matchdict.get('type') g = GameDepLib(gamedeptype) name = deserialized.get("name") display_name = deserialized.get("display_name") description = deserialized.get("description") tags = deserialized.get("tags") if g.exists(page_id): g.update(page_id, name, display_name, description, tags) request.session.flash( s.show_setting("INFO_UPDATED") % page_id, INFO) else: g.create(name, display_name, description, tags, u.show(get_username(request)), request) request.session.flash( s.show_setting("INFO_CREATED") % page_id, INFO) return redirect(request, "gamedep_item", page_id=name, type=gamedeptype)
def get_thread(context, request, threadid=None): """ List all posts in a thread """ threadid = threadid or request.matchdict.get('threadid') thread = bb.get_thread(threadid) thread.view_count += 1 user = u.show(get_username(request)) def get_thread_submit(context, request, deserialized, bind_params): """ Handle "Quick Reply" box. Add post to database. """ threadid = bind_params.get('threadid') if has_permission('forum_reply', context, request): title = "Re: " + deserialized.get('title') body = deserialized.get('body') if not title == '' and not body == '': bb.add_post(thread, title, body, user) transaction.commit() raise HTTPFound(location=request.path_qs) else: raise HTTPForbidden result_dict = rapid_deform(context, request, QuickReplySchema, get_thread_submit, thread_name=thread.name, threadid=threadid) result_dict.update({'thread': thread, 'user': user}) if has_permission('forum_reply', context, request): result_dict['forum_reply'] = True if (has_permission('forum_mod_edit', context, request) and has_permission('forum_mod_delete', context, request)): result_dict['forum_moderator'] = True return result_dict