コード例 #1
0
ファイル: views_article.py プロジェクト: alinelle/profireader
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 = ArticleCompany.get(json['material']['id'])
        publication = ArticlePortalDivision(title=material.title, subtitle=material.subtitle,
                                            keywords=material.keywords,
                                            short=material.short, long=material.long, article_company_id=material.id)
        more_data_to_ret = {
            'material': {'id': material.id},
            'can_material_also_be_published':
                MemberCompanyPortal.get(portal_id=json['portal']['id'], company_id=json['company']['id'])
                    .has_rights(MemberCompanyPortal.RIGHT_AT_PORTAL.PUBLICATION_PUBLISH)
        }
    else:
        publication = ArticlePortalDivision.get(json['publication']['id'])
        more_data_to_ret = {}

    if action == 'load':
        ret = {
            'publication': publication.get_client_side_dict(),
            'company': company.get_client_side_dict(),
            'portal': Portal.get(json['portal']['id']).get_client_side_dict()
        }
        ret['portal']['divisions'] = PRBase.get_ordered_dict([d for d in ret['portal']['divisions']
                                                              if (d['portal_division_type_id'] in ['events', 'news'])])

        return PRBase.merge_dicts(ret, more_data_to_ret)
    else:

        publication.attr(g.filter_json(json['publication'], 'portal_division_id'))
        publication.publishing_tm = PRBase.parse_timestamp(json['publication'].get('publishing_tm'))
        publication.event_tm = PRBase.parse_timestamp(json['publication'].get('event_tm'))
        if 'also_publish' in json and json['also_publish']:
            publication.status = ArticlePortalDivision.STATUSES['PUBLISHED']
        else:
            if article_action in [ArticlePortalDivision.ACTIONS['PUBLISH'], ArticlePortalDivision.ACTIONS['REPUBLISH']]:
                publication.status = ArticlePortalDivision.STATUSES['PUBLISHED']
            elif article_action in [ArticlePortalDivision.ACTIONS['UNPUBLISH'], ArticlePortalDivision.ACTIONS[
                'UNDELETE']]:
                publication.status = ArticlePortalDivision.STATUSES['UNPUBLISHED']
            elif article_action in [ArticlePortalDivision.ACTIONS['DELETE']]:
                publication.status = ArticlePortalDivision.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)
コード例 #2
0
    def check(self, *args, **kwargs):
        from profapp.models.portal import Portal, MemberCompanyPortal
        if 'portal_id' in kwargs:
            portal = Portal.get(kwargs['portal_id'])
        elif 'membership_id' in kwargs:
            portal = MemberCompanyPortal.get(kwargs['membership_id']).portal
        else:
            raise Exception("No portal found by portal_id or membership_id kwargs={}".format(kwargs))

        kwargs['company_id'] = portal.company_owner_id
        return super(EmployeeHasRightAtPortalOwnCompany, self).check(*args, **kwargs) and portal.is_active()
コード例 #3
0
    def check(self, *args, **kwargs):
        from profapp.models.portal import Portal, MemberCompanyPortal
        if 'portal_id' in kwargs:
            portal = Portal.get(kwargs['portal_id'])
        elif 'membership_id' in kwargs:
            portal = MemberCompanyPortal.get(kwargs['membership_id']).portal
        else:
            raise Exception(
                "No portal found by portal_id or membership_id kwargs={}".
                format(kwargs))

        kwargs['company_id'] = portal.company_owner_id
        return super(EmployeeHasRightAtPortalOwnCompany, self).check(
            *args, **kwargs) and portal.is_active()
コード例 #4
0
ファイル: views_article.py プロジェクト: CNazar/profireader
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.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().set_tags_positions()
            return get_portal_dict_for_material(publication.portal, company, publication=publication,
                                                submit=article_action == 'SUBMIT')
コード例 #5
0
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 = ArticleCompany.get(json['material']['id'])
        publication = ArticlePortalDivision(title=material.title,
                                            subtitle=material.subtitle,
                                            keywords=material.keywords,
                                            short=material.short,
                                            long=material.long,
                                            article_company_id=material.id)
        more_data_to_ret = {
            'material': {
                'id': material.id
            },
            'can_material_also_be_published':
            MemberCompanyPortal.get(
                portal_id=json['portal']['id'],
                company_id=json['company']['id']).has_rights(
                    MemberCompanyPortal.RIGHT_AT_PORTAL.PUBLICATION_PUBLISH)
        }
    else:
        publication = ArticlePortalDivision.get(json['publication']['id'])
        more_data_to_ret = {}

    if action == 'load':
        ret = {
            'publication': publication.get_client_side_dict(),
            'company': company.get_client_side_dict(),
            'portal': Portal.get(json['portal']['id']).get_client_side_dict()
        }
        ret['portal']['divisions'] = PRBase.get_ordered_dict([
            d for d in ret['portal']['divisions']
            if (d['portal_division_type_id'] in ['events', 'news'])
        ])

        return PRBase.merge_dicts(ret, more_data_to_ret)
    else:

        publication.attr(
            g.filter_json(json['publication'], 'portal_division_id'))
        publication.publishing_tm = PRBase.parse_timestamp(
            json['publication'].get('publishing_tm'))
        publication.event_tm = PRBase.parse_timestamp(
            json['publication'].get('event_tm'))
        if 'also_publish' in json and json['also_publish']:
            publication.status = ArticlePortalDivision.STATUSES['PUBLISHED']
        else:
            if article_action in [
                    ArticlePortalDivision.ACTIONS['PUBLISH'],
                    ArticlePortalDivision.ACTIONS['REPUBLISH']
            ]:
                publication.status = ArticlePortalDivision.STATUSES[
                    'PUBLISHED']
            elif article_action in [
                    ArticlePortalDivision.ACTIONS['UNPUBLISH'],
                    ArticlePortalDivision.ACTIONS['UNDELETE']
            ]:
                publication.status = ArticlePortalDivision.STATUSES[
                    'UNPUBLISHED']
            elif article_action in [ArticlePortalDivision.ACTIONS['DELETE']]:
                publication.status = ArticlePortalDivision.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)
コード例 #6
0
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.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().set_tags_positions()
            return get_portal_dict_for_material(
                publication.portal,
                company,
                publication=publication,
                submit=article_action == 'SUBMIT')