예제 #1
0
def update(book_id):
    book = firestore.read(book_id)
    form = BookForm(data=book)

    # Process form if submission request
    if form.validate_on_submit():
        data = form.data
        book = firestore.update(data, book_id)
        return redirect(url_for('app.view', book_id=book['id']))

    book = firestore.read(book_id)
    return render_template('book_form.html', form=form, header="Update Book")
예제 #2
0
파일: main.py 프로젝트: gcp-bob/my_app
def edit(entry_id):
    entry = firestore.read(entry_id)
    if request.method == 'POST':
        data = request.form.to_dict(flat=True)
        entry = firestore.update(data, entry_id)
        return redirect(url_for('.view', entry_id=entry['id']))
    return render_template('form.html', action='Edit', entry=entry)
예제 #3
0
def test_delete(app, firestore):
    existing = firestore.create({'title': "Temp Title"})

    with app.test_client() as c:
        rv = c.get('images/%s/delete' % existing['id'], follow_redirects=True)

    assert rv.status == '200 OK'
    assert not firestore.read(existing['id'])
예제 #4
0
def edit(book_id):
    book = firestore.read(book_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.
        image_url = upload_image_file(request.files.get('image'))

        if image_url:
            data['imageUrl'] = image_url

        book = firestore.update(data, book_id)

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

    return render_template('form.html', action='Edit', book=book)
예제 #5
0
파일: main.py 프로젝트: gcp-bob/my_app
def countdown(entry_id):
    entry = firestore.read(entry_id)
    yob_id = request.form.get('yob', type=int)
    mob_id = request.form.get('mob', type=int)
    dob_id = request.form.get('dob', type=int)
    # Get Today's Date
    today = date.today()
    today_txt = "Today: " + today.strftime('%A %d, %b %Y')
    isvalid = True
    try:
        datetime.datetime(yob_id, mob_id, dob_id)
    except ValueError:
        isvalid = False
    if isvalid:
        dob = date(yob_id, mob_id, dob_id)
    else:
        prb_dob = "Please edit your birth date in Firestore to a valid one, different than 30th of February ;)"
        return render_template('countdown.html', entry=entry, prb_dob=prb_dob)
    if date(yob_id, mob_id, dob_id) >= today:
        prb_dob = "Please edit your birth date in Firestore to a valid one, before today :)"
        return render_template('countdown.html', entry=entry, prb_dob=prb_dob)
    # Calculate number of days lived
    number_of_days = (today - dob).days
    # Convert this into whole years to display the age
    age = number_of_days // 365
    age_txt = "You are " + str(age) + " years old."
    # Retrieve the day of the week (Monday to Sunday) corresponding to the birth date
    day = dob.strftime("%A")
    dob_txt = "You were born on a " + day + "."
    doe_txt = "You have spent " + str(number_of_days) + " days on Earth."
    # Calculating the number of days until next birthday
    this_year = today.year
    next_birthday = date(this_year, mob_id, dob_id)
    if today < next_birthday:
        gap = (next_birthday - today).days
        count_down = "Your birthday is in " + str(gap) + " days."
    elif today == next_birthday:
        count_down = "Today is your birthday! Happy Birthday!"
    else:
        next_birthday = date(this_year + 1, mob_id, dob_id)
        gap = (next_birthday - today).days
        count_down = "Your birthday is in " + str(gap) + " days."
    return render_template('countdown.html', entry=entry, today_txt=today_txt,
                           age_txt=age_txt, dob_txt=dob_txt, doe_txt=doe_txt, count_down=count_down)
예제 #6
0
def confirm_item(item_id):
    item = firestore.read(item_id)
    if request.method == 'POST':
        data = request.form.to_dict(flat=True)
        email = data.get("email")
        if email is None:
            return render_template("confirm.html", error_message="Please enter a valid email")
        if email_helper.send_order_confirmation(email, item):
            firestore.update_inventory(item_id)
        user_data = {
            "first_name": data.get("first_name"),
            "last_name": data.get("last_name"),
            "email": data.get("email"),
        }
        user = firestore.create_user(user_data)
        order_data = {
            "item_id": item.get("id"),
            "user_id": user.get("id"),
            "units": int(data.get("units")),
        }
        firestore.create_order(order_data)
        return redirect(url_for('.list_items'))
    return render_template("confirm.html", item=item)
예제 #7
0
def view(book_id):
    book = firestore.read(book_id)
    return render_template('view.html', book=book)
예제 #8
0
def item_detail(item_id):
    item = firestore.read(item_id)
    return render_template('item_details.html', item=item)
예제 #9
0
def view(movies_id):
    movies = firestore.read(movies_id)
    return render_template('view.html', movies=movies)
예제 #10
0
def view(venusdoc_id):
    venusdoc = firestore.read(venusdoc_id)
    return render_template('view.html', venusdoc=venusdoc)
예제 #11
0
파일: main.py 프로젝트: gcp-bob/my_app
def birthday(entry_id):
    entry = firestore.read(entry_id)
    return render_template('countdown.html', entry=entry)
예제 #12
0
파일: main.py 프로젝트: gcp-bob/my_app
def view(entry_id):
    entry = firestore.read(entry_id)
    return render_template('view.html', entry=entry)