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')
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')
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
def add_tag_to_db(name): test_tag = Tag(name=name) db.session.add(test_tag) db.session.commit() return test_tag.id
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)
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)
from models.Tag import Tag try: tag = Tag.select(Tag.id).where(Tag.name == "أكdsdsشن").get() except: print("Nothing")
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))
def delete_tag(tag_id): """deletes the specified tag""" Tag.delete_by_id(tag_id) return redirect('/tags')
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)