[★] 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/ | venv/ | ||||||
| node_modules/ | node_modules/ | ||||||
|  | static/ | ||||||
| main.py | main.py | ||||||
|  |  | ||||||
							
								
								
									
										4
									
								
								Makefile
								
								
								
								
							
							
						
						
									
										4
									
								
								Makefile
								
								
								
								
							|  | @ -1,2 +1,6 @@ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | static/%.html: source/%.haml | ||||||
|  | 	haml --unix-newlines --no-escape-attrs --double-quote-attributes $< > $@ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |  | ||||||
							
								
								
									
										47
									
								
								main.hy
								
								
								
								
							
							
						
						
									
										47
									
								
								main.hy
								
								
								
								
							|  | @ -1,6 +1,6 @@ | ||||||
| #!/usr/local/bin/hy | #!/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__)) | (def app (Flask __name__)) | ||||||
| 
 | 
 | ||||||
| (defn connect [] | (defn connect [] | ||||||
|  | @ -20,26 +20,31 @@ | ||||||
| 
 | 
 | ||||||
| ; This is purely for demonstration purposes. | ; This is purely for demonstration purposes. | ||||||
| 
 | 
 | ||||||
| (with-decorator  | (with-decorator | ||||||
|   (.route app "/")  |   (.route app "/") | ||||||
|   (defn hello []  |   (defn home [] | ||||||
|     (let [[conn (connect)] |     (send-from-directory "static" "index.html"))) | ||||||
|           [curs (.cursor conn)] | 
 | ||||||
|           [week (psycopg2.extras.DateTimeRange (datetime.datetime 2015 1 31 0 0) | ;(with-decorator  | ||||||
|                                                (datetime.datetime 2015 2 7 23 59))] | ;  (.route app "/")  | ||||||
|           [cmd1 (+ "SELECT during FROM staff_appointments WHERE staff_id IN " | ;  (defn hello []  | ||||||
|                    "(SELECT staff_id FROM staff_client_relationships " | ;    (let [[conn (connect)] | ||||||
|                    "WHERE client_id = %s) AND during && %s")] | ;          [curs (.cursor conn)] | ||||||
|           [appointments (select curs cmd1 3 week)] | ;          [week (psycopg2.extras.DateTimeRange (datetime.datetime 2015 1 31 0 0) | ||||||
|           [cmd2 (+ "SELECT during, appointment_id, client_id FROM staff_appointments " | ;                                               (datetime.datetime 2015 2 7 23 59))] | ||||||
|                    "WHERE client_id = %s AND during && %s")] | ;          [cmd1 (+ "SELECT during FROM staff_appointments WHERE staff_id IN " | ||||||
|           [client_appointments (select curs cmd2 3 week)] | ;                   "(SELECT staff_id FROM staff_client_relationships " | ||||||
|           [cmd3 (+ "SELECT during FROM officehours WHERE staff_id IN " | ;                   "WHERE client_id = %s) AND during && %s")] | ||||||
|                     "(SELECT staff_id FROM staff_client_relationships " | ;          [appointments (select curs cmd1 3 week)] | ||||||
|                     "WHERE client_id = %s) AND during && %s")] | ;          [cmd2 (+ "SELECT during, appointment_id, client_id FROM staff_appointments " | ||||||
|           [officehours (select curs cmd3 3 week)]] | ;                   "WHERE client_id = %s AND during && %s")] | ||||||
|       (jsonify { "appointments" (list (map during-to-utc appointments)) | ;          [client_appointments (select curs cmd2 3 week)] | ||||||
|                  "officehours" (list (map during-to-utc officehours)) })))) | ;          [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__") | (if (= __name__ "__main__") | ||||||
|   (do |   (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 |     doing most of the work (including a lot of the business logic) in | ||||||
|     Postgres, just to see if I can. |     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: | ## Solution requirements: | ||||||
| 
 | 
 | ||||||
|     * Data Store |     * Data Store | ||||||
|  |  | ||||||
|  | @ -16,7 +16,7 @@ GRANT ALL PRIVILEGES ON DATABASE officehours TO officehours; | ||||||
| CREATE EXTENSION citext;  | CREATE EXTENSION citext;  | ||||||
| CREATE EXTENSION btree_gist;  | CREATE EXTENSION btree_gist;  | ||||||
| CREATE EXTENSION plv8;  | CREATE EXTENSION plv8;  | ||||||
| 
 | be | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # What can I do? | # What can I do? | ||||||
|  | @ -28,4 +28,4 @@ CREATE EXTENSION plv8; | ||||||
| 
 | 
 | ||||||
| ## Progress: | ## 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