示例#1
0
def get_branch_posts(git_name, git_repository_blog):
    args = request.args.get('access_token')
    per_page = request.args.get('per_page')
    page = request.args.get('page')
    if not args:
        return jsonify({'access_token': args})
    git_access = GitGetAllPosts(git_name, git_repository_blog, args)
    ref = True
    branch_posts = try_file(git_name, git_repository_blog, ref)
    if not branch_posts:
        branch_posts = git_access.get_posts_json('post_branch')
    list_branch_post = []
    if branch_posts and branch_posts[0]['date']:
        posts = try_file(git_name, git_repository_blog)
        if not posts:
            posts = git_access.get_posts_json()
            if not posts:
                posts = []
        for branch_post in branch_posts:
            if branch_post not in posts:
                list_branch_post.append(branch_post)
        branch_posts = sorted(list_branch_post,
                              key=lambda d: d['date'],
                              reverse=True)
        count = len(branch_posts)
        paginate = Pagination(per_page, page, count)
        return jsonify({
            'items':
            branch_posts[paginate.first_post:paginate.last_post + 1],
            'total':
            count
        })
    else:
        return jsonify({"items": [], "total": 0})
示例#2
0
def get_get_blog(git_name, git_repository_blog):
    args = request.args.get('access_token')
    per_page = request.args.get('per_page')
    page = request.args.get('page')
    data = try_file(git_name, git_repository_blog)
    if not data:
        git_access = GitGetAllPosts(git_name, git_repository_blog, args)
        data = git_access.get_file()
        if not data:
            return help_take_data_git(git_access, git_name,
                                      git_repository_blog)
    data_preview = help_take_data_git_2(data)
    args = request.args.get('title', '')
    if args:
        return search(data, 'title', args)
    else:
        count = len(data_preview)
        paginate = Pagination(per_page, page, count)
        if not data_preview[0]['date']:
            return jsonify({'message': False})
        return jsonify({
            'items':
            data_preview[paginate.first_post:paginate.last_post + 1],
            'total':
            count
        })
示例#3
0
def blog(git_name, git_repository_blog, tags=None, page=1):
    # Если существует файл с данными то обращается к файлу если нет то берет с гита
    file = try_file(git_name, git_repository_blog)
    if file:
        if tags:
            file = sorted_by_tags(file, tags)
        paginate = Pagination(3, page, len(file))
        return render_template('blog.html',
                               git_name=git_name,
                               git_repository_blog=git_repository_blog,
                               file=file,
                               paginate=paginate,
                               page=page,
                               tags=tags)
    else:
        git_access = GitGetAllPosts(git_name, git_repository_blog)
        file = git_access.get_file()
        if file:
            if tags:
                file = sorted_by_tags(file, tags)
            paginate = Pagination(3, page, len(file))
            return render_template('blog.html',
                                   git_name=git_name,
                                   git_repository_blog=git_repository_blog,
                                   file=file,
                                   paginate=paginate,
                                   page=page,
                                   tags=tags)
        else:
            return redirect(url_for('homepage'))
示例#4
0
def get_get_blog_by_id(git_name, git_repository_blog, id=None):
    args = request.args.get('access_token')
    data = try_file(git_name, git_repository_blog)
    if not data:
        git_access = GitGetAllPosts(git_name, git_repository_blog, args)
        data = git_access.get_file()
        if not data:
            return help_take_data_git(git_access, git_name,
                                      git_repository_blog)
    one_post = [post for post in data if post['id'] == id]
    if not one_post:
        return abort(404)
    return jsonify(one_post[0])
示例#5
0
def edit_one_branch_post(git_name, git_repository_blog, id_file):
    args = request.args.get('access_token')
    if not args:
        return jsonify({'access_token': args})
    git_access = GitGetAllPosts(git_name, git_repository_blog, args)
    ref = True
    data = git_access.get_one_post(id_file, ref)
    if data.status_code != 200:
        return '', data.status_code
    sha = data.json()['sha']
    changes = request.json
    edit = git_access.edit_post(changes, sha, id_file, ref)
    status = edit.status_code
    return '', status
示例#6
0
def get_one_branch_post(git_name, git_repository_blog, id_file):
    args = request.args.get('access_token')
    if not args:
        return jsonify({'access_token': args})
    git_access = GitGetAllPosts(git_name, git_repository_blog, args)
    ref = True
    data = git_access.get_one_post(id_file, ref)
    if data.status_code != 200:
        return '', data.status_code
    all_post_data = try_file(git_name, git_repository_blog, ref)
    if not all_post_data:
        all_post_data = git_access.get_file(ref)
    for one_post in all_post_data:
        if id_file == one_post['id']:
            return jsonify(one_post)
示例#7
0
def delete_one_branch_post(git_name, git_repository_blog, id_file):
    args = request.args.get('access_token')
    if not args:
        return jsonify({'access_token': args})
    git_access = GitGetAllPosts(git_name, git_repository_blog, args)
    ref = True
    data = git_access.get_one_post(id_file, ref)
    status = 404
    if data.status_code != 200:
        return '', data.status_code
    sha = data.json()['sha']
    path = data.json()['path']
    if data.status_code == 200:
        del_post = git_access.del_one_post(sha, path, ref)
        status = del_post.status_code
    return '', status
示例#8
0
def move_one_branch_post(git_name, git_repository_blog, id_file):
    args = request.args.get('access_token')
    if not args:
        return jsonify({'access_token': args})
    git_access = GitGetAllPosts(git_name, git_repository_blog, args)
    ref = True
    data = git_access.get_one_post(id_file, ref)
    if data.status_code != 200:
        return '', data.status_code
    sha = data.json()['sha']
    path = data.json()['path']
    status = data.status_code
    content = data.json()['content']
    ref = False
    new_post = git_access.new_post(content, ref, id_file)
    if new_post.status_code == 201:
        ref = True
        del_post = git_access.del_one_post(sha, path, ref)
        status = del_post.status_code
    return '', status
示例#9
0
def get_data_blog_tag(git_name, git_repository_blog, tag=None):
    args = request.args.get('access_token')
    per_page = request.args.get('per_page')
    page = request.args.get('page')
    data = try_file(git_name, git_repository_blog)
    if not data:
        git_access = GitGetAllPosts(git_name, git_repository_blog, args)
        data = git_access.get_file()
        if not data:
            return help_take_data_git(git_access, git_name,
                                      git_repository_blog)
    data_preview = help_take_data_git_2(data)
    tag_data = sorted_by_tags(data_preview, tag)
    count = len(tag_data)
    paginate = Pagination(per_page, page, count)
    return jsonify({
        'items':
        tag_data[paginate.first_post:paginate.last_post + 1],
        'total':
        count
    })
示例#10
0
def web_hook(git_name, git_repository_blog):
    args = request.args.get('access_token')
    ref = request.args.get('ref')
    git_access = GitGetAllPosts(git_name, git_repository_blog, args)
    if ref:
        git_access.get_file(ref)
        return '', 200
    git_access.get_file()
    return '', 200