def home(id=0): """Home page.""" static_context = StaticContext.query \ .filter_by(user=session['userid']) \ .join(Category,Category.id==StaticContext.category) \ .join(CategoryAttr,CategoryAttr.id==Category.attr_id) \ .filter(CategoryAttr.url=='index') \ .order_by(StaticContext.main_sort) \ .all() return render('public/home.html', static_context=static_context)
def edit_category(id=0): category = Category.query.get_or_404(id) form = AllCategoryForm() form.title.data = category.title form.summary.data = category.summary form.key.data = category.key form.word.data = category.word form.sort.data = category.sort form.is_enable.data = category.is_enable form.main_sort.data = category.main_sort return render('users/edit_category.html',form=form,id=category.id)
def single(id=0): category = Category.query.get_or_404(id) static_context = StaticContext.query \ .filter_by(user=session['userid']) \ .join(Category,Category.id==StaticContext.category) \ .join(CategoryAttr,CategoryAttr.id==Category.attr_id) \ .filter(Category.id==id) \ .order_by(StaticContext.main_sort) \ .all() return render( '{template}'.format(template=category.categorys_attr.templates), category=category, static_context=static_context)
def show_article(id=0): article = Article.query.get_or_404(id) static_context = [] if article.static_context: _context = article.static_context.split('|') else: _context = session.get('article_context', '').split('|') for i in _context: static_context.append({'html': i}) return render('show_article.html', article=article, static_context=static_context)
def show_photo(id=0): photo = Photo.query.get_or_404(id) #静态内容 static_context = [] if photo.static_context: _context = photo.static_context.split('|') else: _context = session.get('photo_context', '').split('|') for i in _context: static_context.append({'html': i}) photo.update(count=photo.count + 1) return render('show_photo.html', photo=photo, static_context=static_context)
def article(id=0): category = Category.query.get_or_404(id) page = request.args.get('page', 1, type=int) static_context = StaticContext.query \ .filter_by(user=session['userid']) \ .join(Category,Category.id==StaticContext.category) \ .join(CategoryAttr,CategoryAttr.id==Category.attr_id) \ .filter(Category.id==id) \ .order_by(StaticContext.main_sort) \ .all() id_list = [category.id] get_lower_id(id_list, category.id) pagination = Article.query.filter(Article.category.in_(id_list)).paginate( page, session['article_page'], error_out=False) return render( '{template}'.format(template=category.categorys_attr.templates), category=category, static_context=static_context, article=pagination.items, pagination=pagination)
def photo(id=0): category = Category.query \ .filter(Category.state!=0) \ .filter(Category.id==id) \ .first() static_context = StaticContext.query \ .filter_by(user=session['userid']) \ .join(Category,Category.id==StaticContext.category) \ .join(CategoryAttr,CategoryAttr.id==Category.attr_id) \ .filter(Category.id==id) \ .order_by(StaticContext.main_sort) \ .all() #获取所有子孙栏目id id_list = [category.id] get_lower_id(id_list, category.id) photo = Photo.query.filter(Photo.category.in_(id_list)).all() #end return render( '{template}'.format(template=category.categorys_attr.templates), category=category, static_context=static_context, photo=photo)
def all_banner(): form = AllBannerForm(request.form) banner = Banner.query.filter_by(user=current_user.id).order_by('sort').all() return render('users/all_banner.html',form=form, banner=banner)
def all_category_attr(): form = AllCategoryAttrForm(request.form) category_attr = CategoryAttr.query.filter_by(usertemplate_id=current_user.templates).all() return render('users/all_category_attr.html',form=form, category_attr=category_attr)
def all_category(): form = AllCategoryForm(request.form) category = Category.query.filter_by(users=current_user).filter_by(state=1).order_by('sort').all() return render('users/all_category.html',form=form, category=category)