Exemplo n.º 1
0
def new_tag_submission():
    """Submits the new tag to the DB"""
    name = request.form['name']
    if name == '':
        flash('Your tag must have a name!')
        return redirect(f'/tags/new')
    else:
        try:
            Tag.add(name)
            return redirect(f'/tags')
        except:
            flash('I think We already got that Tag!')
            return redirect(f'/tags/new')
Exemplo n.º 2
0
def edit_tag_submission(tag_id):
    """Process edit form, edit tag, and redirects to the tags list."""

    tag = Tag.get(tag_id)
    new_name = request.form.get('name').strip()
    if not new_name:
        flash('Your tag must have a name!')
        return redirect(f'/tags/{tag_id}/edit')
    else:
        try:
            tag.update_name(new_name)
            return redirect(f'/tags')
        except:
            flash("That um.. didnt work...")
            return redirect(f'/tags/{tag_id}/edit')
Exemplo n.º 3
0
def process_post_form(form):
    title = form.get('title').strip()
    content = form.get('content').strip()

    if not title or not content:
        return False
    else:
        post = {'title': title, 'content': content}

        all_tags = Tag.get_all()
        post_tags = []
        for tag in all_tags:
            if form.get(f'tag_{tag.id}') == 'on':
                post_tags.append(tag.id)
        post['tags'] = post_tags
        return post
Exemplo n.º 4
0
def add_tag_to_db(name):
    test_tag = Tag(name=name)
    db.session.add(test_tag)
    db.session.commit()
    return test_tag.id
Exemplo n.º 5
0
def edit_post_form(post_id):
    """Displays the form to edit the specified post"""
    post = Post.get(post_id)
    tags = Tag.get_all()
    return render_template('post_edit_form.html', post=post, tags=tags)
Exemplo n.º 6
0
def new_post_form(user_id):
    """Shows the New Post Form"""
    user = User.get(user_id)
    tags = Tag.get_all()
    return render_template('post_new_form.html', user=user, tags=tags)
Exemplo n.º 7
0
from models.Tag import Tag
try:
    tag = Tag.select(Tag.id).where(Tag.name == "أكdsdsشن").get()
except:
    print("Nothing")
Exemplo n.º 8
0
def edit_tag_form(tag_id):
    """displays the form to edit the tag"""
    return render_template("tag_edit_form.html", tag=Tag.get(tag_id))
Exemplo n.º 9
0
def delete_tag(tag_id):
    """deletes the specified tag"""
    Tag.delete_by_id(tag_id)
    return redirect('/tags')
Exemplo n.º 10
0
def describe_tags(tag_id):
    """Lists the posts assosiated with the tag"""
    tag = Tag.get(tag_id)
    return render_template('tag_details.html', tag=tag)