def index(page=1): searchcriteria = request.query.getunicode('search') try: returned_posts = Posts.objects.order_by('-date').skip( (int(page) - 1) * 10).limit(10) if not searchcriteria else Posts.objects( title__icontains=searchcriteria).order_by('-date').skip( (int(page) - 1) * 10).limit(10) postcount = Posts.objects().count( ) if not searchcriteria else Posts.objects( title__icontains=searchcriteria).count() theme = Themes.objects.get(isactive=True) if theme: data = { "posts": returned_posts, "count": postcount, "ceil": math.ceil(postcount / 10), "currentPage": page, "theme": theme.title + '.css' } else: return template('views/index.jinja2', {'errorMessage': 'incorrect theme'}) except Exception as e: return template('views/index.jinja2', {'errorMessage': str(e)}) return template('views/index.jinja2', data)
def index(page=1): searchcriteria = request.query.getunicode('search') try: returned_posts = Posts.objects.order_by('-date').skip((int(page) - 1) * 10).limit( 10) if not searchcriteria else Posts.objects(title__icontains=searchcriteria).order_by('-date').skip( (int(page) - 1) * 10).limit(10) postcount = Posts.objects().count() if not searchcriteria else Posts.objects(title__icontains=searchcriteria).count() theme = Themes.objects.get(isactive=True) if theme: data = { "posts": returned_posts, "count": postcount, "ceil": math.ceil(postcount / 10), "currentPage": page, "theme": theme.title + '.css' } else: return template('views/index.jinja2', {'errorMessage': 'incorrect theme'}) except Exception as e: return template('views/index.jinja2', {'errorMessage': str(e)}) return template('views/index.jinja2', data)
def posts(page=1): try: returned_posts = Posts.objects.order_by('-date').skip((int(page) - 1) * 10).limit(10) postcount = Posts.objects().count() data = { "posts": returned_posts, "count": postcount, "ceil": math.ceil(postcount / 10), "currentPage": page } except: return template('admin/views/login.jinja2', {'errorMessage': 'DB error'}) return template('admin/views/posts.jinja2', data)
def posts(page=1): try: returned_posts = Posts.objects.order_by('-date').skip( (int(page) - 1) * 10).limit(10) postcount = Posts.objects().count() data = { "posts": returned_posts, "count": postcount, "ceil": math.ceil(postcount / 10), "currentPage": page } except: return template('admin/views/login.jinja2', {'errorMessage': 'DB error'}) return template('admin/views/posts.jinja2', data)
def deletepost(): try: Posts.objects(id=request.forms.get('id')).delete() return 'ok' except: return 'failed'