[Bese-devel] Date in form and clsql time elements mapping

Aashish L aashishrl at yahoo.co.in
Fri Jul 2 13:08:10 UTC 2010


Hi 
I am using stock UCW and I have difficulty in handling dates from CLSQL.
Take a look at following code, its messy, use of variables- dd,mm,yy and action- datehelper is what I want to avoid! I also refered back Boxset's form.lisp, but could not figure out how to put raw d,m,y intgers back in time element.
Help welcome!
Thanks.
~Arl

code starts:-------------
(clsql:def-view-class datetrial ()
  ((id
    :db-kind :key :type (integer 4) :initarg :id :initform 0)  
   (trydate
    :accessor trydate :type clsql:wall-time
    :initarg :trydate :initform (clsql:make-time :year 2000 :month 1 :day 1)))
  (:base-table |datetrial|))

;(clsql:create-view-from-class 'datetrial)

(defcomponent date-man ()
  ((ddate :accessor ddate :initarg :ddate :backtrack t
	  :initform (make-instance 'datetrial))))

(defcomponent get-date (date-man) 
  ())

(defmethod render ((self get-date))
  (let* ((temp (ddate self))
	 (bdate (trydate temp))
	 (dd (clsql:time-element bdate :day-of-month))
	 (mm (clsql:time-element bdate :month))
	 (yy (clsql:time-element bdate :year)))
    (<ucw:form :action (datehelper temp dd mm yy)
	       :method "post"
	       (<:table
		:border 1		
		(<:tr (<:td "date") 
		      (<:td "D :" (<ucw:select :accessor dd
					       (dotimes (x 31) 
						 (<ucw:option :value (+ 1 x) (<:as-html (+ 1 x)))))
			    " M :" (<ucw:select :accessor mm
						(dotimes (x 12) 
						  (<ucw:option :value (+ 1 x) (<:as-html (+ 1 x)))))
			    " Y :" (<ucw:select :accessor yy
						(do ((x 1950 (1+ x))) ((>= x 2020)) 
						  (<ucw:option :value x (<:as-html x)))))))
		(<:tr (<:td :colspan 2 :align "center"
			    (<:input :type "submit"))))))

(defaction datehelper ((temp datetrial) dd mm yy)
  (setf (trydate temp) (clsql:make-time :day dd
					:month mm
					:year yy))
  (answer temp))

(defaction new-date ()
  (let* ((newid (+ 1 (caar (clsql:select [max [id]] :from [|datetrial|]))))
	 (tdate (call 'get-date)))
    (progn 
      (setf (slot-value datetrial 'id) newid)      
      (clsql:update-records-from-instance tdate))))

(defentry-point "datetrial.html" (:application *date-application*);simple-application
  ()
  (new-date))
code ends:-------------






More information about the bese-devel mailing list