diff --git a/src/utils.lisp b/src/utils.lisp index cdbf63a..0e9cd9a 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -1,21 +1,21 @@ +(in-package #:cl-user) (defpackage #:utils (:use #:cl + #:caveman2 #:log4cl) - (:export #:format-date - #:i18n-load + (:export #:i18n-load #:_ #:parse-iso-date #:request-params - #:string-is-nil-or-empty-p - #:separate-files-in-web-request) + #:string-is-nil-or-empty? + #:separate-files-in-web-request + #:set-alert + #:get-alert + #:get-and-reset-alert) (:documentation "Utilities that do not depend on models.")) (in-package #:utils) -(defun format-date (date) - "Format the given date with the default date format (yyyy-mm-dd). Return a string." - (local-time:format-timestring nil date :format +date-y-m-d+)) - (defun asciify (string) (str:downcase (slug:asciify string))) @@ -25,7 +25,7 @@ (read-from-string key)) :collect value)) -(defun string-is-nil-or-empty-p (string-to-test) +(defun string-is-nil-or-empty? (string-to-test) "Tests to see if `STRING-TO-TEST' is empty of just whitespace. This is essentially the 'IsNullOrWhiteSpace' function I use in C#. It expands the 'empty string' check to include a check to see if there is @@ -46,3 +46,19 @@ name. Just specify it in this function's `REQUEST-VALUE' argument." if (or (string= "CONTENT-FILES" (car item)) (string= request-value (car item))) collect item)) + +(defun set-alert (message) + "Sets the alert `MESSAGE' stored in session, provide info. to users. +The intention is store a `MESSAGE' across a redirect during a HTTP +POST request." + (setf (gethash :alert ningle:*session*) message)) + +(defun get-alert () + "Get alert message from session data." + (gethash :alert ningle:*session*)) + +(defun get-and-reset-alert () + "Returns the `ALERT' message and clears its content from the session hash." + (let ((message (get-alert))) + (set-alert nil) + message))