Exemple #1
0
def editpost():
    editForm = EditPostForm()

    if request.method == 'POST':

        if editForm.validate_on_submit():
            postinfo = {}
            if editForm.id.data:
                postinfo['id'] = editForm.id.data
            else:
                postinfo['userId'] = current_user.user_id
            postinfo['title'] = editForm.title.data
            postinfo['content'] = editForm.content.data
            if editForm.datetime.data:
                tmp = editForm.datetime.data.split(' ')
                date = tmp[0].split('-')

                string = ''
                for num in mon:
                    if mon[num] == date[1]:
                        string = '%s-%s-%s %s' % (date[0], num, date[2],
                                                  tmp[1])

                postinfo['date'] = datetime.strptime(string,
                                                     "%Y-%m-%d %H:%M:%S")
            else:
                postinfo['date'] = datetime.now()

            if editForm.password.data:
                postinfo['pass'] = editForm.password.data

            postinfo['status'] = editForm.status.data
            if postinfo['status'] == PostStatus['RELEASED'] or postinfo[
                    'status'] == PostStatus['OVERHEAD']:
                if not current_user.isEditor():
                    postinfo['status'] = PostStatus['UNAUDITED']

            if editForm.save.data:
                postinfo['status'] = PostStatus['DRAFT']

            postinfo['meta'] = editForm.metas.data
            postinfo['labels'] = editForm.labels.data.split(',')

            addPost(postinfo)

    choices = []

    metalist = get_all_metas(page=0)
    for meta in metalist:
        tmp = (int(meta.meta_id), meta.meta_name)
        choices.append(tmp)

    editForm.metas.choices = choices

    if request.method == 'GET':
        id = request.args.get('postid')
        if id:
            post = getPostById(id)
            editForm.id.data = id
            editForm.title.data = post.post_title
            editForm.content.data = post.post_content
            editForm.datetime.data = post.post_date.strftime("%Y-") +\
                            mon[int(post.post_date.strftime("%m"))] + post.post_date.strftime("-%d %H:%M:%S")
            editForm.metas.data = 1
            editForm.labels.data = '1,2,3'
            editForm.password.data = post.post_password
            editForm.status.data = post.post_status

    return render_template('admin/editpost.html', form=editForm)
Exemple #2
0
def editpost():
    editform = EditPostForm()

    if request.method == 'POST':

        if editform.validate_on_submit():
            postinfo = {}
            if editform.id.data:
                postinfo['id'] = editform.id.data
            else:
                postinfo['userId'] = current_user.user_id
            postinfo['title'] = editform.title.data
            postinfo['content'] = editform.content.data
            if editform.datetime.data:
                tmp = editform.datetime.data.split(' ')
                date = tmp[0].split('-')

                string = ''
                for num in mon:
                    if mon[num] == date[1]:
                        string = '%s-%s-%s %s' % (date[0], num, date[2],
                                                  tmp[1])

                postinfo['date'] = datetime.strptime(string,
                                                     "%Y-%m-%d %H:%M:%S")
            else:
                postinfo['date'] = datetime.now()

            if editform.password.data:
                postinfo['pass'] = editform.password.data

            postinfo['status'] = editform.status.data
            if postinfo['status'] == PostStatus['RELEASED'] or postinfo[
                    'status'] == PostStatus['OVERHEAD']:
                if not current_user.isEditor():
                    postinfo['status'] = PostStatus['UNAUDITED']

            if editform.save.data:
                if not editform.id.data:
                    postinfo['status'] = PostStatus['DRAFT']

            postinfo['meta'] = editform.metas.data
            postinfo['labels'] = editform.labels.data.split(',')

            post = add_post(postinfo)
            editform.id.data = post.post_id

    if request.method == 'GET':
        id = request.args.get('postid')
        if id:
            # post = get_post_by_id(id)
            post = Post.query.filter_by(post_id=id).first_or_404()
            # if not post:
            #    abort(404)

            editform.id.data = id
            editform.title.data = post.post_title
            editform.content.data = post.post_content
            editform.datetime.data = post.post_date.strftime("%Y-") + \
                                     mon[int(post.post_date.strftime("%m"))] + post.post_date.strftime("-%d %H:%M:%S")
            editform.metas.data = post.post_meta
            editform.labels.data = '1,2,3'
            editform.password.data = post.post_password
            editform.status.data = post.post_status
    print editform.metas
    return render_template('admin/editpost.html', form=editform)
