def edit(question_id): try: b = Question.objects.get(id=question_id) categories = Question_Category.objects() username=json.loads(session.get('user')).get('username') if str(b.user.id) != str(json.loads(session.get('user')).get('_id').get('$oid')) or json.loads(session.get('user')).get('permission') < 3: return abort(403) return render.template('admin/question/edit.html', question=b,categories=categories,username=username) except DoesNotExist: abort(404, "404 does not exist")
def index(): # Slice of to pagination # List of filter by get args: # Example: /admin/question_category/?page=1&name_icontains=apple data = request.args.to_dict() # Type of filter engine_filter = {'name__icontains': str} # Prepare filter criteria = {} for k in data: if k in engine_filter: criteria[k] = engine_filter[k](data[k]) pagination = Paginate('admin.question_category.index', count=len(Question_Category.objects(**criteria)), per_page=10) page = pagination.get_page() question_categorys = Question_Category.objects(**criteria)[(page-1) * 10:page * 10] return render.template('admin/question_category/index.html', question_categorys=question_categorys, pagination=pagination)
def add(): categories = Question_Category.objects() username=json.loads(session.get('user')).get('username') return render.template('admin/question/create.html',categories=categories, username=username)