Пример #1
0
def create():
    if request.method == 'POST':
        form = EntryForm(request.form)
        if form.validate():
            entry = form.save_entry(Entry(author=g.user))
            db.session.add(entry)
            db.session.commit()
            flash('Entry "%s" created successfully.' % entry.title, 'success')
            return redirect(url_for('entries.detail', slug=entry.slug))
    else:
        form = EntryForm()
    return render_template('entries/create.html', form=form)
Пример #2
0
def add_entry(project):
    form = EntryForm(request.form)
    if not form.validate():
        return str(form.errors)
    name = form.name.data
    value = form.value.data
    project_id = form.project_id.data

    entry = Entry(name, value, project_id)
    db.session.add(entry)
    db.session.commit()
    return redirect(url_for('view_project',name=project))
Пример #3
0
def edit(slug):
    entry = get_entry_or_404(slug, g.user)
    if request.method == 'POST':
        form = EntryForm(request.form, obj=entry)
        if form.validate():
            entry = form.save_entry(entry)
            db.session.add(entry)
            db.session.commit()
            flash('Blog: %s ,Edited! ' %entry.title, 'success')
            return redirect(url_for('entries.detail', slug = entry.slug))
    else:
        form = EntryForm(obj = entry)
        return render_template('entries/edit.html', entry = entry, form = form)
Пример #4
0
def create():
    form = EntryForm()
    if request.method == 'POST':
        form = EntryForm(request.form)
        if form.validate():
            entry = form.save_entry(Entry(author = g.user))
            db.session.add(entry)
            db.session.commit()
            flash('Blog: %s ,Created! ' %entry.title, 'success')
            return redirect(url_for('entries.detail', slug = entry.slug))
        else:
            form = EntryForm()
    return render_template('entries/create.html',form = form)
Пример #5
0
def edit(slug):
    entry = get_entry_or_404(slug, author=None)
    if request.method == 'POST':
        form = EntryForm(request.form, obj=entry)
        if form.validate():
            entry = form.save_entry(entry)
            db.session.add(entry)
            db.session.commit()
            flash('Entry "%s" has been saved.' % entry.title, 'success')
            return redirect(url_for('entries.detail', slug=entry.slug))
    else:
        form = EntryForm(obj=entry)
    return render_template('entries/edit.html', entry=entry, form=form)
Пример #6
0
def create():
	if request.method == 'POST':
		form = EntryForm(request.form)
		if form.validate():
			# saved in the database as the author of that entry
			entry = form.save_entry(Entry(author=g.user))
			# entry = form.save_entry(Entry())
			try:
				db.session.add(entry)
				db.session.commit()
			except IntegrityError as err:
				db.session.rollback()
				flash('Entry "%s" did not create successfully.' % entry.title, 'warning')
			else:
				flash('Entry "%s" created successfully.' % entry.title, 'success')
				return redirect(url_for('entries.detail', slug=entry.slug))
	else:
		form = EntryForm()
	return render_template('entries/create.html', form=form)
Пример #7
0
def edit(slug):
	# entry = Entry.query.filter(Entry.slug == slug).first_or_404()
	# entry = get_entry_or_404(slug)
	entry = get_entry_or_404(slug, author=None)
	if request.method == 'POST':
		# When WTForms receives an obj parameter, it will attempt to pre-populate the form  fields with values taken from obj
		form = EntryForm(request.form, obj=entry)
		if form.validate():
			entry = form.save_entry(entry)
			try:
				db.session.add(entry)
				db.session.commit()
			except IntegrityError as err:
				db.session.rollback()
				flash('Entry "%s" did not update successfully.' % entry.title, 'warning')
			else:
				flash('Entry "%s" has been saved.' % entry.title, 'success')
				return redirect(url_for('entries.detail', slug=entry.slug))
	else:
		form = EntryForm(obj=entry)
	return render_template('entries/edit.html', entry=entry, form=form)