Beispiel #1
0
def edit(id):
    """Edit route"""
    form = forms.NewForm()
    try:
        detailed_entry = models.Journal.get(models.Journal.entry_id == id)
        if current_user.username != \
                detailed_entry.owner and not current_user.is_admin:
            flash("Updating of other people's"
                  " entries is not allowed.", 'Error')
            return redirect(url_for('detail', id=detailed_entry))
    except models.DoesNotExist:
        abort(404)
    # Fill form
    if form.validate_on_submit():
        detailed_entry.title = form.title.data.strip()
        detailed_entry.date = form.date.data
        detailed_entry.time_spent = form.time_spent.data
        detailed_entry.Characters = form.Characters.data.strip()
        detailed_entry.Play = \
            form.Play.data.strip()
        detailed_entry.tags = form.tags.data.strip()
        detailed_entry.save()
        flash('Update successful', 'success')
        return redirect(url_for('detail', id=id))
    else:
        form.title.data = detailed_entry.title
        form.date.data = detailed_entry.date
        form.time_spent.data = detailed_entry.time_spent
        form.Characters.data = detailed_entry.Characters
        form.Play.data = detailed_entry.Play
        form.tags.data = detailed_entry.tags
    return render_template('edit.html', form=form, id=id)
Beispiel #2
0
def Enter_end0of0day_numbers(data=None):
    cursor = connection.cursor()
    cursor.execute(queries.get_pos_this_week())
    pos = cursor.fetchall()
    if data:
        for po in data:
            # update progress
            cursor.execute(queries.update_progress(po))
            connection.commit()

            # update have
            utils.update_haves(po, connection)

            # update debat numbers
            utils.update_debat_numbers(po, connection)

            # update leftovers
            utils.update_leftovers(po, connection)

        utils.flash_message("Numbers entered!", category='success')

    return flask.render_template('end-of-day.html',
                                 pos=pos,
                                 form=forms.NewForm(),
                                 length=len(pos))
Beispiel #3
0
def create_entry():
    """New entry route"""
    form = forms.NewForm()
    if form.validate_on_submit():
        flash("Yay, you made an entry!", "success")
        models.Journal.add_entry(form.title.data.strip(), form.date.data,
                                 form.time_spent.data,
                                 form.Characters.data.strip(),
                                 form.Play.data.strip(),
                                 form.tags.data.strip(), current_user.username)
        return redirect(url_for('index'))
    return render_template('new.html', form=form)
Beispiel #4
0
def new():
    form = forms.NewForm()
    if form.validate_on_submit():
        models.Entry.create_entry(
            title=form.title.data,
            date=form.date.data,
            time_spent=form.time_spent.data,
            what_you_learned=form.what_you_learned.data,
            resources_to_remember=form.resources_to_remember.data)
        flash("New Entry Created", "success")
        return redirect(url_for('index'))
    return render_template('new.html', form=form)
Beispiel #5
0
def entry(slug=None):
    form = forms.NewForm()
    if slug:
        # Get the Task data
        entry = (models.Task.select()
                 .where(models.Task.title == slug.replace('_', ' ')))

        if entry.count() == 0:
            # invalid slug
            abort(404)
        form_data = entry.get()
        if form.validate_on_submit():
            # data submitted & valid
            form_data.title = form.title.data
            form_data.date = form.date.data
            form_data.time_spent = form.time_spent.data
            form_data.what_i_learned = form.what_i_learned.data
            form_data.resources_to_remember = form.resources_to_remember.data
            form_data.save()
            add_tags(form_data, form.tags.data)
            flash("Entry Updated")
            return redirect(url_for('index'))
        if form.id.data == 0:
            # populate from data
            form.id.data = form_data.id
            form.title.data = form_data.title
            form.date.data = form_data.date
            form.time_spent.data = form_data.time_spent
            form.what_i_learned.data = form_data.what_i_learned
            form.resources_to_remember.data = form_data.resources_to_remember
            alltags = []
            for tag in form_data.get_tags():
                alltags.append(tag.name)
            form.tags.data = ", ".join(alltags)
        if form.errors:
            flash("Not saved, please see errors below")
    else:
        # New Task
        if form.validate_on_submit():
            task = models.Task.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
            )
            # Add Tags
            add_tags(task, form.tags.data)
            flash("New entry saved.")
            return redirect(url_for('index'))
        if form.errors:
            flash("Not saved, please see errors below")
    return render_template('new.html', form=form)
Beispiel #6
0
def edit(title):
    form = forms.NewForm()
    if form.validate_on_submit():
        # Yes, this is a delete then an insert, but I could not get the
        # Peewee update to work properly
        models.Entry.get(models.Entry.title == title).delete_instance()
        models.Entry.create_entry(
            title=form.title.data,
            date=form.date.data,
            time_spent=form.time_spent.data,
            what_you_learned=form.what_you_learned.data,
            resources_to_remember=form.resources_to_remember.data)
        flash("Entry Updated", "success")
        return redirect(url_for('index'))
    return render_template('edit.html', form=form, title=title)