From 5d8009bf3193c0e35789ba55984e47512e4607ed Mon Sep 17 00:00:00 2001 From: "Elf M. Sternberg" Date: Sat, 13 Feb 2016 09:13:25 -0800 Subject: [PATCH] =?UTF-8?q?[=E2=98=85]=20Acheivement=20Unlocked:=20Serving?= =?UTF-8?q?=20static=20content=20with=20Flask.=20[=E2=98=85]=20Acheivement?= =?UTF-8?q?=20Unlocked:=20Generating=20static=20content=20from=20HAML.=20[?= =?UTF-8?q?=E2=98=85]=20Achievement=20Unlocked:=20Building=20HAML=20from?= =?UTF-8?q?=20a=20Makefile.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I used to use Cakefiles for this sort of thing. Man, I was an idiot once upon a time. Cake and Grunt and Gulp and all the rest are task runners, not dependency managers, and will Rebuild The World every time. --- .gitignore | 1 + Makefile | 4 ++++ main.hy | 47 ++++++++++++++++++++++++++--------------------- notes/bs.md | 10 ++++++++++ notes/progress.md | 4 ++-- source/index.haml | 10 ++++++++++ 6 files changed, 53 insertions(+), 23 deletions(-) create mode 100644 source/index.haml 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 +