Example #1
0
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)