Extending standard-db-class?

Rupert Swarbrick <[email protected]>
Newsgroups gmane.lisp.clsql.general
Message-ID <[email protected]>
Hi there,

I hope this isn't a hopelessly naive question. I've been playing with
writing a hunchentoot and clsql based admin interface to a website I
administer. The current admin interface (in php) has quite a few pages
that are basically views of database tables (there aren't many rows -
it's one row per committee member, for example).

Since the first iteration of my design is basically to copy the end
result of the php version and check it works, I thought it would be
sensible to render as an editable HTML table classes defined by
def-view-class.

While this works, I'd like to do stuff like say "this column should be
immutable" (the original author of a news posting, say) or "this column
shouldn't show up" (id columns or auxiliary info that no user cares
about). Thinking about it, I realised that what I really wanted to do
was to add some more slot options to def-view-class...

Is the following code the right way to (start to) go about it? I'm a
little wary of all the ::'s required. I take it there isn't an exported
interface for doing something like this?

Rupert

;;; A CLSQL-based metaclass that allows you to specify which slots should be
;;; shown in an editing based view.

(defclass tableable-db-class (clsql-sys::standard-db-class)
  ())

(defclass tableable-view-class-slot-mixin ()
  ((visible
    :accessor db-class-slot-visible
    :initarg :visible
    :documentation "Whether this slot is visible when rendered as a DB table
with an HTML view.")))

(defclass tableable-view-class-direct-slot-definition
    (tableable-view-class-slot-mixin
     clsql-sys::view-class-direct-slot-definition)
  ())

(defclass tableable-view-class-effective-slot-definition
    (tableable-view-class-slot-mixin
     clsql-sys::view-class-effective-slot-definition)
  ())

(defmethod sb-mop:direct-slot-definition-class ((class tableable-db-class)
                                                &rest initargs)
  (declare (ignore initargs))
  (find-class 'tableable-view-class-direct-slot-definition))

(defmethod sb-mop:effective-slot-definition-class ((class tableable-db-class)
                                                   &rest initargs)
  (declare (ignore initargs))
  (find-class 'tableable-view-class-effective-slot-definition))

(defmacro def-tableable-view-class (class supers slots &rest cl-options)
  `(clsql:def-view-class
       ,class ,supers ,slots
       ;; Nicked the following from clsql ooddl.lisp
       ,@(if (find :metaclass `,cl-options :key #'car)
             `,cl-options
             (cons '(:metaclass tableable-db-class) `,cl-options))))

_______________________________________________
CLSQL mailing list
[email protected]
http://lists.b9.com/cgi-bin/mailman/listinfo/clsql
signature.asc (application/pgp-signature, 314 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iJwEAQECAAYFAkqdl3IACgkQRtd/pJbYVoZxhwP9GNwH2gzrGXQ1qH2x+neOjwah
2gWJxkHd0zbd718FEwcdvn96j8OT7dSeeSLQfcpZ5u2Ry8RChfXF4FXS8EaZs2B6
UD6RfqMYPLWe661rYBxMdYelNBaoAY0Q302LAbwaHmQcP8h+jvNv6BnsvmksOxL8
39dsOLmh30mz62jqigQ=
=5GW4
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.