def get(self, id=''): obj = Categories.get(id) if obj: self.redirect('%s/category/%s' % (BASE_URL, obj.name), 301) return else: self.redirect(BASE_URL)
def get(self): act = self.get_argument("act", '').encode('utf-8') category_id = self.get_argument("id", '').encode('utf-8') obj = None if act == 'del': if category_id: Categories.delete(category_id) clear_cache_by_pathlist(['/']) self.set_header("Content-Type", "application/json") self.write(json.dumps("OK")) return elif act == 'edit': if category_id: obj = Categories.get(category_id) # 分类列表 page = self.get_argument("page", 1) category = Categories.get_paged(page, getAttr('ADMIN_CATEGORY_NUM')) total = int( math.ceil(Categories.count_all() / float(getAttr('ADMIN_CATEGORY_NUM')))) if page == 1: self.echo('admin_category.html', { 'title': "分类列表", 'objs': category, 'obj': obj, 'category_kv': Categories.get_all_kv(0), 'show_types': ShowTypes.get_all(), 'total': total, }, layout='_layout_admin.html') else: result = { 'list': category, 'total': total, } self.set_header("Content-Type", "application/json") self.write(json.dumps(result, default=dthandler)) return
def get(self): act = self.get_argument("act", '').encode('utf-8') category_id = self.get_argument("id", '').encode('utf-8') obj = None if act == 'del': if category_id: Categories.delete(category_id) clear_cache_by_pathlist(['/']) self.set_header("Content-Type", "application/json") self.write(json.dumps("OK")) return elif act == 'edit': if category_id: obj = Categories.get(category_id) # 分类列表 page = self.get_argument("page", 1) category = Categories.get_paged(page, getAttr('ADMIN_CATEGORY_NUM')) total = int(math.ceil(Categories.count_all() / float(getAttr('ADMIN_CATEGORY_NUM')))) if page == 1: self.echo('admin_category.html', { 'title': "分类列表", 'objs': category, 'obj': obj, 'category_kv': Categories.get_all_kv(0), 'show_types': ShowTypes.get_all(), 'total': total, }, layout='_layout_admin.html') else: result = { 'list': category, 'total': total, } self.set_header("Content-Type", "application/json") self.write(json.dumps(result, default=dthandler)) return
def get(self): from model.categories import Categories self.echo('robots.txt', {'cats': Categories.get()})