Google Groups Home
Help | Sign in
Sorted list with options for use with SingleSelectField
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Cecil Westerhof  
View profile
 More options May 12, 10:02 pm
From: "Cecil Westerhof" <cldwester...@gmail.com>
Date: Tue, 13 May 2008 04:02:34 +0200
Local: Mon, May 12 2008 10:02 pm
Subject: Sorted list with options for use with SingleSelectField
I defined the folowing function:
#####
def getOptions(label, table):
    return [(-1, 'Select %s' % (label))] +\
        sorted([(entry.id, str(entry)) for entry in table.select()],
               key = operator.itemgetter(1))
#####

I can be used with:
#####
    owner          = SingleSelectField(label     = ownerLabel,
                                       options   = getOptions(ownerLabel, Owner)
                                       default   = 1)
#####

In this way the select field starts with an entry that tells to select
a value. And after that it has on ordered list off all the values of
the foreign key.
I hope it is usefull for someone.

--
Cecil Westerhof


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Cecil Westerhof  
View profile
 More options May 12, 11:03 pm
From: "Cecil Westerhof" <cldwester...@gmail.com>
Date: Tue, 13 May 2008 05:03:49 +0200
Local: Mon, May 12 2008 11:03 pm
Subject: Re: Sorted list with options for use with SingleSelectField
2008/5/13 Cecil Westerhof <cldwester...@gmail.com>:

> I defined the folowing function:
>  #####
>  def getOptions(label, table):
>     return [(-1, 'Select %s' % (label))] +\
>         sorted([(entry.id, str(entry)) for entry in table.select()],
>                key = operator.itemgetter(1))
>  #####

A sligthy better version:
#####
def cmpOptions(a, b):
    temp1 = a[1].lower()
    temp2 = b[1].lower()
    if temp1 < temp2:
        return -1
    if temp1 > temp2:
        return 1
    return 0

def getOptions(label, table):
    options = [(entry.id, str(entry)) for entry in table.select()]
    options.sort(cmpOptions)
    return [(-1, 'Selecteer %s' % (label))] + options
#####

Now dummy comes before Test.

--
Cecil Westerhof


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google