Compare commits
2 Commits
dcf3a571d5
...
26006c698f
Author | SHA1 | Date |
---|---|---|
Remi Rampin | 26006c698f | |
Remi Rampin | db4cb67757 |
|
@ -1,6 +1,6 @@
|
|||
import bisect
|
||||
from datetime import datetime, timedelta
|
||||
from flask import Flask, jsonify, redirect, request
|
||||
from flask import Flask, jsonify, make_response, redirect, request
|
||||
from google.auth.transport.requests import Request
|
||||
from google.oauth2.credentials import Credentials
|
||||
from googleapiclient.discovery import build
|
||||
|
@ -14,7 +14,8 @@ WEEK_DAYS = {1, 2, 3, 4, 5}
|
|||
FROM = 9
|
||||
TO = 17
|
||||
|
||||
TIMEZONE = pytz.timezone('America/New_York')
|
||||
TIMEZONE_NAME = 'America/New_York'
|
||||
TIMEZONE = pytz.timezone(TIMEZONE_NAME)
|
||||
|
||||
AVAILABILITY_LIFETIME = timedelta(minutes=2)
|
||||
|
||||
|
@ -31,8 +32,12 @@ def read_datetime(dct):
|
|||
return dt
|
||||
|
||||
|
||||
def asiso(dt):
|
||||
return dt.isoformat()[:19]
|
||||
|
||||
|
||||
def asutciso(dt):
|
||||
return dt.astimezone(UTC).isoformat()[:19] + 'Z'
|
||||
return asiso(dt.astimezone(UTC)) + 'Z'
|
||||
|
||||
|
||||
def aslocal(dt):
|
||||
|
@ -111,6 +116,49 @@ def api_availability():
|
|||
return jsonify({'availability': [asutciso(time) for time in availability]})
|
||||
|
||||
|
||||
@app.route('/book', methods=['POST'])
|
||||
@app.route('/book', methods=['POST', 'OPTIONS'])
|
||||
def api_book():
|
||||
TODO
|
||||
# Allow cross-origin
|
||||
if request.method == 'OPTIONS':
|
||||
response = make_response()
|
||||
response.headers.add(
|
||||
'Access-Control-Allow-Origin',
|
||||
'https://vicky.rampin.org',
|
||||
)
|
||||
response.headers.add(
|
||||
'Access-Control-Allow-Headers',
|
||||
'Content-Type',
|
||||
)
|
||||
response.headers.add(
|
||||
'Access-Control-Allow-Methods',
|
||||
'POST',
|
||||
)
|
||||
return response
|
||||
|
||||
if not creds.valid:
|
||||
creds.refresh(Request())
|
||||
service = build('calendar', 'v3', credentials=creds)
|
||||
|
||||
full_name = request.form['name']
|
||||
email = request.form['email']
|
||||
topic = request.form['topic']
|
||||
date = request.form['date']
|
||||
|
||||
end = start + timedelta(minutes=30)
|
||||
|
||||
service.events().insert(
|
||||
calendarId='primary',
|
||||
body=dict(
|
||||
start={'dateTime': asiso(start), 'timeZone': TIMEZONE_NAME},
|
||||
end={'dateTime': asiso(end), 'timeZone': TIMEZONE_NAME},
|
||||
summary="Meeting with Vicky",
|
||||
description="Meeting scheduled from the web",
|
||||
),
|
||||
)
|
||||
|
||||
response = redirect('https://vicky.rampin.org/book-successful', 303)
|
||||
response.headers.add(
|
||||
'Access-Control-Allow-Origin',
|
||||
'https://vicky.rampin.org',
|
||||
)
|
||||
return response
|
||||
|
|
28
form.html
28
form.html
|
@ -7,48 +7,34 @@
|
|||
<body>
|
||||
|
||||
<div class="container px-5 my-5">
|
||||
<form id="contactForm" data-sb-form-api-token="API_TOKEN">
|
||||
<form id="contactForm">
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="name">Full name</label>
|
||||
<input class="form-control" id="name" name="name" type="text" placeholder="Full name" data-sb-validations="required" />
|
||||
<div class="invalid-feedback" data-sb-feedback="fullName:required">Full name is required.</div>
|
||||
<input class="form-control" id="name" name="name" type="text" placeholder="Full name" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="email">Email address</label>
|
||||
<input class="form-control" id="email" name="email" type="email" placeholder="Email address" data-sb-validations="required,email" />
|
||||
<div class="invalid-feedback" data-sb-feedback="emailAddress:required">Email address is required.</div>
|
||||
<div class="invalid-feedback" data-sb-feedback="emailAddress:email">Email address Email is not valid.</div>
|
||||
<input class="form-control" id="email" name="email" type="email" placeholder="Email address" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="topic">What would you like to discuss?</label>
|
||||
<textarea class="form-control" id="topic" name="topic" placeholder="What would you like to discuss?" style="height: 10rem;" data-sb-validations="required"></textarea>
|
||||
<div class="invalid-feedback" data-sb-feedback="whatWouldYouLikeToDiscuss:required">What would you like to discuss? is required.</div>
|
||||
<textarea class="form-control" id="topic" name="topic" placeholder="What would you like to discuss?" style="height: 10rem;"></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label d-block">Which day and time works best for us to meet on Zoom?</label>
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input" id="optionA" type="radio" name="date" data-sb-validations="" />
|
||||
<input class="form-check-input" id="optionA" type="radio" name="date" />
|
||||
<label class="form-check-label" for="optionA">option A</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input" id="optionB" type="radio" name="date" data-sb-validations="" />
|
||||
<input class="form-check-input" id="optionB" type="radio" name="date" />
|
||||
<label class="form-check-label" for="optionB">option B</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input" id="optionC" type="radio" name="date" data-sb-validations="" />
|
||||
<input class="form-check-input" id="optionC" type="radio" name="date" />
|
||||
<label class="form-check-label" for="optionC">option C</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-none" id="submitSuccessMessage">
|
||||
<div class="text-center mb-3">
|
||||
<div class="fw-bolder">Form submission successful!</div>
|
||||
<p>To activate this form, sign up at</p>
|
||||
<a href="https://startbootstrap.com/solution/contact-forms">https://startbootstrap.com/solution/contact-forms</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-none" id="submitErrorMessage">
|
||||
<div class="text-center text-danger mb-3">Error sending message!</div>
|
||||
</div>
|
||||
<div class="d-grid">
|
||||
<button class="btn btn-primary btn-lg disabled" id="submitButton" type="submit">Submit</button>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue