Пример #1
0
def entry(entry_id=None):
    """Page to create a new entry or edit an existing entry"""
    form = forms.JournalEntryForm()
    if entry_id:  # edit an existing entry
        template = 'edit.html'
        entry = models.JournalEntry.get(models.JournalEntry.id==entry_id)

    else:  # create a new entry
        template = 'new.html'
        if form.validate_on_submit():
            try:
                models.JournalEntry.create(
                    user=g.user._get_current_object(),
                    title=form.title.data,
                    date=form.date.data,
                    time_spent=form.time_spent.data,
                    what_i_learned=form.what_i_learned.data,
                    resources_to_remember=form.resources_to_remember.data
                )
            except:
                flash("Journal Entry Failed to save...", 'error')
            else:
                flash("Journal Entry Saved", 'success')
                return redirect(url_for('index'))
    return render_template(template, form=form)
def edit_entry(entry_id):
    entry = None

    form = forms.JournalEntryForm()

    try:
        entry = models.Entries.select().where(
            models.Entries.id == int(entry_id)).get()
    except models.DoesNotExist:
        abort(404)

    # Fetch entry by id
    if request.method == 'GET':
        form.title.data = entry.title
        form.date.data = entry.date
        form.time_spent.data = entry.time_spent
        form.learned.data = entry.learned
        form.resources.data = entry.resources

    else:
        # If information is valid, then update data
        if form.validate_on_submit():
            entry.title = form.title.data.strip()
            entry.date = form.date.data
            entry.time_spent = form.time_spent.data
            entry.learned = form.learned.data.strip()
            entry.resources = form.resources.data.strip()
            entry.save()

            flash("Update is successful")

            # if update is successful, return to detail page
            return redirect(url_for('entry_detail', entry_id=entry_id))

    return render_template('edit.html', form=form, entry_id=entry_id)
Пример #3
0
def create():
    """create new entry"""
    form = forms.JournalEntryForm()
    if form.validate_on_submit():
        models.Entry.create(title=form.title.data, date=form.date.data,
                            timespent=form.timespent.data,
                            post=form.content.data.strip(),
                            resources=form.resources.data.strip())
        flash("Message posted! Thanks!", "success")
        return redirect(url_for('index'))
    else:
        return render_template('new.html', form=form)
Пример #4
0
def edit(id):
    """Edit an entry"""
    form = forms.JournalEntryForm()
    post = models.Entry.get(models.Entry.entry_id == id)
    if form.validate_on_submit():
        post.title = form.title.data
        post.date = form.date.data
        post.timespent = form.timespent.data
        post.post = form.content.data.strip()
        post.resources = form.resources.data.strip()
        post.save()
        return redirect(url_for('index'))
    return render_template('edit.html', form=form, post=post)
Пример #5
0
def add_entry():
	form = forms.JournalEntryForm()
	if form.validate_on_submit():
		models.JournalEntry.create(
			title=form.title.data,
			date=form.date.data,
			time_spent=form.time_spent.data,
			what_i_learned=form.what_i_learned.data,
			resources_to_remember=form.resources_to_remember.data,
			user=g.user._get_current_object()
		)
		flash('New journal entry was added!', 'success')
		return redirect(url_for('index'))
	return render_template('new.html', form=form)
def create_entry():
    form = forms.JournalEntryForm()

    if form.validate_on_submit():

        entry_id = models.Entries.create_entry(
            title=form.title.data.strip(),
            date=form.date.data,
            time_spent=form.time_spent.data,
            learned=form.learned.data.strip(),
            resources=form.resources.data.strip(),
        )

        return redirect(url_for('entry_detail', entry_id=entry_id))

    return render_template('new.html', form=form)
Пример #7
0
def create_new():
    """Create a new journal entry."""
    form = forms.JournalEntryForm()
    if form.validate_on_submit():
        models.Post.create(
            user=g.user.get_id(),
            title=form.title.data.strip(),
            date=form.date.data,
            time_spent=form.time_spent.data,
            what_i_learned=form.what_i_learned.data.strip(),
            resources_to_remember=form.resources_to_remember.data.strip())
        flash("Entry created", "success")
        models.PostTags.tag_new_post(
            models.Post.get(title=form.title.data.strip()))
        return redirect(url_for('view_posts'))
    return render_template('new.html', form=form)
Пример #8
0
def edit_entry(entry_id):
	try:
		entry = models.JournalEntry.get(models.JournalEntry.id == entry_id)
	except models.DoesNotExist:
		abort(404)
	else:
		form_data = {
			'title': entry.title,
			'date': entry.date,
			'time_spent': entry.time_spent,
			'what_i_learned': entry.what_i_learned,
			'resources_to_remember': entry.resources_to_remember
		}
		form = forms.JournalEntryForm(data=form_data)
		if form.validate_on_submit():
			entry.title = form.title.data
			entry.date = form.date.data
			entry.time_spent = form.time_spent.data
			entry.what_i_learned = form.what_i_learned.data
			entry.resources_to_remember = form.resources_to_remember.data
			entry.save()
			flash('Entry has been updated!', 'success')
			return redirect(url_for('journal_entry', entry_id=entry.id))
		return render_template('edit.html', form=form)