Exemple #1
0
    def setup_regionalsummaries(self, parent):
        if 'regional-summaries' in parent.contentIds():
            ns = parent['regional-summaries']
        else:
            ns = create(parent, 'Folder', title=u'Regional summaries')
            self.set_layout(ns, 'reg-summary-start')
            alsoProvides(ns, interfaces.IRegionalSummaryFolder)

        for region in REGIONAL_DESCRIPTORS_REGIONS:
            if not region.is_main:
                continue

            code, name = region.code.lower(), region.title
            if code in ns.contentIds():
                rf = ns[code]
            else:
                rf = create(ns,
                            'wise.msfd.regionalsummaryfolder',
                            title=name,
                            id=code)

                rf._subregions = region.subregions
                rf._countries_for_region = self._get_countries_names(
                    region.countries)

            self.set_layout(rf, 'assessment-summary')
            alsoProvides(rf, interfaces.IRegionalSummaryRegionFolder)
Exemple #2
0
    def add_comment(self):
        form = self.request.form
        question_id = form.get('q').lower()
        thread_id = form.get('thread_id')
        transition_id = 'open_for_{}'.format(thread_id)

        text = form.get('text')

        folder = self.context

        if question_id in folder.contentIds():
            q_folder = folder[question_id]

            # Due to a bug, For 'EC' the wrong state was given (opened_for_tl)
            # transition to the correct state if necessary
            current_state = get_state(q_folder)
            correct_state = 'opened_for_{}'.format(thread_id)

            if current_state != 'closed' and current_state != correct_state:
                transition(obj=q_folder, transition='close')
                transition(obj=q_folder, transition=transition_id)

        else:  # initially create the question folder for comments
            q_folder = create(folder,
                              'wise.msfd.commentsfolder',
                              id=question_id,
                              title='Comments for question ' + question_id)
            transition(obj=q_folder, transition=transition_id)

        comment = create(q_folder, 'wise.msfd.comment', text=text)
        logger.info('Added comment %r in %r:, %r', q_folder, comment, text)

        return self.template()
Exemple #3
0
    def import_etc_report(self, context, portal_type, tree):
        """import_etc_report.

        :param context:
        :param portal_type:
        :param tree:
        """
        count = 0

        for node in tree.xpath('object'):
            url = node.get('url')
            r_id = url.rsplit('/', 1)[-1]
            props = {}

            for ep in node.findall('prop'):
                pname = ep.get('name')

                if pname in self._map:
                    pname, convert = self._map[pname]
                else:
                    convert = noop

                text = ep.text or ''
                props[pname] = convert(text.strip())

            try:
                obj = create(context, portal_type, id=r_id, **props)
            except ValueError:  # this is due to id error
                obj = create(context, portal_type, **props)
                logger.warning("Changed id for object: %s", r_id)

            logger.info("Imported %s", obj.absolute_url())
            count += 1

        return count
Exemple #4
0
    def setup_secondary_articles(self, parent):
        if 'national-descriptors-assessments' not in parent.contentIds():
            return

        nda_parent = parent['national-descriptors-assessments']
        country_ids = nda_parent.contentIds()

        for country in country_ids:
            country_folder = nda_parent[country]

            for article in _get_secondary_articles():
                if article.lower() in country_folder.contentIds():
                    nda = country_folder[article.lower()]
                else:
                    nda = create(country_folder,
                                 'wise.msfd.nationaldescriptorassessment',
                                 title=article)

                    logger.info("Created NationalDescriptorAssessment %s",
                                nda.absolute_url())

                alsoProvides(nda,
                             interfaces.INationalDescriptorAssessmentSecondary)
                self.set_layout(nda, '@@nat-desc-art-view-secondary')

                self.create_comments_folder(nda)
Exemple #5
0
    def setup_nationalsummaries(self, parent):
        if 'national-summaries' in parent.contentIds():
            ns = parent['national-summaries']
        else:
            ns = create(parent, 'Folder', title=u'National summaries')
            self.set_layout(ns, '@@nat-summary-start')
            alsoProvides(ns, interfaces.INationalSummaryFolder)

        for code, country in self._get_countries():
            if code.lower() in ns.contentIds():
                cf = ns[code.lower()]
            else:
                # national_summary type used for Assessment summary/pdf export
                cf = create(ns, 'national_summary', title=country, id=code)

            self.set_layout(cf, 'assessment-summary')
            alsoProvides(cf, interfaces.INationalSummaryCountryFolder)