Exemple #3
0
def editpage():

    editform = EditPageForm()

    if request.method == 'POST':

        if editform.validate_on_submit():
            pageinfo = {}
            if editform.id.data:
                pageinfo['id'] = editform.id.data
            else:
                pageinfo['userId'] = current_user.user_id
            pageinfo['title'] = editform.title.data

            if 'slug' in pageinfo:
                pageinfo['slug'] = editform.slug.data
            else:
                pageinfo['slug'] = editform.title.data

            pageinfo['content'] = editform.content.data

            if editform.datetime.data:
                tmp = editform.datetime.data.split(' ')
                date = tmp[0].split('-')

                string = ''
                for num in mon:
                    if mon[num] == date[1]:
                        string = '%s-%s-%s %s' % (date[0], num, date[2],
                                                  tmp[1])

                pageinfo['date'] = datetime.strptime(string,
                                                     "%Y-%m-%d %H:%M:%S")
            else:
                pageinfo['date'] = datetime.now()

            if editform.password.data:
                pageinfo['pass'] = editform.password.data

            pageinfo['status'] = editform.status.data
            if pageinfo['status'] == PostStatus['RELEASED'] or pageinfo[
                    'status'] == PostStatus['OVERHEAD']:
                if not current_user.isEditor():
                    pageinfo['status'] = PostStatus['UNAUDITED']

            if editform.save.data:
                if not editform.id.data:
                    pageinfo['status'] = PostStatus['DRAFT']

            page = add_page(pageinfo)
            editform.id.data = page.page_id

    if request.method == 'GET':
        id = request.args.get('pageid', type=int)
        if id:
            page = get_page_by_id(id)

            if not page:
                abort(404)

            editform.id.data = id
            editform.title.data = page.page_title
            editform.content.data = page.page_content
            editform.slug.data = page.page_slug
            editform.datetime.data = page.page_date.strftime("%Y-") +\
                            mon[int(page.page_date.strftime("%m"))] + page.page_date.strftime("-%d %H:%M:%S")
            editform.password.data = page.page_password
            editform.status.data = page.page_status

    return render_template('admin/editpage.html', form=editform)
Exemple #4
0
def editpost():
    editForm = EditPostForm()

    if request.method == 'POST':

        if editForm.validate_on_submit():
            postinfo = {}
            if editForm.id.data:
                postinfo['id'] = editForm.id.data
            else:
                postinfo['userId'] = current_user.user_id
            postinfo['title'] = editForm.title.data
            postinfo['content'] = editForm.content.data
            if editForm.datetime.data:
                tmp = editForm.datetime.data.split(' ')
                date = tmp[0].split('-')

                string = ''
                for num in mon:
                    if mon[num] == date[1]:
                        string = '%s-%s-%s %s' % (date[0], num, date[2], tmp[1])

                postinfo['date'] = datetime.strptime(string, "%Y-%m-%d %H:%M:%S")
            else:
                postinfo['date'] = datetime.now()

            if editForm.password.data:
                postinfo['pass'] = editForm.password.data

            postinfo['status'] = editForm.status.data
            if postinfo['status'] == PostStatus['RELEASED'] or postinfo['status'] == PostStatus['OVERHEAD']:
                if not current_user.isEditor():
                    postinfo['status'] = PostStatus['UNAUDITED']

            if editForm.save.data:
                postinfo['status'] = PostStatus['DRAFT']

            postinfo['meta'] = editForm.metas.data
            postinfo['labels'] = editForm.labels.data.split(',')

            addPost(postinfo)

    choices = []

    metalist = get_all_metas(page=0)
    for meta in metalist:
        tmp = (int(meta.meta_id), meta.meta_name)
        choices.append(tmp)

    editForm.metas.choices = choices

    if request.method == 'GET':
        id = request.args.get('postid')
        if id:
            post = getPostById(id)
            editForm.id.data = id
            editForm.title.data = post.post_title
            editForm.content.data = post.post_content
            editForm.datetime.data = post.post_date.strftime("%Y-") +\
                            mon[int(post.post_date.strftime("%m"))] + post.post_date.strftime("-%d %H:%M:%S")
            editForm.metas.data = 1
            editForm.labels.data = '1,2,3'
            editForm.password.data = post.post_password
            editForm.status.data = post.post_status

    return render_template('admin/editpost.html', form=editForm)
