From 0e3178239303a4c893ce4d246ad789532f174776 Mon Sep 17 00:00:00 2001 From: Maciej Pasternacki Date: Tue, 21 Oct 2008 17:26:07 +0200 Subject: [PATCH] - slugs --- src/common.lisp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/common.lisp b/src/common.lisp index fa7af39..dee9ee2 100644 --- a/src/common.lisp +++ b/src/common.lisp @@ -7,7 +7,7 @@ ;; Package for internal use in libraries and projects (defpackage #:trane-common (:use #:common-lisp) ; referenced with package name: #:py-configparser - (:export #:id + (:export #:id #:slug #:slug-dao #:*config* #:*init-functions* #:on-init #:*setup-functions* #:on-setup #:*db* #:make-keyword #:named-lambda #:random-string)) @@ -19,7 +19,7 @@ (in-package #:trane-common) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;; Numerical IDs of database objects +;;; Common access methods for database objects (defgeneric id (object) (:documentation "Numeric ID or :NULL for DAOs and, if it makes sense, other objects. @@ -37,6 +37,13 @@ Usually it will be a reader method automatically defined for ID column of a DAO. (defmethod id ((n string)) (parse-integer n :junk-allowed t)) +(defgeneric slug (object) + (:documentation "Get short, unique, urlified name of OBJECT.")) + +(defun slug-dao (class slug) + "Select DAO of CLASS having \"slug\" column set to SLUG." + (first (postmodern:select-dao class (:= 'slug slug)))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Initialization and setup protocol -- 2.11.4.GIT