Exemple #6
0
    def make_country(self, parent, country_code, name):

        if country_code.lower() in parent.contentIds():
            cf = parent[country_code.lower()]
        else:
            cf = create(parent,
                        'wise.msfd.countrydescriptorsfolder',
                        title=name,
                        id=country_code)

        for regid, region in self.get_country_regions(country_code):
            if regid.lower() in cf.contentIds():
                reg = cf[regid.lower()]
            else:
                reg = create(cf, 'Folder', title=region, id=regid.lower())
                alsoProvides(reg, interfaces.INationalRegionDescriptorFolder)
                self.set_layout(reg, '@@nat-desc-reg-view')

            for desc_code, description in self._get_descriptors():
                if desc_code.lower() in reg.contentIds():
                    df = reg[desc_code.lower()]
                else:
                    df = create(reg, 'Folder', title=description, id=desc_code)
                    alsoProvides(df, interfaces.IDescriptorFolder)

                for art in self._get_articles():
                    if art.lower() in df.contentIds():
                        nda = df[art.lower()]
                    else:
                        nda = create(df,
                                     'wise.msfd.nationaldescriptorassessment',
                                     title=art)
                        lr = nda.__ac_local_roles__

                        group = self.get_group(desc_code)

                        lr[group] = ['Contributor']

                        logger.info("Created NationalDescriptorAssessment %s",
                                    nda.absolute_url())

                        self.set_layout(nda, '@@nat-desc-art-view')

                    self.create_comments_folder(nda)

        return cf
Exemple #7
0
    def make_region(self, parent, region):
        code, name = region.code.lower(), region.title

        if code.lower() in parent.contentIds():
            rf = parent[code.lower()]
        else:
            rf = create(parent,
                        'wise.msfd.regiondescriptorsfolder',
                        title=name,
                        id=code)

            rf._subregions = region.subregions
            rf._countries_for_region = self._get_countries_names(
                region.countries)
            self.set_layout(rf, '@@reg-region-start')
            alsoProvides(rf, interfaces.IRegionalDescriptorRegionsFolder)

        for desc_code, description in self._get_descriptors():
            if desc_code.lower() in rf.contentIds():
                df = rf[desc_code.lower()]
            else:
                df = create(rf, 'Folder', title=description, id=desc_code)
                alsoProvides(df, interfaces.IDescriptorFolder)

            for art in self._get_articles():
                if art.lower() in df.contentIds():
                    rda = df[art.lower()]
                else:
                    rda = create(df,
                                 'wise.msfd.regionaldescriptorassessment',
                                 title=art)

                    lr = rda.__ac_local_roles__
                    group = self.get_group(desc_code)
                    lr[group] = ['Contributor']

                    logger.info("Created RegionalDescriptorArticle %s",
                                rda.absolute_url())

                    self.set_layout(rda, '@@reg-desc-art-view')
                    alsoProvides(rda, interfaces.IRegionalDescriptorAssessment)

                self.create_comments_folder(rda)

        return rf
Exemple #8
0
 def create_comments_folder(self, content):
     for id, title, trans in [
         (u'tl', 'Discussion track with Topic Leads', 'open_for_tl'),
         (u'ec', 'Discussion track with EC', 'open_for_ec'),
     ]:
         if id not in content.contentIds():
             dt = create(content,
                         'wise.msfd.commentsfolder',
                         id=id,
                         title=title)
             transition(obj=dt, transition=trans)
Exemple #9
0
    def _create_page(self, destination, p_id, title, html):
        """_create_page.

        :param destination:
        :param id:
        :param title:
        :param html:
        """
        title, html = self._parse_page(title, html)

        rt = RichTextValue(html, 'text/html', 'text/html')

        return create(destination, 'Document', id=p_id, title=title, text=rt)
Exemple #10
0
    def import_Folder(self, obj, destination):
        """import_Folder.

        :param obj:
        :param destination:
        """
        folder = create(destination,
                        'Folder',
                        id=obj.getId(),
                        title=as_plain_text(obj.title))
        logger.info("Created folder: %s", obj.absolute_url())

        return self.import_location(obj, folder)
Exemple #11
0
    def setup_nationaldescriptors(self, parent):
        # National Descriptors Assessments

        if 'national-descriptors-assessments' in parent.contentIds():
            nda = parent['national-descriptors-assessments']
        else:
            nda = create(parent,
                         'Folder',
                         title=u'National Descriptors Assessments')
            self.set_layout(nda, '@@nat-desc-start')
            alsoProvides(nda, interfaces.INationalDescriptorsFolder)

        for code, country in self._get_countries():
            self.make_country(nda, code, country)
