Beispiel #1
0
def edit(id):
    job = get_model().read(id)

    if request.method == 'POST':
        data = request.form.to_dict(flat=True)

        # If an image was uploaded, update the data to point to the new image.
        file_url = upload_file(request.files.get('details_file'))

        if file_url:
            data['fileURL'] = file_url

        job = get_model().update(data, id)

        return redirect(url_for('.view', id=job['id']))

    return render_template("form.html", action="Edit", job=job)
Beispiel #2
0
def list():
    token = request.args.get('page_token', None)
    if token:
        token = token.encode('utf-8')

    jobs, next_page_token = get_model().list(cursor=token)

    return render_template("list.html",
                           jobs=jobs,
                           next_page_token=next_page_token)
Beispiel #3
0
def list_mine():
    token = request.args.get('page_token', None)
    if token:
        token = token.encode('utf-8')

    jobs, next_page_token = get_model().list_by_user(
        user_id=session['profile']['id'], cursor=token)

    return render_template("list.html",
                           jobs=jobs,
                           next_page_token=next_page_token)
Beispiel #4
0
def add():
    if request.method == 'POST':
        data = request.form.to_dict(flat=True)

        # If an image was uploaded, update the data to point to the new image.
        file_url = upload_file(request.files.get('details_file'))

        if file_url:
            data['fileURL'] = file_url

        # If the user is logged in, associate their profile with the new job.
        if 'profile' in session:
            data['createdBy'] = session['profile']['displayName']
            data['createdById'] = session['profile']['id']

        job = get_model().create(data)

        return redirect(url_for('.view', id=job['id']))

    return render_template("form.html", action="Add", job={})
Beispiel #5
0
def view(id):
    job = get_model().read(id)
    return render_template("view.html", job=job)
Beispiel #6
0
def delete(id):
    get_model().delete(id)
    return redirect(url_for('.list'))