Browse Source

Continued the define-form macro

Samuel W. Flint 9 years ago
parent
commit
19d288443a
1 changed files with 18 additions and 3 deletions
  1. 18 3
      collect.lisp

+ 18 - 3
collect.lisp

@@ -193,7 +193,7 @@
                       (collect `(post-parameter ,field)))))
     `(execute-non-query *db* ,actual-query ,@fields)))
 
-(defmacro define-form (name table (&rest fields) &key &allow-other-keys)
+(defmacro define-form (name table (&rest fields) &key (title name) (description title) &allow-other-keys)
   (let* ((columns (map 'list #'second fields))
          (field-names (map 'list #'(lambda (column)
                                      (concatenate 'string "fld_" column))
@@ -203,5 +203,20 @@
          (route-name (intern (string-upcase name)))
          (route-name-post (intern (string-upcase (concatenate 'string name "-post")))))
     `(progn
-       (define-route ,route-name (,name))
-       (define-route ,route-name-post (,name :method :post)))))
+       (define-route ,route-name (,name)
+         (with-html-output-to-string (out)
+           (:html
+               (:head (:title ,title)
+                 (:link :rel "style_sheet" :href (genurl 'main-css)))
+             (:body (:div :class "nav")
+               (:div :class "main-content"
+                     (:h1 ,title)
+                     (:p ,description)
+                     (:form :action (genurl ',route-name-post)
+                            :method :post
+                            (:table ,@form-entries
+                              (:tr (:td)
+                                (:td (:input :type :submit :value "Submit"))))))))))
+       (define-route ,route-name-post (,name :method :post)
+         ,update-query
+         (redirect ',route-name)))))