Exemple #12
0
    def setup_regionaldescriptors(self, parent):
        # Regional Descriptors Assessments

        if 'regional-descriptors-assessments' in parent.contentIds():
            rda = parent['regional-descriptors-assessments']
        else:
            rda = create(parent,
                         'Folder',
                         title=u'Regional Descriptors Assessments')
            self.set_layout(rda, '@@reg-desc-start')
            alsoProvides(rda, interfaces.IRegionalDescriptorsFolder)

        for region in REGIONAL_DESCRIPTORS_REGIONS:
            if not region.is_main:
                continue

            self.make_region(rda, region)
Exemple #13
0
    def __call__(self):

        # if 'compliance-module' in self.context.contentIds():
        #     self.context.manage_delObjects(['compliance-module'])

        if 'assessment-module' in self.context.contentIds():
            cm = self.context['assessment-module']
        else:
            cm = create(self.context, 'Folder', title=u'Compliance Module')

            self.set_layout(cm, '@@comp-start')
            self.set_policy(cm, 'compliance_section_policy')

            alsoProvides(cm, interfaces.IComplianceModuleFolder)

            lr = cm.__ac_local_roles__
            lr[REVIEWER_GROUP_ID] = [u'Reviewer']
            lr[EDITOR_GROUP_ID] = [u'Editor']

        # Contributor: TL
        # Reviewer: EC
        # Editor: Milieu

        # self.setup_nationaldescriptors(cm)
        DEFAULT = 'regional,nationalsummary,regionalsummary,secondary'
        targets = self.request.form.get('setup', DEFAULT)

        if targets:
            targets = targets.split(',')
        else:
            targets = DEFAULT

        if "regional" in targets:
            self.setup_regionaldescriptors(cm)

        if "nationalsummary" in targets:
            self.setup_nationalsummaries(cm)

        if "secondary" in targets:
            self.setup_secondary_articles(cm)

        if 'regionalsummary' in targets:
            self.setup_regionalsummaries(cm)

        return cm.absolute_url()
Exemple #14
0
    def import_File(self, obj, destination):
        """import_File.

        :param obj:
        :param destination:
        """
        # if DEBUG:
        #     return

        oid, fobj = blob_from_ofs_file(obj)
        props = {
            'file': fobj,
            'title': as_plain_text(obj.title),
            'id': oid,
        }

        obj = create(destination, 'File', **props)
        logger.info("Created file: %s", obj.absolute_url())

        transaction.commit()

        return obj
Exemple #15
0
    def _create_report(self, destination, r_id, title, html):
        """_create_report.

        :param destination:
        :param id:
        :param title:
        :param html:
        """
        # has 2 files:
        # https://bd.eionet.europa.eu/Reports/ETCBDTechnicalWorkingpapers/
        # Factsheets_Mediterranean_marine_hab_spec
        title, html = self._parse_page(title, html)

        e = fromstring(html)
        fp = e.xpath('//p[contains(text(), "See the")]')

        if fp:  # treat the linked report file(s)
            p = fp[0]
            p.drop_tree()
            file_links = p.xpath('a/@href')

        bs = e.xpath('//b[contains(text(), "Abstract")]')

        if bs:
            bs[0].drop_tree()

        publication_date = None
        brs = e.xpath('//b[contains(text(), "Released in")]')

        if brs:
            br = brs[0]
            human_date = br.tail.strip()
            br.tail = ''
            br.drop_tree()

            try:
                tstruct = strptime(human_date, '%B %Y')
            except ValueError:
                logger.warning("Could not parse date: %s", human_date)
            else:
                d = date.fromtimestamp(mktime(tstruct))
                publication_date = d  # DateTime(d.year, d.month, d.day)

        html = tostring(e, pretty_print=True)
        rt = RichTextValue(html, 'text/html', 'text/html')
        f_field = None

        if len(file_links) == 1:
            fobj = self._find_original_file(file_links[0])
            _, f_field = blob_from_ofs_file(fobj)

        report = create(destination,
                        'etc_report',
                        id=r_id,
                        title=title,
                        abstract=rt,
                        publication_date=publication_date,
                        file=f_field)

        logger.info("Created report: %s", report)

        if len(file_links) != 1:
            for link in file_links:
                fobj = self._find_original_file(link)
                # logger.info("Got file: %s for link %s", fobj, link)
                self.import_File(fobj, report, force=True)

        return report