Browse files

Added most of the support for adding a project to my projects list. I…

… still need to add the code to put the forms contents into the data store, but I'm learning as I go. I also need to put in some sort of authorization system at some point, right now anyone who uses this will be able to add projects if they want to, it is security by obscurity. On a brighter note, I'm learning a lot about how to use enlive!
  • Loading branch information...
jColeChanged committed Nov 23, 2010
1 parent 707faac commit ac7cfb229a423169a83055fd5dfca685df2ec80d
Showing with 63 additions and 15 deletions.
  1. +2 −1 project.clj
  2. +41 −6 src/mysite/core.clj
  3. +20 −8 src/mysite/projects/add.html
@@ -4,7 +4,8 @@
[org.clojure/clojure-contrib "1.2.0"]
[compojure "0.5.3"]
[ring/ring-jetty-adapter "0.3.1"]
[enlive "1.0.0-SNAPSHOT"]]
[enlive "1.0.0-SNAPSHOT"]
[pour "0.1.0"]]
:dev-dependencies [[appengine-magic "0.3.0-SNAPSHOT"]
[swank-clojure "1.2.1"]]
:namespaces [mysite.app_servlet])
@@ -1,21 +1,56 @@
(ns mysite.core
(:use compojure.core)
(:use compojure.core, ring.middleware.keyword-params, ring.middleware.params,
ring.util.response, pour.core, pour.validators)
(:require [net.cgrand.enlive-html :as html])
(:require [appengine-magic.core :as ae]))
;; Forms
(defform add-project-form
:title [required "Title is required."]
:pitch [required "Pitch is required."]
:details [required "Details are required."]
:priority [required "A priority is required."
an-integer "The priority must be an integer."])
(defn set-input
[id form]
(html/set-attr :value (str (id (:values form)))))
(defn set-error
[id form]
(html/html-content (id (:errors form))))
;; Templates
(html/deftemplate add-project "mysite/projects/add.html" [] [] [])
(html/deftemplate add-project-template "mysite/projects/add.html"
[:div#title :input] (set-input :title form-data)
[:div#title :p] (set-error :title form-data)
[:div#pitch :input] (set-input :pitch form-data)
[:div#pitch :p] (set-error :pitch form-data)
[:div#details :textarea] (html/html-content (:details (:values form-data)))
[:div#details :p] (set-error :details form-data)
[:div#priority :input] (set-input :priority form-data)
[:div#priority :p] (set-error :priority form-data))
(defn show-project
(str request))
(let [form-data (add-project-form params)]
(if (empty? (:errors form-data))
(redirect "/projects/list/")
(add-project-template form-data))))
(defroutes mysite-app-handler
(GET "/projects/add/" [] (add-project))
(POST "/projects/add/" [] show-project)
(GET "/projects/add/" [] (add-project-template 0))
(POST "/projects/add/" {params :params} (show-project params))
(GET "*" req
{:status 200
:headers {"Content-Type" "text/plain"}
:body "making changes live*"}))
(def mysite-app-handler
(-> mysite-app-handler
(ae/def-appengine-app mysite-app #'mysite-app-handler)
@@ -4,14 +4,26 @@
<h1>Add a project</h1>
<form method="POST" action="/projects/add/">
<label for="title">Title</label><br />
<input name="title" type="text"></input><br />
<label for="pitch">Pitch</label><br />
<input name="pitch" type="text"></input><br />
<label for="details">Details</label><br />
<textarea name="details" rows="10" cols="80"></textarea><br />
<label for="priority">Priority</label><br />
<input name="priority" type="text"></input><br />
<div id="title">
<label for="title">Title</label><br />
<input name="title" type="text"></input>
<p class="error"></p>
<div id="pitch">
<label for="pitch">Pitch</label><br />
<input name="pitch" type="text"></input><br />
<p class="error"></p>
<div id="details">
<label for="details">Details</label><br />
<textarea id="details" name="details" rows="10" cols="80"></textarea><br />
<p class="error"></p>
<div id="priority">
<label for="priority">Priority</label><br />
<input id="priority" name="priority" type="text"></input><br />
<p class="error"></p>
<input type="submit" value="Add project"></input>

0 comments on commit ac7cfb2

Please sign in to comment.