def tag_moderate_edit_info(tag_name): try: tag = Tag(tag_name) except: error_context = { 'error_name': "404 Not Found", 'error_info': "The tag you tried to access does not exist, but you can create this tag." } return render_template('error.html', **error_context) if not check.logged_in(): error_context = { 'error_name': "Forbidden", 'error_info': "You may not access this page without logging in" } return render_template('error.html', **error_context) if not TagModerator.is_mod(session['user_id'], tag.id): error_context = { 'error_name': "Access Denied", 'error_info': "You are not a moderator of this tag" } return render_template('error.html', **error_context) form = TagEditForm(csrf_enabled=False) if form.validate_on_submit(): tag.description = form.description.data tag.rules = form.rules.data tag.save() flash('Tag info saved') return redirect(url_for('tag_pages.tag_moderate', tag_name=tag_name))
def tag_create(): if not check.logged_in(): error_context = { 'error_name': "403 Forbidden", 'error_info': "You may not create a tag without an account. Please log in or create an account" } return render_template('error.html', **error_context) else: form = TagCreationForm() if form.validate_on_submit(): tag = Tag() mod = TagModerator() # TODO: tag name sanitization tag.title = form.title.data tag.date = datetime.now() tag.subscriber_amount = 0 tag.is_banned = False tag.description = form.description.data tag.rules = form.rules.data tag.save() # exact same date of creation denotes original creator mod.date = tag.date mod.user_id = int(session['user_id']) mod.tag_id = tag.id mod.save() flash('New tag created') # TODO: Redirect to tag page return render_template('tag_create.html', form=form) else: return render_template('tag_create.html', form=form)