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 registermainuser(): try: if Users.objects().count() == 0: user = Users() user.username = '******' user.password = base64.b64encode(bytes('admin', 'UTF8')) user.save() if Email.objects().count() == 0: email = Email() email.email = '*****@*****.**' email.save() if Posts.objects.count() == 0: post = Posts() post.title = 'სატესტო' post.content = "სატესტო პოსტი" post.date = datetime.now() post.save() except: print('error while connecting to db')
def savepost(): if request.method == 'GET': return template('admin/views/addoreditpost.jinja2') else: try: title = request.forms.getunicode('title') content = request.forms.getunicode('content') p_id = request.forms.get('isediting') if p_id: post = Posts.objects.get(id=p_id) else: post = Posts() post.title = title post.content = content post.date = datetime.now() post.save() except: return template('admin/views/login.jinja2', {'errorMessage': 'DB error'}) redirect('/admin/posts')
def deletepost(): try: Posts.objects(id=request.forms.get('id')).delete() return 'ok' except: return 'failed'