Sorting and modifying fields in views?

2 views
Skip to first unread message

petter

unread,
Nov 30, 2009, 2:53:15 PM11/30/09
to weblocks
What is the correct syntax for specifying the intital ordering of a
field? I've tried:

(defview some-table-view (:type table :inherit-from '(:scaffold some))
(field :order-by '(some field :desc))

But it does not seem to work.

Also what is the prefered method of showing something which is not an
actual field in the database?

I have starttime and endtime in my db, but I would rather present the
starttime and the duration rather than endtime. I can make a duration
field and specify a reader or use the same reader for the endtime
field. In either case I seem to get problems when the user is trying
to sort using the field (the first will get a nil db field, the latter
will sort by endtime rather than duration). Or do I have to create
extra fields containing redudant information in my database?

Leslie P. Polzer

unread,
Nov 30, 2009, 3:55:10 PM11/30/09
to weblocks
On Nov 30, 8:53 pm, petter <petter.gus...@gmail.com> wrote:

> (defview some-table-view (:type table :inherit-from '(:scaffold some))
>   (field :order-by '(some field :desc))
>
> But it does not seem to work.

There's no such argument right now, see
http://viridian-project.de/~sky/user-guide.stx.html#Syntax.of.declarative.view.declaration
for a list of the
ones available.


> Also what is the prefered method of showing something which is not an
> actual field in the database?
>
> I have starttime and endtime in my db, but I would rather present the
> starttime and the duration rather than endtime. I can make a duration
> field and specify a reader or use the same reader for the endtime
> field. In either case I seem to get problems when the user is trying
> to sort using the field (the first will get a nil db field, the latter
> will sort by endtime rather than duration).

Yes, virtual fields (i.e. those with custom readers) don't benefit
from
sorting right now. This is a missing feature.


> Or do I have to create extra fields containing redudant information in
> my database?

That would be a way to kludge around it. Why not create a view, in
case
you're using SQL?

Leslie

petter

unread,
Nov 30, 2009, 4:10:56 PM11/30/09
to weblocks
Thank you for a prompt reply and great work!
I'll try that.

Petter

nunb

unread,
Dec 1, 2009, 3:52:12 AM12/1/09
to weblocks
Sorting (afaik) depends quite heavily on the query-fn and hence the
store. I posted a make-query-fn to the pastebin a while back..

The kludge I use is: http://paste.lisp.org/+1YH1 and there's an
annotation for composite/linked objects, though it may not be
applicable to SQL stores, I use cl-prevalence.

It all depends on how the value for that slot is obtained, again iirc,
weblocks funcalls the view field slot name if there is no slot with
that exact name, so that's why the kludge works (Leslie can correct me
here).

Using custom readers, writers and presenters (as well as view field
names which are functions) yields quite a bit of flexibility.

Leslie P. Polzer

unread,
Dec 1, 2009, 5:14:05 AM12/1/09
to webl...@googlegroups.com

nunb wrote:

> It all depends on how the value for that slot is obtained, again iirc,
> weblocks funcalls the view field slot name if there is no slot with
> that exact name, so that's why the kludge works (Leslie can correct me
> here).

The default behavior is to call SLOT-VALUE on the field name.


> Using custom readers, writers and presenters (as well as view field
> names which are functions) yields quite a bit of flexibility.

Fortunately, yeah. But I'm worried about the kludgy nature of all
this and would like to see proper solutions for the most common
cases eventually...

Leslie

petter

unread,
Dec 2, 2009, 12:06:16 PM12/2/09
to weblocks
I added some views which made things much simpler, but still the data
is not sorted correctly, even though I have an order by statement in
my view definition. If I do a select * from my_view limit 5 I do get
the correct order from the database itself. Is there an easy way to
print the SQL sent to the server?

Petter

Leslie P. Polzer

unread,
Dec 2, 2009, 12:10:42 PM12/2/09
to webl...@googlegroups.com

petter wrote:

> I added some views which made things much simpler, but still the data
> is not sorted correctly, even though I have an order by statement in
> my view definition. If I do a select * from my_view limit 5 I do get
> the correct order from the database itself. Is there an easy way to
> print the SQL sent to the server?

Try (trace clsql:select)

petter

unread,
Dec 2, 2009, 12:20:04 PM12/2/09
to weblocks


On Dec 2, 6:10 pm, "Leslie P. Polzer" <s...@viridian-project.de>
wrote:

> Try (trace clsql:select)

That I should have figured out by myself, shame on me...

But it appears that there is an explicit order-by there on the first
field of the view there:

:RESULT-TYPES :AUTO :ORDER-BY
((#<CLSQL-SYS:SQL-IDENT-ATTRIBUTE
REGRUN_VIEW.REVISION>
:ASC))
:OFFSET 0 :LIMIT 15 :DATABASE

Petter

petter

unread,
Dec 2, 2009, 12:35:07 PM12/2/09
to weblocks

A
:sort '(field . :desc)

when I create the widget solved the problem.

It has to be a dotted pair as specified in dataseq.lisp

Leslie P. Polzer

unread,
Dec 2, 2009, 12:35:15 PM12/2/09
to weblocks
On Dec 2, 6:20 pm, petter <petter.gus...@gmail.com> wrote:

> But it appears that there is an explicit order-by there on the first
> field of the view there:

Alright, the code in find-persistent-objects is this:

(select class-name
:order-by (order-by-expression class-name order-by)
...)

class-name and order-by are part of f-p-o's lambda list.

You'll have to find some way to tell f-p-o to pass the correct sorting
clause.
Hint: if order-by is nil the whole sorting clause should be omitted
from the query.

Does that help?

Leslie

petter

unread,
Dec 2, 2009, 12:58:21 PM12/2/09
to weblocks

As I said in my previous message the :sort key solved my problem.
Thank you for your help.
Reply all
Reply to author
Forward
0 new messages