def topic(tid): pn = request.args.get('pn', '1') count_post = int(config['count_post']) try: validate_id(_('Page Number'), pn) except ValidationError as err: return validation_err_response(err, json=False) result_info = forum.topic_info(tid) if result_info[0] != 0: return err_response(result_info) topic_info = result_info[2] is_admin = False is_level0_admin = False uid = session.get('uid') if uid: result_admin_site = forum.admin_check(uid) if result_admin_site[0] != 0: return err_response(result_admin_site) result_admin = forum.admin_check(uid, topic_info['board']) if result_admin[0] != 0: return err_response(result_admin) if result_admin_site[2]['admin']: is_level0_admin = True elif result_admin[2]['admin']: is_level0_admin = (result_admin[2]['level'] == 0) else: is_level0_admin = False is_admin = (result_admin_site[2]['admin'] or result_admin[2]['admin']) result = forum.post_list(tid, int(pn), count_post) if result[0] != 0: return err_response(result) elif not result[2]['list']: return err_response((248, _('No such page.')) ) else: data = result[2] for post in data['list']: result_subpost = forum.post_list( post['pid'], 1, COUNT_SUBPOST, subpost=True ) if result_subpost[0] != 0: return err_response(result_subpost) post['subposts'] = result_subpost[2] return render_template( 'topic_content.html', tid = tid, topic_info = topic_info, data = result[2], pn = int(pn), count_post = count_post, count_subpost = COUNT_SUBPOST, is_admin = is_admin, is_level0_admin = is_level0_admin )
def topic(tid): pn = request.args.get('pn', '1') count_post = int(config['count_post']) try: validate_id(_('Page Number'), pn) except ValidationError as err: return validation_err_response(err, json=False) result_info = forum.topic_info(tid) if result_info[0] != 0: return err_response(result_info) topic_info = result_info[2] is_admin = False is_level0_admin = False uid = session.get('uid') if uid: result_admin_site = forum.admin_check(uid) if result_admin_site[0] != 0: return err_response(result_admin_site) result_admin = forum.admin_check(uid, topic_info['board']) if result_admin[0] != 0: return err_response(result_admin) if result_admin_site[2]['admin']: is_level0_admin = True elif result_admin[2]['admin']: is_level0_admin = (result_admin[2]['level'] == 0) else: is_level0_admin = False is_admin = (result_admin_site[2]['admin'] or result_admin[2]['admin']) result = forum.post_list(tid, int(pn), count_post) if result[0] != 0: return err_response(result) elif not result[2]['list']: return err_response((248, _('No such page.'))) else: data = result[2] for post in data['list']: result_subpost = forum.post_list(post['pid'], 1, COUNT_SUBPOST, subpost=True) if result_subpost[0] != 0: return err_response(result_subpost) post['subposts'] = result_subpost[2] return render_template('topic_content.html', tid=tid, topic_info=topic_info, data=result[2], pn=int(pn), count_post=count_post, count_subpost=COUNT_SUBPOST, is_admin=is_admin, is_level0_admin=is_level0_admin)
def topic_move_form(tid): result_info = forum.topic_info(tid) if result_info[0] != 0: return err_response(result_info) result_board = forum.board_list() if result_board[0] != 0: return err_response(result_board) return render_template('form_move.html', tid=tid, source=result_info[2]['board'], board_list=result_board[2]['list'])
def topic_move_form(tid): result_info = forum.topic_info(tid) if result_info[0] != 0: return err_response(result_info) result_board = forum.board_list() if result_board[0] != 0: return err_response(result_board) return render_template( 'form_move.html', tid = tid, source = result_info[2]['board'], board_list = result_board[2]['list'] )
def topic_distillate_unset(tid): operator = session.get('uid') if not operator: return json_response((249, _('Not signed in.'))) result_board = forum.topic_info(tid) if result_board[0] != 0: return json_response(result_board) board = result_board[2]['board'] try: if check_permission(operator, board, level0=True): return json_response(forum.topic_distillate_unset(tid)) else: return json_response((254, _('Permission denied.'))) except ForumPermissionCheckError as err: return permission_err_response(err)
def topic_distillate_unset(tid): operator = session.get('uid') if not operator: return json_response((249, _('Not signed in.')) ) result_board = forum.topic_info(tid) if result_board[0] != 0: return json_response(result_board) board = result_board[2]['board'] try: if check_permission(operator, board, level0=True): return json_response(forum.topic_distillate_unset(tid) ) else: return json_response((254, _('Permission denied.')) ) except ForumPermissionCheckError as err: return permission_err_response(err)
def topic_pin(tid): revert = request.args.get('revert', '') operator = session.get('uid') if not operator: return json_response((249, _('Not signed in.'))) result_board = forum.topic_info(tid) if result_board[0] != 0: return json_response(result_board) board = result_board[2]['board'] try: if check_permission(operator, board, level0=True): return json_response(forum.topic_pin(tid, revert=bool(revert))) else: return json_response((254, _('Permission denied.'))) except ForumPermissionCheckError as err: return permission_err_response(err)
def topic_pin(tid): revert = request.args.get('revert', '') operator = session.get('uid') if not operator: return json_response((249, _('Not signed in.')) ) result_board = forum.topic_info(tid) if result_board[0] != 0: return json_response(result_board) board = result_board[2]['board'] try: if check_permission(operator, board, level0=True): return json_response(forum.topic_pin(tid, revert=bool(revert)) ) else: return json_response((254, _('Permission denied.')) ) except ForumPermissionCheckError as err: return permission_err_response(err)
def post_add(): parent = request.form.get('parent', '') content = request.form.get('content', '') reply = request.form.get('reply', '0') # subpost: argument from URL subpost = request.args.get('subpost', '') try: validate_id(_('Parent Topic/Post ID'), parent) if not subpost: validate(_('Content'), content, not_empty=True) else: validate(_('Content'), content, min=1, max=200) if reply != '0': validate_id(_('Subpost to Reply'), reply) except ValidationError as err: return validation_err_response(err) uid = session.get('uid') if not uid: return json_response((249, _('Not signed in.')) ) if subpost: result_board = forum.post_get_board(parent) else: result_board = forum.topic_info(parent) if result_board[0] != 0: return json_response(result_board) board = result_board[2]['board'] result_ban_global = forum.ban_check(uid) if result_ban_global[0] != 0: return json_response(result_ban_global) result_ban_local = forum.ban_check(uid, board) if result_ban_local[0] != 0: return json_response(result_ban_local) if result_ban_global[2]['banned'] or result_ban_local[2]['banned']: return json_response((252, _('You are being banned.')) ) if subpost: content = content.replace('\n', ' ').replace('\r', '') return json_response( forum.post_add(parent, uid, content, bool(subpost), int(reply)) )
def post_add(): parent = request.form.get('parent', '') content = request.form.get('content', '') reply = request.form.get('reply', '0') # subpost: argument from URL subpost = request.args.get('subpost', '') try: validate_id(_('Parent Topic/Post ID'), parent) if not subpost: validate(_('Content'), content, not_empty=True) else: validate(_('Content'), content, min=1, max=200) if reply != '0': validate_id(_('Subpost to Reply'), reply) except ValidationError as err: return validation_err_response(err) uid = session.get('uid') if not uid: return json_response((249, _('Not signed in.'))) if subpost: result_board = forum.post_get_board(parent) else: result_board = forum.topic_info(parent) if result_board[0] != 0: return json_response(result_board) board = result_board[2]['board'] result_ban_global = forum.ban_check(uid) if result_ban_global[0] != 0: return json_response(result_ban_global) result_ban_local = forum.ban_check(uid, board) if result_ban_local[0] != 0: return json_response(result_ban_local) if result_ban_global[2]['banned'] or result_ban_local[2]['banned']: return json_response((252, _('You are being banned.'))) if subpost: content = content.replace('\n', ' ').replace('\r', '') return json_response( forum.post_add(parent, uid, content, bool(subpost), int(reply)))
def topic_remove(tid): revert = request.args.get('revert') operator = session.get('uid') if not operator: return json_response((254, _('Permission denied.'))) result_board = forum.topic_info(tid) if result_board[0] != 0: return json_response(result_board) board = result_board[2]['board'] try: if check_permission(operator, board): if not revert: return json_response(forum.topic_remove(tid, operator)) else: return json_response(forum.topic_revert(tid)) else: return json_response((254, _('Permission denied.'))) except ForumPermissionCheckError as err: return permission_err_response(err)
def topic_distillate_set(tid): category = request.args.get('category', '') try: validate(_('Category Name'), category, not_empty=True) except ValidationError as err: return validation_err_response(err) operator = session.get('uid') if not operator: return json_response((249, _('Not signed in.'))) result_board = forum.topic_info(tid) if result_board[0] != 0: return json_response(result_board) board = result_board[2]['board'] try: if check_permission(operator, board, level0=True): return json_response(forum.topic_distillate_set(tid, category)) else: return json_response((254, _('Permission denied.'))) except ForumPermissionCheckError as err: return permission_err_response(err)
def topic_remove(tid): revert = request.args.get('revert') operator = session.get('uid') if not operator: return json_response((254, _('Permission denied.')) ) result_board = forum.topic_info(tid) if result_board[0] != 0: return json_response(result_board) board = result_board[2]['board'] try: if check_permission(operator, board): if not revert: return json_response(forum.topic_remove(tid, operator)) else: return json_response(forum.topic_revert(tid)) else: return json_response((254, _('Permission denied.')) ) except ForumPermissionCheckError as err: return permission_err_response(err)
def topic_distillate_set(tid): category = request.args.get('category', '') try: validate(_('Category Name'), category, not_empty=True) except ValidationError as err: return validation_err_response(err) operator = session.get('uid') if not operator: return json_response((249, _('Not signed in.')) ) result_board = forum.topic_info(tid) if result_board[0] != 0: return json_response(result_board) board = result_board[2]['board'] try: if check_permission(operator, board, level0=True): return json_response(forum.topic_distillate_set(tid, category) ) else: return json_response((254, _('Permission denied.')) ) except ForumPermissionCheckError as err: return permission_err_response(err)
def topic_move(tid): target = request.form.get('target') try: validate_board(_('Target'), target) except ValidationError as err: return validation_err_response(err) operator = session.get('uid') if not operator: return json_response((249, _('Not signed in.'))) result_board = forum.topic_info(tid) if result_board[0] != 0: return json_response(result_board) board = result_board[2]['board'] try: if check_permission(operator, board): return json_response(forum.topic_move(tid, target)) else: return json_response((254, _('Permission denied.'))) except ForumPermissionCheckError as err: return permission_err_response(err)
def topic_move(tid): target = request.form.get('target') try: validate_board(_('Target'), target) except ValidationError as err: return validation_err_response(err) operator = session.get('uid') if not operator: return json_response((249, _('Not signed in.')) ) result_board = forum.topic_info(tid) if result_board[0] != 0: return json_response(result_board) board = result_board[2]['board'] try: if check_permission(operator, board): return json_response(forum.topic_move(tid, target)) else: return json_response((254, _('Permission denied.')) ) except ForumPermissionCheckError as err: return permission_err_response(err)