Skip to content

Commit

Permalink
Merge commit 'v0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
dbyrne committed May 17, 2011
2 parents 2735985 + 20e5cc2 commit 1ca94b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion project.clj
@@ -1,4 +1,4 @@
(defproject foreclojure "0.3.0"
(defproject foreclojure "0.3.1"
:description "4clojure - a website for lisp beginners"
:dependencies [[org.clojure/clojure "1.2.1"]
[org.clojure/clojure-contrib "1.2.0"]
Expand Down
22 changes: 13 additions & 9 deletions src/foreclojure/problems.clj
Expand Up @@ -285,26 +285,28 @@

(def-page problem-submission-page []
[:div.instructions
[:p "Thanks for choosing to submit a problem. Please make sure that you own the rights to the code you are submitting and that you wouldn't mind having us use the code as a 4clojure problem."]]
[:p "Thanks for choosing to submit a problem. Please make sure that you own the rights to the code you are submitting and that you wouldn't mind having us use the code as a 4clojure problem. Once you've submitted your problem, it won't appear on the site until someone from the 4clojure team has had a chance to review it."]]
(form-to {:id "problem-submission"} [:post "/problems/submit"]
(hidden-field :author (session/flash-get :author))
(hidden-field :prob-id (session/flash-get :prob-id))
(label :title "Problem Title")
(text-field :title (session/flash-get :title))
(label :tags "Tags (space separated)")
(text-field :tags (session/flash-get :tags))
(label :restricted "Restricted Functions (space separated)")
(text-field :restricted (session/flash-get :restricted))
(label :description "Problem Description")
(text-area {:id "problem-description"} :description (session/flash-get :description))
[:br]
(label :code-box "Problem test cases. Use two underscores (__) for user input. Multiple tests ought to be on one line each.")
(label :code-box "Problem test cases. Use two underscores (__) for user input. Individual tests can span multiple lines, but each test should be separated by a totally blank line.")
(text-area {:id "code-box" :spellcheck "false"}
:code (session/flash-get :tests))
[:p
[:button.large {:id "run-button" :type "submit"} "Submit"]]))

(defn create-problem
"create a user submitted problem"
[title tags description code id author]
[title tags restricted description code id author]
(let [user (session/session-get :user)]
(if (can-submit? user)
(let [prob-id (or id
Expand All @@ -319,21 +321,23 @@
:title title
:times-solved 0
:description description
:tags (s/split tags #"\s+")
:tests (s/split-lines code)
:tags (re-seq #"\S+" tags)
:restricted (re-seq #"\S+" restricted)
:tests (s/split code #"\r\n\r\n")
:user (if (empty? author) user author)
:approved false})
(flash-msg "Thank you for submitting a problem! Be sure to check back to see it posted." "/problems"))
(flash-error "You are not authorized to submit a problem." "/problems"))))

(defn edit-problem [id]
(let [{:keys [title user tags description tests]} (get-problem id)]
(let [{:keys [title user tags restricted description tests]} (get-problem id)]
(doseq [[k v] {:prob-id id
:author user
:title title
:tags (s/join " " tags)
:restricted (s/join " " restricted)
:description description
:tests (s/join "\n" tests)}]
:tests (s/join "\r\n\r\n" tests)}]
(session/flash-put! k v))
(response/redirect "/problems/submit")))

Expand Down Expand Up @@ -373,8 +377,8 @@
(GET "/problems" [] (problem-page))
(GET "/problem/:id" [id] (code-box id))
(GET "/problems/submit" [] (problem-submission-page))
(POST "/problems/submit" [prob-id author title tags description code]
(create-problem title tags description code (when (not= "" prob-id) (Integer. prob-id)) author))
(POST "/problems/submit" [prob-id author title tags restricted description code]
(create-problem title tags restricted description code (when (not= "" prob-id) (Integer. prob-id)) author))
(GET "/problems/unapproved" [] (unapproved-problems))
(POST "/problem/edit" [id]
(edit-problem (Integer. id)))
Expand Down

0 comments on commit 1ca94b5

Please sign in to comment.