0001-api-don-t-get-list-of-formdefs-once-per-category-900.patch
wcs/api.py | ||
---|---|---|
257 | 257 |
def __init__(self, category=None): |
258 | 258 |
self.category = category |
259 | 259 | |
260 |
def get_list_forms(self, user, list_all_forms=False): |
|
260 |
def get_list_forms(self, user, list_all_forms=False, formdefs=None):
|
|
261 | 261 |
list_forms = [] |
262 |
if formdefs is None: |
|
263 |
formdefs = FormDef.select(order_by='name', ignore_errors=True) |
|
264 | ||
265 |
formdefs = [x for x in formdefs if not x.is_disabled() or x.disabled_redirection] |
|
266 | ||
262 | 267 |
if self.category: |
263 |
formdefs = FormDef.select(lambda x: ( |
|
264 |
str(x.category_id) == str(self.category.id) and ( |
|
265 |
not x.is_disabled() or x.disabled_redirection)), |
|
266 |
order_by = 'name') |
|
267 |
else: |
|
268 |
formdefs = FormDef.select(lambda x: not x.is_disabled() or x.disabled_redirection, |
|
269 |
order_by='name', |
|
270 |
ignore_errors=True) |
|
268 |
formdefs = [x for x in formdefs if str(x.category_id) == str(self.category.id)] |
|
271 | 269 | |
272 | 270 |
charset = get_publisher().site_charset |
273 | 271 | |
... | ... | |
372 | 370 |
charset = get_publisher().site_charset |
373 | 371 |
categories = Category.select() |
374 | 372 |
Category.sort_by_position(categories) |
373 |
all_formdefs = FormDef.select(order_by='name', ignore_errors=True) |
|
375 | 374 |
for category in categories: |
376 | 375 |
d = {} |
377 | 376 |
d['title'] = unicode(category.name, charset) |
... | ... | |
379 | 378 |
d['url'] = category.get_url() |
380 | 379 |
if category.description: |
381 | 380 |
d['description'] = unicode(category.description, charset) |
382 |
formdefs = ApiFormdefsDirectory(category).get_list_forms(user) |
|
381 |
formdefs = ApiFormdefsDirectory(category).get_list_forms(user, |
|
382 |
formdefs=all_formdefs) |
|
383 | 383 |
if not formdefs: |
384 | 384 |
# don't advertise empty categories |
385 | 385 |
continue |
386 |
- |