def publish_dialog_save(publication, jpublication, status): publication.portal_division = PortalDivision.get(jpublication['portal_division_id'], returnNoneIfNotExists=True) publication.visibility = jpublication['visibility'] publication.tags = [Tag.get(t['id']) for t in jpublication['tags']] for d in ['publishing_tm', 'event_begin_tm', 'event_end_tm']: setattr(publication, d, PRBase.parse_timestamp(jpublication.get(d))) if status: publication.status = status
def publish_dialog_save(publication, jpublication, status): publication.portal_division = PortalDivision.get( jpublication['portal_division_id'], returnNoneIfNotExists=True) publication.visibility = jpublication['visibility'] publication.tags = [Tag.get(t['id']) for t in jpublication['tags']] for d in ['publishing_tm', 'event_begin_tm', 'event_end_tm']: setattr(publication, d, PRBase.parse_timestamp(jpublication.get(d))) if status: publication.status = status
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 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 load_form_create(json, article_company_id=None, mine_version_article_company_id=None, article_portal_division_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 article_company_id: # companys version. always updating existing articleVersion = ArticleCompany.get(article_company_id) elif mine_version_article_company_id: # updating personal version articleVersion = ArticleCompany.get(mine_version_article_company_id) elif article_portal_division_id: # updating portal version articleVersion = ArticlePortalDivision.get(article_portal_division_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)) else: # creating personal version articleVersion = ArticleCompany(editor=g.user, article=Article(author_user_id=g.user.id)) if action == 'load': article_dict = articleVersion.get_client_side_dict(more_fields='long|company') if article_portal_division_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|short|long|keywords, image.*') articleVersion.attr(parameters['article']) if action == 'validate': articleVersion.detach() return articleVersion.validate(article_company_id is 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) a = articleVersion.save() if article_portal_division_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 submit_publish(json, article_action): action = g.req('action', allowed=['load', 'validate', 'save']) company = Company.get(json['company']['id']) if article_action == 'SUBMIT': material = Material.get(json['material']['id']) check = EditOrSubmitMaterialInPortal(material=material, portal=json['portal']['id']).action_is_allowed( article_action) if check != True: return check publication = Publication(material=material) more_data_to_ret = { 'material': {'id': material.id}, 'can_material_also_be_published': check == True } else: publication = Publication.get(json['publication']['id']) check = PublishUnpublishInPortal(publication=publication, division=publication.portal_division_id, company=company).action_is_allowed(article_action) if check != True: return check more_data_to_ret = {} if action == 'load': portal = Portal.get(json['portal']['id']) ret = { 'publication': publication.get_client_side_dict(), 'company': company.get_client_side_dict(), 'portal': portal.get_client_side_dict() } ret['portal']['divisions'] = PRBase.get_ordered_dict( PublishUnpublishInPortal().get_active_division(portal.divisions)) return utils.dict_merge(ret, more_data_to_ret) else: # publication.attr(g.filter_json(json['publication'], 'portal_division_id')) publication.division = PortalDivision.get(json['publication']['portal_division_id']) # publication.division = PortalDivision.get(json['publication']['portal_division_id']) publication.publishing_tm = PRBase.parse_timestamp(json['publication'].get('publishing_tm')) publication.event_begin_tm = PRBase.parse_timestamp(json['publication'].get('event_begin_tm')) publication.event_end_tm = PRBase.parse_timestamp(json['publication'].get('event_end_tm')) publication.tags = [Tag.get(t['id']) for t in json['publication']['tags']] if 'also_publish' in json and json['also_publish']: publication.status = PublishUnpublishInPortal.STATUSES['PUBLISHED'] else: if article_action in [PublishUnpublishInPortal.ACTIONS['PUBLISH'], PublishUnpublishInPortal.ACTIONS['REPUBLISH']]: publication.status = PublishUnpublishInPortal.STATUSES['PUBLISHED'] elif article_action in [PublishUnpublishInPortal.ACTIONS['UNPUBLISH'], PublishUnpublishInPortal.ACTIONS['UNDELETE']]: publication.status = PublishUnpublishInPortal.STATUSES['UNPUBLISHED'] elif article_action in [PublishUnpublishInPortal.ACTIONS['DELETE']]: publication.status = PublishUnpublishInPortal.STATUSES['DELETED'] if action == 'validate': publication.detach() return publication.validate(True if article_action == 'SUBMIT' else False) else: # if article_action == 'SUBMIT': # publication.long = material.clone_for_portal_images_and_replace_urls(publication.portal_division_id, # publication) publication.save() return get_portal_dict_for_material(publication.portal, company, publication=publication, submit=article_action == 'SUBMIT')
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 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), }