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()}
def load_form_create(json): action = g.req('action', allowed=['load', 'validate', 'save']) if action == 'load': return {'id': '', 'title': '', 'short': '', 'long': '', 'coordinates': '', 'ratio': Config.IMAGE_EDITOR_RATIO} if action == 'validate': del json['coordinates'], json['ratio'] return Article.save_new_article(g.user_dict['id'], **g.filter_json(json, 'title,short,long,keywords')).mine_version.validate('insert') else: image_id = json.get('image_file_id') if image_id: json['image_file_id'] = crop_image(image_id, json.get('coordinates')) del json['coordinates'], json['ratio'] article = Article.save_new_article(g.user_dict['id'], **json) g.db.add(article) return article.get_client_side_dict()
def load_form_create(json, company_id=None, material_id=None, publication_id=None): action = g.req('action', allowed=['load', 'validate', 'save']) def portal_division_dict(article, tags=None): if (not hasattr(article, 'portal_division_id')) or ( article.portal_division_id is None): return {'positioned_articles': []} else: filter = article.position_unique_filter() return { 'positioned_articles': [ pda.get_client_side_dict(fields='id|position|title') for pda in db(ArticlePortalDivision).filter(filter).order_by( expression.desc(ArticlePortalDivision.position)).all() ], 'availableTags': tags } available_tag_names = None if company_id: # creating material version articleVersion = ArticleCompany( company_id=company_id, editor=g.user, article=Article(author_user_id=g.user.id)) elif material_id: # companys version. always updating existing articleVersion = ArticleCompany.get(material_id) elif publication_id: # updating portal version articleVersion = ArticlePortalDivision.get(publication_id) portal_division_id = articleVersion.portal_division_id article_tag_names = articleVersion.tags available_tags = PortalDivision.get( portal_division_id).portal_division_tags available_tag_names = list( map(lambda x: getattr(x, 'name', ''), available_tags)) if action == 'load': article_dict = articleVersion.get_client_side_dict( more_fields='long|company') article_dict['image'] = articleVersion.get_image_client_side_dict() if publication_id: article_dict = dict( list(article_dict.items()) + [('tags', article_tag_names)]) return { 'article': article_dict, 'portal_division': portal_division_dict(articleVersion, available_tag_names) } else: parameters = g.filter_json( json, 'article.title|subtitle|short|long|keywords') articleVersion.attr(parameters['article']) if action == 'validate': articleVersion.detach() return articleVersion.validate(articleVersion.id is not None) else: if type(articleVersion) == ArticlePortalDivision: tag_names = json['article']['tags'] articleVersion.manage_article_tags(tag_names) article_dict = articleVersion.set_image_client_side_dict( json['article']['image']).save().get_client_side_dict( more_fields='long|company') if publication_id: articleVersion.insert_after( json['portal_division']['insert_after'], articleVersion.position_unique_filter()) article_dict['image'] = articleVersion.get_image_client_side_dict() return { 'article': article_dict, 'portal_division': portal_division_dict(articleVersion) }
def details_load(json, article_id): return Article.get(article_id).get_client_side_dict()
def submit_to_company(json, article_id): a = Article.get(article_id) a.mine_version.clone_for_company(json['company_id']).save() return {'article': a.get(article_id).get_client_side_dict(), 'company_id': json['company_id']}
def save(json, article_company_id): json.pop('company') ret = Article.save_edited_version(g.user.id, article_company_id, **json).save().article return ret.get_client_side_dict()
def confirm_create(json): return Article.save_new_article(g.user_dict['id'], **json).save().get_client_side_dict()
def load_mine(json): return {'articles': [a.get_client_side_dict() for a in Article.get_articles_for_user(g.user.id)]}
def load_form_create(json, company_id=None, material_id=None, publication_id=None): action = g.req('action', allowed=['load', 'validate', 'save']) def portal_division_dict(article, tags=None): if (not hasattr(article, 'portal_division_id')) or ( article.portal_division_id is None): return {'positioned_articles': []} else: filter = article.position_unique_filter() return { 'positioned_articles': [ pda.get_client_side_dict(fields='id|position|title') for pda in db(ArticlePortalDivision).filter(filter).order_by( expression.desc(ArticlePortalDivision.position)).all() ], 'availableTags': tags } available_tag_names = None if company_id: # creating material version articleVersion = ArticleCompany( company_id=company_id, editor=g.user, article=Article(author_user_id=g.user.id)) elif material_id: # companys version. always updating existing articleVersion = ArticleCompany.get(material_id) elif publication_id: # updating portal version articleVersion = ArticlePortalDivision.get(publication_id) portal_division_id = articleVersion.portal_division_id article_tag_names = articleVersion.tags available_tags = PortalDivision.get( portal_division_id).portal_division_tags available_tag_names = list( map(lambda x: getattr(x, 'name', ''), available_tags)) if action == 'load': article_dict = articleVersion.get_client_side_dict( more_fields='long|company') if publication_id: article_dict = dict( list(article_dict.items()) + [('tags', article_tag_names)]) image_dict = { 'ratio': Config.IMAGE_EDITOR_RATIO, 'coordinates': None, 'image_file_id': article_dict['image_file_id'], 'no_image_url': g.fileUrl(FOLDER_AND_FILE.no_article_image()) } # article_dict['long'] = '<table><tr><td><em>cell</em> 1</td><td><strong>cell<strong> 2</td></tr></table>' # TODO: VK by OZ: this code should be moved to model try: if article_dict.get('image_file_id'): image_dict['image_file_id'], image_dict['coordinates'] = ImageCroped. \ get_coordinates_and_original_img(article_dict.get('image_file_id')) else: image_dict['image_file_id'] = None except Exception as e: pass return { 'article': article_dict, 'image': image_dict, 'portal_division': portal_division_dict(articleVersion, available_tag_names) } else: parameters = g.filter_json( json, 'article.title|subtitle|short|long|keywords, image.*') articleVersion.attr(parameters['article']) if action == 'validate': articleVersion.detach() return articleVersion.validate(articleVersion.id is not None) else: image_id = parameters['image'].get('image_file_id') # TODO: VK by OZ: this code dont work if ArticlePortalDivision updated if image_id: articleVersion.image_file_id = crop_image( image_id, parameters['image']['coordinates']) else: articleVersion.image_file_id = None if type(articleVersion) == ArticlePortalDivision: tag_names = json['article']['tags'] articleVersion.manage_article_tags(tag_names) articleVersion.save() if publication_id: articleVersion.insert_after( json['portal_division']['insert_after'], articleVersion.position_unique_filter()) return { 'article': articleVersion.save().get_client_side_dict(more_fields='long'), 'image': json['image'], 'portal_division': portal_division_dict(articleVersion) }
def my_versions(article_id): return render_template('article/versions.html', article_versions=Article.get_versions(article_id, author_user_id=g.user.id))
def show_form_update(article_version_id): return render_template('article/edit_form.html', article_version = Article.get_one_version(article_version_id=article_version_id))
def show_mine(): return render_template('article/mine_list.html', articles = Article.list(g.user_dict['id']))