Search class:
class Search util.Search:
T = current.T
categories = {
"a": [
T("Abattoirs"),
T("Accountants"),
T("Administration Services"),
T("Adventure Activity"),
T("Advertising-Point of Sale"),
T("Agricultural Contractors"),
T("Agricultural Merchants"),
T("Agricultural Supplies"),
T("Air Conditioning"),
T("Ambulance Service"),
T("Amusement Centres/Leisure Attractions"),
T("Animal Supplies"),
T("Animal Welfare Societies"),
T("Antique Dealers"),
T("Antique Repair & Restoration"),
T("Architects"),
T("Architectural Technologists & Technicians"),
T("Aromatherapy"),
T("Art & Craft Eqpt & Materials"),
T("Art & Craft Shops"),
T("Assessors"),
T("Auctioneers & Valuers"),
],
# add more keywords
}
@classmethod
def get_category(cls, section):
return Search.categories[section]
controller:
def index():
curr_page='index'
from util import Search
if request.vars['search']:
categories = Search.get_category(request.vars['search'])
else:
categories = Search.get_category('a')
search = request.vars.get('search')
if not search:
search = "a"
return dict(search=search, categories=categories)
view index.html:
{{
import string
search_links = []
for letter in string.ascii_letters:
search_links.append(
LI(A(T(letter), _href=URL('directory', '?search='+letter+'&type=category'),
_class=('active' if letter == search_term else '')))
)
pass
}}
{{=OL(
search_links,
_id='manual-search'
)
}}
{{
cat_options = []
for index, category in enumerate(categories):
cat_options.append(
LI(A(SPAN(category),
_href=URL('directory','business_listing',args=[search_term, index])))
)
pass
}}
{{=UL(
cat_options,
_id='category-listing'
)
}}
On Sun, Mar 4, 2012 at 7:07 AM, Anthony <[email protected]> wrote:
> In the view, maybe something like:
>
> {{import string}}
> {{for browse_type in ['category', 'listing', 'locality', 'brand']:}}
> {{=CAT('Browse by ', browse_type, ' ',
> *[A(letter, _href=URL('default', 'browse', args=[browse_type,
> letter]))
> for letter in string.uppercase])}}
> {{pass}}
>
> That will generate a set of links like /yourapp/default/browse/category/A,
> etc. Of course, you'll have to fill out the HTML a little more to get the
> exact format/layout you want -- the above is just an example of how to
> generate the links.
>
> Then in the controller:
>
> def browse():
> if len(request.args) < 2:
> redirect(URL('default', 'somewhere'))
> [code to generate items to browse based on browse type and letter]
>
> Note, request.args(0) will contain the browse type (i.e., "category",
> "listing", etc.), and request.args(1) will contain the letter (i.e., "A",
> "B", etc.). You can use those values to generate the appropriate query,
> which will depend on how you have structured your data.
>
> If some of the letters won't have any items, you might consider removing
> those links or making them inactive. This will require a database query
> before generating the pagination links so you know which links to show/make
> active -- to minimize db hits, you should probably cache that query for
> some time (or better yet, cache the complete pagination HTML).
>
> Anthony
>
> On Sunday, March 4, 2012 2:03:03 AM UTC-5, Praveen Bhat wrote:
>>
>> Hello,
>>
>> I have a Listings page for Businesses and I want a Alphabetical
>> pagination/menu like in the attached screenshot.
>>
>> Any help will be appreciated.
>>
>>
>> Regards
>> Praveen
>>
>
--
--
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.warplydesigned.com
http://www.fitnessfriendsfinder.com