diff --git a/.gitignore b/.gitignore index e429938..9d4e3d8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ *~ venv/ node_modules/ +static/ main.py diff --git a/Makefile b/Makefile index 139597f..f45569e 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,6 @@ +static/%.html: source/%.haml + haml --unix-newlines --no-escape-attrs --double-quote-attributes $< > $@ + + diff --git a/main.hy b/main.hy index 021d85e..1e2470c 100644 --- a/main.hy +++ b/main.hy @@ -1,6 +1,6 @@ #!/usr/local/bin/hy -(import psycopg2 psycopg2.extras datetime [flask [Flask jsonify]]) +(import psycopg2 psycopg2.extras datetime [flask [Flask jsonify send-from-directory]]) (def app (Flask __name__)) (defn connect [] @@ -20,26 +20,31 @@ ; This is purely for demonstration purposes. -(with-decorator - (.route app "/") - (defn hello [] - (let [[conn (connect)] - [curs (.cursor conn)] - [week (psycopg2.extras.DateTimeRange (datetime.datetime 2015 1 31 0 0) - (datetime.datetime 2015 2 7 23 59))] - [cmd1 (+ "SELECT during FROM staff_appointments WHERE staff_id IN " - "(SELECT staff_id FROM staff_client_relationships " - "WHERE client_id = %s) AND during && %s")] - [appointments (select curs cmd1 3 week)] - [cmd2 (+ "SELECT during, appointment_id, client_id FROM staff_appointments " - "WHERE client_id = %s AND during && %s")] - [client_appointments (select curs cmd2 3 week)] - [cmd3 (+ "SELECT during FROM officehours WHERE staff_id IN " - "(SELECT staff_id FROM staff_client_relationships " - "WHERE client_id = %s) AND during && %s")] - [officehours (select curs cmd3 3 week)]] - (jsonify { "appointments" (list (map during-to-utc appointments)) - "officehours" (list (map during-to-utc officehours)) })))) +(with-decorator + (.route app "/") + (defn home [] + (send-from-directory "static" "index.html"))) + +;(with-decorator +; (.route app "/") +; (defn hello [] +; (let [[conn (connect)] +; [curs (.cursor conn)] +; [week (psycopg2.extras.DateTimeRange (datetime.datetime 2015 1 31 0 0) +; (datetime.datetime 2015 2 7 23 59))] +; [cmd1 (+ "SELECT during FROM staff_appointments WHERE staff_id IN " +; "(SELECT staff_id FROM staff_client_relationships " +; "WHERE client_id = %s) AND during && %s")] +; [appointments (select curs cmd1 3 week)] +; [cmd2 (+ "SELECT during, appointment_id, client_id FROM staff_appointments " +; "WHERE client_id = %s AND during && %s")] +; [client_appointments (select curs cmd2 3 week)] +; [cmd3 (+ "SELECT during FROM officehours WHERE staff_id IN " +; "(SELECT staff_id FROM staff_client_relationships " +; "WHERE client_id = %s) AND during && %s")] +; [officehours (select curs cmd3 3 week)]] +; (jsonify { "appointments" (list (map during-to-utc appointments)) +; "officehours" (list (map during-to-utc officehours)) })))) (if (= __name__ "__main__") (do diff --git a/notes/bs.md b/notes/bs.md index 111a636..8b8956b 100644 --- a/notes/bs.md +++ b/notes/bs.md @@ -27,6 +27,16 @@ Note: "BS" stands for BrainStorming. doing most of the work (including a lot of the business logic) in Postgres, just to see if I can. +## What have other people done? + + I wondered how other people solved the problem of constraint. + Google doesn't let you see more than a month at a time, but one of + its tasks is to assemble of view that may incorporate dozens of + underlying calendars. On the other hand, assuming one person had + every half-hour booked with a unique task for a ten hour day, six + days a week without breaks, that's only 6240 individual items, well + within the performant range of a tool like Backbone or React. + ## Solution requirements: * Data Store diff --git a/notes/progress.md b/notes/progress.md index 85e6112..7c238f8 100644 --- a/notes/progress.md +++ b/notes/progress.md @@ -16,7 +16,7 @@ GRANT ALL PRIVILEGES ON DATABASE officehours TO officehours; CREATE EXTENSION citext; CREATE EXTENSION btree_gist; CREATE EXTENSION plv8; - +be # What can I do? @@ -28,4 +28,4 @@ CREATE EXTENSION plv8; ## Progress: -Everything works in psycopg2. +## Retrieve "this week" with Flask. diff --git a/source/index.haml b/source/index.haml new file mode 100644 index 0000000..ce5e8de --- /dev/null +++ b/source/index.haml @@ -0,0 +1,10 @@ +!!! 5 +%html + %head + %title Appointment Calendar + %link{:href => "/static/officehours.css", :rel => "stylesheet", :type => "text/css"} + %script{:src => "static/officehours.js"} + + %body + .container +