On Mon, 13 Nov 2006 19:04:19 -0600, Jeremy Dunck wrote:
> On 11/13/06, Patrick <[EMAIL PROTECTED]> wrote:
>> I'd appreciate your informative answers and am
>> looking forward to getting familiar with this part of the framework.
>
> Can you show the code that's storing the cached info? There are
> several ways to get data into and out of the cache (all documented
> here http://www.djangoproject.com/documentation/cache/ ) and the
> answer depends on what you're using. :)
>
>
Here is the view function I'm caching (the cache_page function call at the
bottom):
def pagelist_by_group(request, group, page):
"""Retrive paginated list of items by pub group"""
if not page:
page = request.GET.get('page', 1)
page = int(page)
limit = 30
# connect to UDB (3rd party XML database)
udb = UDB(UDB_URL)
# get http response from UDB
resp = udb.getResponse(udb.request("read", method = "free", base =
'%s' % group,
limit = '%s:%s' % (limit, page * limit), lang =
request.LANGUAGE_CODE, sort = '-showdate', options = 'total',
query = "language = '%s' and entry = 'item'" %
request.LANGUAGE_CODE)
)
# get total count of entries
total = resp.getAttribute('total')
if total:
total, pages = int(total), int(total)/limit
# find out if we have the previous pagelist has_previous_page = page >
1
# find out if we have the next pagelist
has_next_page = page <= pages
# parse the response into dictionary of entries
entries = udb.parseEntries(resp)
# create an empty list of entries and populate it with items
entry_list = []
for key, value in entries.items():
item = Item(key,
value['pubno'],
value['title'],
value['subtitle'],
value['author'],
value['pubdate'],
value['showdate'],
value.get('modified'),
value['classification'])
entry_list.append(item)
# get the list of publication groups from DB
pubgroup_list = PubGroup.objects.filter(is_approved = True
).filter(purpose__exact = 'resource'
).filter(language__exact = request.LANGUAGE_CODE
).order_by('name')
# render it to response
return render_to_response('publications/pubgroup_list.html',
context_instance = RequestContext(request, {
'object_list': entry_list,
'is_paginated': pages > 1,
'results_per_page': limit,
'has_next': has_next_page,
'has_previous': has_previous_page,
'page': page,
'next': page + 1,
'previous': page - 1,
'pages': pages,
'hits' : total,
'pubgroup': group,
'pubgroup_list': pubgroup_list,
'designation_list': DESIGNATION,
})
)
pagelist_by_group = cache_page(pagelist_by_group, 60 * 15)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---