예제 #1
0
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')
예제 #2
0
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')
예제 #3
0
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')