A few updates.

This commit is contained in:
Elf M. Sternberg 2016-02-08 15:09:08 -08:00
parent dd91a3cb85
commit 1ab5bb05fd
5 changed files with 43 additions and 25 deletions

View File

@ -2,7 +2,9 @@
(import [flask [Flask]]) (import [flask [Flask]])
(def app (Flask __name__)) (def app (Flask __name__))
(def hello ((.route app "/") (fn [] "Hello World")))
(with-decorator (.route app "/") (defn hello [] "Hello World"))
(if (= __name__ "__main__") (if (= __name__ "__main__")
(.run app)) (.run app))

View File

@ -1,8 +1,7 @@
# from http://flask.pocoo.org/ tutorial
from flask import Flask from flask import Flask
app = Flask(__name__) app = Flask(__name__)
@app.route("/") # take note of this decorator syntax, it's a common pattern @app.route("/") # take note of this decorator syntax, it's a common pattern
def hello(): def hello():
return "Hello World!" return "Hello World!"

View File

@ -15,6 +15,14 @@ Note: "BS" stands for BrainStorming.
slot is booked, other clients should not be able to book that slot slot is booked, other clients should not be able to book that slot
with the same coach. with the same coach.
## Alternatives
Google Calendar offers an "office hours" appointment mechanism. It
doesn't quite do what the problem requires; it's only available to
other members of the same school or corporate group account.
## Solution requirements: ## Solution requirements:
* Data Store * Data Store
@ -175,7 +183,12 @@ TODO Postgres range example
TODO Deliver home page TODO Deliver home page
TODO Deliver retreivals TODO Deliver retreivals
---
Quick thoughts:
Craft views or

View File

@ -1,4 +1,5 @@
Re-learning how to install Postgres (*Sigh) # Re-learning how to install Postgres (*Sigh)
## WITH Postgres 9.4
CREATE DATABASE officehours; CREATE DATABASE officehours;
CREATE USER officehours; CREATE USER officehours;
@ -16,17 +17,15 @@ CREATE EXTENSION citext;
CREATE EXTENSION btree_gist; CREATE EXTENSION btree_gist;
CREATE EXTENSION plv8; CREATE EXTENSION plv8;
#
What can I do?
1) Add users and make them clients.
2) Add users and make them staff.
3) Allocate a block of time as "office hours"
4) Allocate a block of time as an "appointment."
NEXT: Psycopg2 # What can I do?
** Progress: Everything works in psycopg2 EXCEPT add_appointment, which 1) Add users and make them clients.
is very distressing. Really, _really_ don't want to take that 2) Add users and make them staff.
functionality and put it into the middle tier. It's rock-solid business 3) Allocate a block of time as "office hours"
logic; it belongs in the database as a constraint. 4) Allocate a block of time as an "appointment."
## Progress:
Everything works in psycopg2.

21
play.hy
View File

@ -7,7 +7,6 @@
(defn connect [] (defn connect []
(psycopg2.connect "host='localhost' dbname='officehours' user='officehours' password='eatabug'")) (psycopg2.connect "host='localhost' dbname='officehours' user='officehours' password='eatabug'"))
(def users [ (def users [
(, "Alice" "alice@example.com") (, "Alice" "alice@example.com")
(, "Bob" "bob@example.com") (, "Bob" "bob@example.com")
@ -58,16 +57,22 @@
(.execute curs "INSERT INTO officehours (staff_id, during) VALUES (2, '[2015-02-07 12:00, 2015-02-07 15:00)');") (.execute curs "INSERT INTO officehours (staff_id, during) VALUES (2, '[2015-02-07 12:00, 2015-02-07 15:00)');")
(.commit conn)) (.commit conn))
; [ops ["SELECT add_appointment(3, '[2015-02-07 10:00, 2015-02-07 10:30)');"
; "SELECT add_appointment(4, '[2015-02-07 10:30, 2015-02-07 11:00)');"
; "SELECT add_appointment(5, '[2015-02-07 13:00, 2015-02-07 13:30)');"
; "SELECT add_appointment(6, '[2015-02-07 13:30, 2015-02-07 14:00)');"]]]
(let [[conn (connect)] (let [[conn (connect)]
[curs (.cursor conn)] [curs (.cursor conn)]
[ops ["SELECT add_appointment(3, '[2015-02-07 10:00, 2015-02-07 10:30)');" [ops [(, 3 "[2015-02-07 10:00, 2015-02-07 10:30)")
"SELECT add_appointment(4, '[2015-02-07 10:30, 2015-02-07 11:00)');" (, 4 "[2015-02-07 10:30, 2015-02-07 11:00)")
"SELECT add_appointment(5, '[2015-02-07 13:00, 2015-02-07 13:30)');" (, 5 "[2015-02-07 13:00, 2015-02-07 13:30)")
"SELECT add_appointment(6, '[2015-02-07 13:30, 2015-02-07 14:00)');"]]] (, 6 "[2015-02-07 13:30, 2015-02-07 14:00)")]]]
(for [op ops] (for [op ops]
(print op) (.callproc curs "add_appointment" op)
(.execute curs op)
(.commit conn))) (.commit conn)))
(let [[conn (connect)] (let [[conn (connect)]