def create(): form = forms.Post() if form.validate_on_submit(): models.Entry.create( title=form.title.data, date=datetime.datetime.combine(form.date.data, datetime.datetime.now().time()), time_spent=form.time_spent.data, learned=form.learned.data, remember=form.remember.data, user_id=current_user.id ) tags_list = form.tags.data.split(', ') entry = models.Entry.get(models.Entry.title == form.title.data) for item in tags_list: try: models.Tags.create(tag=item) except: pass for tag in tags_list: tag_data = models.Tags.get(models.Tags.tag == tag) models.EntryTags.create( entry_id=entry.id, tag_id=tag_data ) flash("Your Entry has been created!") return redirect(url_for('index')) return render_template('new.html', form=form)
def edit(id): entry = models.Entry.select().where(models.Entry.id == id).get() tags_list = [] for tag in get_tags(id): tags_list.append(tag.tag) tags = ", ".join(tags_list) form = forms.Post() if form.validate_on_submit(): entry.title = form.title.data entry.date = (datetime.datetime .combine(form.date.data, entry.date.time()) ) entry.time_spent = form.time_spent.data entry.learned = form.learned.data entry.remember = form.remember.data for item in form.tags.data.split(', '): try: models.Tags.create(tag=item) except: pass entry.save() del_tags(id) for tag in form.tags.data.split(', '): tag_data = models.Tags.get(models.Tags.tag == tag) models.EntryTags.create( entry_id=entry.id, tag_id=tag_data.id ) flash("Your Entry has been edited!") return redirect(url_for('index')) return render_template("edit.html", form=form, id=id, models=models, tags=tags)
def add_post(): form = forms.Post() if form.validate_on_submit(): out = process(form.content.data) post = Post(title=form.title.data, content=form.content.data, tags=str(out)) db.session.add(post) db.session.commit() return redirect(url_for("list_post")) return render_template('add_post.html', form=form)
def create_post(id=None): """Display form for creating a post.""" form = forms.Post() if form.validate_on_submit(): models.Post.create(project_id=id, name=form.name.data, content=form.content.data) post = (models.Post.select() .where( (models.Post.name == form.name.data), (models.Post.content == form.content.data)).get()) for fileid in request.files: logging.debug('detected file id by {}'.format(fileid)) file = request.files.get(str(fileid)) logging.debug('fileid = {}'.format(fileid)) upload_file(file, post.id) return redirect(url_for('admin')) return render_template('create_post.html', form=form)