diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2009-11-20 23:51:39 +0100 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2009-11-20 23:51:39 +0100 |
commit | 3772b960e369b3614968e869896192dee77a1902 (patch) | |
tree | 935febe9fe2d6fc8cd55520958564eb5366d706c | |
parent | 25267f2c6f36a6c17c45c7e94a05ad5770d74fe2 (diff) |
Save changes made by the user to the database.
-rw-r--r-- | logikorr.lisp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/logikorr.lisp b/logikorr.lisp index 761d391..7ec11bd 100644 --- a/logikorr.lisp +++ b/logikorr.lisp @@ -12,6 +12,8 @@ (defvar *database* #p"/Users/mulk/Dropbox/Projekte/Logikorr/blatt3.txt") (defvar *lock* (merge-pathnames #p".mulk-db-lock" *database*)) +(defvar *students* nil) + (defparameter *in-locked-context-p* nil) #+(or) @@ -205,14 +207,22 @@ div.autocomplete ul li { (setf (elt (student-score student) index) (let ((*read-eval* nil)) (let ((score (read-from-string score))) - (check-type score number)))))) + (check-type score number) + score)))) + (write-database)) "\"OK\"") -(define-easy-handler (add-student-score :uri "/add-student-score") - (id) - (let ((student (find-student-by-id (parse-integer id)))) - (vector-push-extend 0 (student-score student)) - (1- (length (student-score student))))) +(defun write-database () + (with-data-lock () + (unless *students* + (return-from write-database)) + (with-open-file (out *database* :external-format :utf-8 :direction :output :if-exists :new-version #+(or) :supersede) + (dolist (student *students*) + (if (student-last-name student) + (format out "~&~A, ~A" (student-last-name student) (student-first-name student)) + (format out "~&~A" (student-first-name student))) + (format out "~&~A" (coerce (student-score student) 'list)) + (format out "~%~%"))))) (defun start-logikorr () (start (make-instance 'acceptor :port 8080))) |