Exemple #5
0
def editpost():
    editform = EditPostForm()

    if request.method == 'POST':

        if editform.validate_on_submit():
            postinfo = {}
            if editform.id.data:
                postinfo['id'] = editform.id.data
            else:
                postinfo['userId'] = current_user.user_id
            postinfo['title'] = editform.title.data
            postinfo['content'] = editform.content.data
            if editform.datetime.data:
                tmp = editform.datetime.data.split(' ')
                date = tmp[0].split('-')

                string = ''
                for num in mon:
                    if mon[num] == date[1]:
                        string = '%s-%s-%s %s' % (date[0], num, date[2], tmp[1])

                postinfo['date'] = datetime.strptime(string, "%Y-%m-%d %H:%M:%S")
            else:
                postinfo['date'] = datetime.now()

            if editform.password.data:
                postinfo['pass'] = editform.password.data

            postinfo['status'] = editform.status.data
            if postinfo['status'] == PostStatus['RELEASED'] or postinfo['status'] == PostStatus['OVERHEAD']:
                if not current_user.isEditor():
                    postinfo['status'] = PostStatus['UNAUDITED']

            if editform.save.data:
                if not editform.id.data:
                    postinfo['status'] = PostStatus['DRAFT']

            postinfo['meta'] = editform.metas.data
            postinfo['labels'] = editform.labels.data.split(',')

            post = add_post(postinfo)
            editform.id.data = post.post_id

    if request.method == 'GET':
        id = request.args.get('postid')
        if id:
            # post = get_post_by_id(id)
            post = Post.query.filter_by(post_id=id).first_or_404()
            # if not post:
            #    abort(404)

            editform.id.data = id
            editform.title.data = post.post_title
            editform.content.data = post.post_content
            editform.datetime.data = post.post_date.strftime("%Y-") + \
                                     mon[int(post.post_date.strftime("%m"))] + post.post_date.strftime("-%d %H:%M:%S")
            editform.metas.data = post.post_meta
            editform.labels.data = '1,2,3'
            editform.password.data = post.post_password
            editform.status.data = post.post_status
    print editform.metas
    return render_template('admin/editpost.html', form=editform)
Exemple #6
0
def editpage():

    editform = EditPageForm()

    if request.method == 'POST':

        if editform.validate_on_submit():
            pageinfo = {}
            if editform.id.data:
                pageinfo['id'] = editform.id.data
            else:
                pageinfo['userId'] = current_user.user_id
            pageinfo['title'] = editform.title.data

            if 'slug' in pageinfo:
                pageinfo['slug'] = editform.slug.data
            else:
                pageinfo['slug'] = editform.title.data

            pageinfo['content'] = editform.content.data

            if editform.datetime.data:
                tmp = editform.datetime.data.split(' ')
                date = tmp[0].split('-')

                string = ''
                for num in mon:
                    if mon[num] == date[1]:
                        string = '%s-%s-%s %s' % (date[0], num, date[2], tmp[1])

                pageinfo['date'] = datetime.strptime(string, "%Y-%m-%d %H:%M:%S")
            else:
                pageinfo['date'] = datetime.now()

            if editform.password.data:
                pageinfo['pass'] = editform.password.data

            pageinfo['status'] = editform.status.data
            if pageinfo['status'] == PostStatus['RELEASED'] or pageinfo['status'] == PostStatus['OVERHEAD']:
                if not current_user.isEditor():
                    pageinfo['status'] = PostStatus['UNAUDITED']

            if editform.save.data:
                if not editform.id.data:
                    pageinfo['status'] = PostStatus['DRAFT']

            page = add_page(pageinfo)
            editform.id.data = page.page_id

    if request.method == 'GET':
        id = request.args.get('pageid', type=int)
        if id:
            page = get_page_by_id(id)

            if not page:
                abort(404)

            editform.id.data = id
            editform.title.data = page.page_title
            editform.content.data = page.page_content
            editform.slug.data = page.page_slug
            editform.datetime.data = page.page_date.strftime("%Y-") +\
                            mon[int(page.page_date.strftime("%m"))] + page.page_date.strftime("-%d %H:%M:%S")
            editform.password.data = page.page_password
            editform.status.data = page.page_status

    return render_template('admin/editpage.html', form=editform)