def GET(self, catslug, pgno=1): cat = get_category_by_slug(catslug) pagination = Pagination(info_record_query2(cat.id), info_count_query2(cat.id), pgno) qs = pagination.queryset entities = qs.all() # import pdb # pdb.set_trace() category_ancestors = get_category_ancestors(cat) req = web.ctx.req req.update( { "entities": entities, "category_ancestors": category_ancestors, "thecat": cat, "pagination": pagination, "get_latest_entities": get_latest_entities, } ) template = cat.template and cat.template.list_file or None if not template or not template_exist(template): template = web.config.default_category_list return info_render.render(template, **req)
def GET(self, slug): cat = get_category_by_slug(slug) req = web.ctx.req req.update({"thecat": cat, "get_latest_entities": get_latest_entities, "get_entity": get_entity}) template = cat.template and cat.template.index_file or None # if template: # web.debug("111 cat:%s 's template:%s" % (cat.slug, template)) if not template or not template_exist(template): template = web.config.default_category_index # if template: # web.debug("222 cat:%s 's template:%s" % (cat.slug, template)) return info_render.render(template, **req)
def POST(self): form = category_form() valid = form.validates() is_unique_slug = get_category_by_slug(form.d.slug) is None if not valid or not is_unique_slug: if not is_unique_slug: form.slug.note = u"%s已存在,请重新指定。" % (form.d.slug) categories = category_tree() templates = get_templates() req = web.ctx.req req.update({ 'form': form, 'categories': categories, 'templates': templates, }) return admin_render.category_edit(**req) new_category(form.d) raise web.seeother('/category/index')
def catslug_unique(data): if data.id < 1: return get_category_by_slug(data.slug) is None else: return not get_other_categories(data.id, data.slug)