示例#1
0
def load_mine(json):
    page = json.get('gr_data')['paginationOptions']['pageNumber'] if json.get('gr_data') else 1
    pageSize = json.get('gr_data')['paginationOptions']['pageSize'] if json.get('gr_data') else 25
    search_text = json.get('gr_data')['search_text'] if json.get('gr_data') else None
    params = {'user_id': g.user_dict['id']}
    if json.get('gr_data'):
        params['sort'] = {}
        params['filter'] = {}
        if json.get('gr_data')['sort']:
            for n in json.get('gr_data')['sort']:
                params['sort'][n] = json.get('gr_data')['sort'][n]
        if json.get('gr_data')['filter']:
            for b in json.get('gr_data')['filter']:
                if json.get('gr_data')['filter'][b] != '-- all --':
                    params['filter'][b] = json.get('gr_data')['filter'][b]
    subquery = ArticleCompany.subquery_user_articles(search_text=search_text,**params)
    articles, pages, current_page = pagination(subquery,
                                               page=page, items_per_page=pageSize)
    add_param = {'value': '1', 'label': '-- all --'}
    statuses = Article.list_for_grid_tables(ARTICLE_STATUS_IN_COMPANY.all, add_param, False)
    company_list_for_grid = Article.list_for_grid_tables(ArticleCompany.get_companies_where_user_send_article(g.user_dict['id']), add_param, True)
    articles_drid_data = Article.getListGridDataArticles(articles.all())
    grid_filters = {'company': company_list_for_grid,'status': statuses}
    return {'grid_data': articles_drid_data,
            'grid_filters': grid_filters,
            'total': subquery.count()}
示例#2
0
def load_mine(json):
    current_page = json.get('pages')['current_page'] if json.get('pages') else 1
    chosen_company_id = json.get('chosen_company')['id'] if json.get('chosen_company') else 0
    params = {'search_text': json.get('search_text'), 'user_id': g.user_dict['id']}
    original_chosen_status = None
    article_status = json.get('chosen_status')
    if chosen_company_id:
        params['company_id'] = chosen_company_id
    if article_status and article_status != 'All':
        params['status'] = original_chosen_status = article_status
    subquery = ArticleCompany.subquery_user_articles(**params)

    articles, pages, current_page = pagination(subquery,
                                               page=current_page,
                                               items_per_page=10)

    all, companies = ArticleCompany.get_companies_where_user_send_article(g.user_dict['id'])
    statuses = {status: status for status in ARTICLE_STATUS_IN_COMPANY.all}
    statuses['All'] = 'All'

    return {'articles': [{'article': a.get_client_side_dict(),
                          'company_count': len(a.get_client_side_dict()['submitted_versions']) + 1}
                         for a in articles],
            'companies': companies,
            'search_text': json.get('search_text') or '',
            'original_search_text': json.get('search_text') or '',
            'chosen_company': json.get('chosen_company') or all,
            'pages': {'total': pages,
                      'current_page': current_page,
                      'page_buttons': Config.PAGINATION_BUTTONS},
            'chosen_status': json.get('chosen_status') or statuses['All'],
            'original_chosen_status': original_chosen_status,
            'statuses': statuses}