Browse Source

add bool to checkbox convertion funcitons to utils pacakge.

The functions are helper functions for when dealing with
SQLite3. Because SQLite3 doesn't have a Boolean data-type, I have to
store the 'true' and 'false' values as integetes.

0 == false
1 == true.
stable
Craig Oates 2 years ago
parent
commit
177521aa34
  1. 26
      src/utils.lisp

26
src/utils.lisp

@ -2,7 +2,8 @@
(defpackage #:utils
(:use #:cl
#:caveman2
#:log4cl)
#:log4cl
#:app-constants)
(:export #:i18n-load
#:_
#:parse-iso-date
@ -11,7 +12,9 @@
#:separate-files-in-web-request
#:set-alert
#:get-alert
#:get-and-reset-alert)
#:get-and-reset-alert
#:bool-to-checkbox
#:checkbox-to-bool)
(:documentation "Utilities that do not depend on models."))
(in-package #:utils)
@ -62,3 +65,22 @@ POST request."
(let ((message (get-alert)))
(set-alert nil)
message))
(defun bool-to-checkbox (value)
"Converts `VALUE' so it can populate an HTML checkbox.
It is assumed you are converting a SQLite version of a Boolean so
either 1 (true) or 0 (false). If you need a traditional Boolean value,
DO NOT USE THIS FUNCTION."
(cond ((= value 0) "off")
((null value) "off")
(t "on")))
(defun checkbox-to-bool (value)
"Converts a HTML Checkbox `VALUE' to a Boolean.
The `VALUE' will either be 'on' or 'off'. 'Boolean' in this instance
is assuming you are using SQLite and need to convert `VALUE' to an
integer/number. If you are needing a traditional Boolean value, DO NOT USE
THIS FUNCTION."
(cond ((string= "checked" value) +true+)
((string= "off" value) +false+)
((null value) +false+)))

Loading…
Cancel
Save