[★] Acheivement Unlocked: Serving static content with Flask.
[★] Acheivement Unlocked: Generating static content from HAML. [★] Achievement Unlocked: Building HAML from a Makefile. 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.
This commit is contained in:
parent
6157bf07ea
commit
5d8009bf31
|
@ -4,4 +4,5 @@
|
|||
*~
|
||||
venv/
|
||||
node_modules/
|
||||
static/
|
||||
main.py
|
||||
|
|
4
Makefile
4
Makefile
|
@ -1,2 +1,6 @@
|
|||
|
||||
|
||||
static/%.html: source/%.haml
|
||||
haml --unix-newlines --no-escape-attrs --double-quote-attributes $< > $@
|
||||
|
||||
|
||||
|
|
43
main.hy
43
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 []
|
||||
|
@ -22,24 +22,29 @@
|
|||
|
||||
(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)) }))))
|
||||
(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
|
||||
|
|
10
notes/bs.md
10
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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
Loading…
Reference in New Issue