summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2009-12-02 13:48:17 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2009-12-02 13:48:17 +0100
commit44eb990b475ca835b4720bf0521d4159b21b9508 (patch)
tree2d2e183605ec5ad76133c4bf6b59d444afd34d56 /src
parent6aadd1b6f2237511e1b853327136e892ec4ef0c0 (diff)
Add a button for sending the database as mail to all users.
Diffstat (limited to 'src')
-rw-r--r--src/logikorr/servlet.clj46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/logikorr/servlet.clj b/src/logikorr/servlet.clj
index 10ef5d5..31b6ef7 100644
--- a/src/logikorr/servlet.clj
+++ b/src/logikorr/servlet.clj
@@ -4,7 +4,10 @@
(:require [appengine-clj.datastore :as ds]
[org.danlarkin.json :as json])
(:import [com.google.appengine.api.datastore DatastoreServiceFactory Entity Query Query$FilterOperator Query$SortDirection KeyFactory EntityNotFoundException Key]
- [com.google.appengine.api.users UserServiceFactory]))
+ [com.google.appengine.api.users UserServiceFactory]
+ [java.util Properties]
+ [javax.mail Message Message$RecipientType MessagingException Session Transport]
+ [javax.mail.internet AddressException InternetAddress MimeMessage MimeMultipart MimeUtility MimeBodyPart]))
(defmacro with-ds-transaction [& body]
`(call-with-ds-transaction (fn [] ~@body)))
@@ -86,6 +89,8 @@
[:h2 "Neue Ergebnisse"]
[:form [:button#make-revision {:type "button"} "Aktuelle Version sichern"]
[:div#new-version-label {:style "display: inline; color: #070"}]]
+ [:form [:button#send-mail {:type "button"} "Datei an die Korrektoren schicken"]
+ [:div#mail-sent-label {:style "display: inline; color: #070"}]]
[:table#ergebnisse]
[:h2 "Bestehende Ergebnisse"]
[:table
@@ -186,6 +191,44 @@
(:key (current-revision))))
(recur (rest (rest lines)))))))))
+(defn encode-database-file []
+ (with-out-str
+ (let [students (find-students)]
+ (doseq [student students]
+ (printf "%s\n" (unsplit-name (:first-name student) (:last-name student)))
+ (printf "(")
+ (doseq [score (:score student)]
+ (printf "%-3s " (str score)))
+ (printf ")\n\n")))))
+
+(defn send-mail []
+ (let [props (Properties.)
+ session (Session/getDefaultInstance props nil)
+ message (MimeMessage. session)
+ users (ds/find-all (Query. "user"))]
+ (doseq [user users]
+ (.addRecipient message
+ Message$RecipientType/TO
+ (InternetAddress. (:email user) (:email user))))
+ (doto message
+ (.setFrom (InternetAddress. "mulkiatsch@gmail.com" "Logikorr"))
+ (.setSubject "Logik-Korrekturergebnisse")
+ (.setContent
+ (doto (MimeMultipart.)
+ (.addBodyPart (doto (MimeBodyPart.)
+ (.setText "Anbei die jüngsten Korrekturergebnisse.
+
+Automatisch erzeugte Grüße,
+Logikorr")))
+ (.addBodyPart (doto (MimeBodyPart.)
+ ;;(.setText (encode-database-file))
+ (.setContent (encode-database-file) "text/plain")
+ ;; (.setDataHandler (doto (DataSource.)
+ ;; ()))
+ (.setFileName "logik.txt")
+ (.setDisposition "attachment"))))))
+ (Transport/send message)))
+
(defmacro with-authentication [& body]
`(call-with-authentication (fn [] ~@body)))
@@ -196,6 +239,7 @@
(GET "/find-student" (with-authentication (find-student-json (:name params))))
(GET "/update-student-score" (with-authentication (update-student-score (:id params) (:score-number params) (:score params))))
(GET "/make-new-revision" (with-authentication (make-new-revision)))
+ (GET "/send-mail" (with-authentication (send-mail)))
(POST "/import-score-file" (with-authentication
(import-score-file (:file-data params))
(redirect-to "/")))