Exemple #1
0
    def sett(self, value):
        """ Set tags
        """
        # if folder didn't have a theme tag earlier we send an event
        # so folders and stuff can be created in the themecentre
        tags = IThemeTagging(self.context).tags
        should_promote = not tags

        IThemeTagging(self.context).tags = (value, )
        if value and should_promote:
            notify(PromotedToThemeCentreEvent(self.context))
Exemple #2
0
    def afterSetUp(self):
        """ After setup
        """
        self.setRoles(['Manager'])
        self.portal.invokeFactory('Folder', id='to_be_promoted')
        self.portal.invokeFactory('Folder', id='to_be_promoted2')
        self.portal.invokeFactory('Document', id='cut_and_paste')
        IThemeTagging(self.portal.cut_and_paste).tags = ['climate']
        self.portal.invokeFactory('Document', id='copy_and_paste')
        IThemeTagging(self.portal.copy_and_paste).tags = ['climate']
        self.createObject = createObject

        self.portal.invokeFactory('Event', id='event_link')
        self.portal.invokeFactory('Document', id='doc_link')
    def afterSetUp(self):
        """ Set up
        """
        setSite(self.portal)
        self.setRoles('Member')
        self.workflow = self.portal.portal_workflow
        self.portal.acl_users._doAddUser(
            'reviewer', 'secret', ['Reviewer'], [])

        self.folder.invokeFactory('Document', id='unpub_air')
        self.folder.invokeFactory('Highlight', id='unpub_air_high')
        self.folder.invokeFactory('Promotion', id='unpub')
        self.folder.invokeFactory('Document', id='pub_air')
        self.folder.invokeFactory('PressRelease', id='priv_air_press')
        self.folder.invokeFactory('Document', id='pub')
        self.folder.invokeFactory('Document', id='rel_from')
        self.folder.invokeFactory('Document', id='rel_to')
        self.folder.invokeFactory('Document', id='rel_to2')
        self.folder.invokeFactory('Article', id='rel_not_same_type')
        self.folder.invokeFactory('Article', id='art1_pub')
        self.folder.invokeFactory('Article', id='art2_pub')
        self.folder.invokeFactory('Article', id='art3')

        IThemeTagging(self.folder.unpub_air).tags = ['air']
        IThemeTagging(self.folder.unpub_air_high).tags = ['air']
        IThemeTagging(self.folder.pub_air).tags = ['air']
        IThemeTagging(self.folder.priv_air_press).tags = ['air']

        self.folder.rel_from.setRelatedItems([self.folder.rel_to,
                                              self.folder.rel_to2,
                                              self.folder.rel_not_same_type,
                                              self.folder.unpub_air])
        self.folder.unpub_air.setRelatedItems([self.folder.rel_to])
        self.setRoles('Manager')

        self.workflow.doActionFor(self.folder.pub_air, 'publish')
        self.workflow.doActionFor(self.folder.pub, 'publish')
        self.workflow.doActionFor(self.folder.art1_pub, 'publish')
        self.workflow.doActionFor(self.folder.art2_pub, 'publish')

        air = self.portal.portal_vocabularies.themes.air
        self.workflow.doActionFor(air, 'publish')

        self.folder.unpub_air.reindexObject()
        self.folder.unpub_air_high.reindexObject()
        self.folder.unpub.reindexObject()
        self.folder.pub_air.reindexObject()
        self.folder.priv_air_press.reindexObject()
        self.folder.pub.reindexObject()
Exemple #4
0
def objectThemeTagged(obj, event):
    """ Checks if the object's theme tags are modified. If true, tags are
        copied to eventual translations, and catalog is updated.
    """
    for desc in event.descriptions:
        if getattr(desc, 'interface', None) == IThemeTagging:
            try:
                context = obj.context
            except AttributeError:
                context = obj

            if context.isCanonical():
                for _lang, trans in context.getTranslations().items():
                    IThemeTagging(trans[0]).tags = IThemeTagging(context).tags
            context.reindexObject()
def setupLocalRDFRepositories(context):

    if context.readDataFile('eeaploneadmin_localsites.txt') is None:
        return

    plone = context.getSite()
    logger = context.getLogger('eea-localsite')
    wf = getToolByName(plone, 'portal_workflow')

    enRDFRepo = plone.SITE.themes['rdf-repository']
    #siteLangView = plone.unrestrictedTraverse('@@translatedSitesLanguages')
    languages = getLanguages(context)

    for rid, ob in enRDFRepo.objectItems():
        if 'reports_' in rid:
            theme = IThemeTagging(ob).tags[0]
            rssTemplate = ('http://reports.eea.europa.eu/reports_local.rdf?'
                           'select=public&image=yes&replang=%s&theme=%s')
            rssTitle = _(u'Reports')
            newRss = oldRss = 0
            for lang, _unused in languages:
                translation = ob.getTranslation(lang)
                if translation is None:
                    ob.addTranslation(lang)
                    translation = ob.getTranslation(lang)
                    transaction.savepoint()
                    newRss += 1
                else:
                    oldRss += 1

                IThemeTagging(translation).tags = IThemeTagging(ob).tags
                translation.unmarkCreationFlag()
                translation.setTitle(translate(rssTitle, target_language=lang))
                translation.setUrl('/%s/themes/%s/reports' % (lang, theme))
                rssUrl = rssTemplate % (lang, theme)
                translation.setFeedURL(rssUrl)
                translation.setLanguage(lang)
                translation.setEntriesSize(10000)
                translation.setEntriesWithDescription(0)
                translation.updateFeed()
                if wf.getInfoFor(translation, 'review_state') != 'published':
                    wf.doActionFor(translation,
                                   'publish',
                                   comment=('Initial publish by method '
                                            'setupLocalRDFRepositories'))
            logger.info("setupLocalRDFRepositories(): "
                        "configured %s new and %s old RSS FeedRecipe for "
                        "theme:%s" % (newRss, oldRss, theme))
Exemple #6
0
 def gett(self):
     """ Get tags
     """
     tags = IThemeTagging(self.context).tags
     if tags:
         return tags[0]
     return None
Exemple #7
0
 def setThemes(self, value, **kw):
     """ Use the tagging adapter to set the themes.
     """
     # value = filter(None, value)
     value = [val for val in value if val]
     tagging = IThemeTagging(self)
     tagging.tags = value
Exemple #8
0
    def menu(self):
        """ Menu
        """
        plone_utils = getToolByName(self.context, 'plone_utils')
        propstool = getToolByName(self.context, 'portal_properties')
        siteprops = getattr(propstool, 'site_properties', None)
        if siteprops:
            view_actions = siteprops.getProperty(
                'typesUseViewActionInListings', [])
        else:
            view_actions = []

        themecentre = getThemeCentre(self.context)
        if themecentre is None:
            return None

        themecentre_url = themecentre.absolute_url()
        tags = IThemeTagging(themecentre).tags
        query = {'navSection': TOPICS_ID}
        memtool = getToolByName(self.context, 'portal_membership')
        if memtool is not None and memtool.isAnonymousUser():
            query['review_state'] = 'published'

        # get all objects that have the same theme as the current themecentre
        rel = queryAdapter(themecentre, IRelations)
        if rel:
            related_brains = rel.byTheme(getBrains=True, constraints=query)
            # ignore the objects that are stored in the current themecentre
            related_brains = [
                brain for brain in related_brains
                if not brain.getURL().startswith(themecentre_url)
            ]
        else:
            related_brains = []

        menu = []
        for brain in related_brains:
            # check that the related object doesn't belong
            # to a deprecated theme
            themes = [theme for theme in brain.getThemes if theme not in tags]
            if themes:
                wf_state = plone_utils.normalizeString(brain.review_state)
                if brain.portal_type in view_actions:
                    url = brain.getURL() + '/view'
                else:
                    url = brain.getURL()

                item = {
                    'title': brain.Title,
                    'url': url,
                    'portal_type':
                    plone_utils.normalizeString(brain.portal_type),
                    'wf_state': wf_state,
                }

                menu.append(item)

        menu.sort()
        return menu
def retagAllTranslations(context, languages):
    catalog = getToolByName(context, 'portal_catalog')
    #langs = [ lang for lang, _unused in languages if lang != 'en' ]

    for b in catalog(
            object_provides='eea.themecentre.interfaces.IThemeTaggable',
            Language='all'):

        if 'portal_factory' in b.getURL() or b.Language == 'en':
            continue
        obj = b.getObject()
        if b.getThemes == [] or b.getThemes == [None]:
            IThemeTagging(obj).tags = IThemeTagging(obj.getCanonical()).tags
        if IThemeCentre.providedBy(obj):
            IThemeRelation(obj).related = IThemeRelation(
                obj.getCanonical()).related
            print "%s : %s" % (obj.absolute_url(1),
                               IThemeRelation(obj).related)
Exemple #10
0
    def fixVersion(self, version):
        """  Fix objects by version id
        """
        ctool = getToolByName(self.context, 'portal_catalog')
        brains = ctool(getVersionId=version)
        if len(brains) < 2:
            return

        try:
            brains = sorted(brains,
                            reverse=1,
                            key=lambda b: max(b.effective.asdatetime(),
                                              b.created.asdatetime()))
        except Exception as err:
            logger.exception(err)
            return self._redirect("Couldn't synchronize older versions",
                                  "warn")

        themes = None
        state = None
        for brain in brains:
            try:
                old_themes = brain.getThemes
                old_state = brain.review_state
            except Exception as err:
                logger.exception(err)
                continue

            # Skip some revisions
            if old_state in self.ignore_states:
                continue

            # Latest version state
            if not state:
                state = old_state

            # Latest version themes
            if not themes:
                themes = old_themes
                continue

            # Nothing changed
            if sorted(themes) == sorted(old_themes):
                continue

            try:
                doc = brain.getObject()
                IThemeTagging(doc).tags = themes
                doc.reindexObject(idxs=["getThemes"])
            except Exception as err:
                logger.exception(err)
            else:
                self.updateHistory(doc, themes, old_themes)

        return self._redirect(
            "Succesfully synchronized topics on older versions")
Exemple #11
0
def getThemesForIndex(obj, **kwargs):
    """ Get themes for catalog index """
    try:
        themes = IThemeTagging(obj)
        return themes.tags
    except (ComponentLookupError, TypeError, ValueError):
        # if can't be adapted, see if it's an AT object with getThemes method
        if hasattr(obj, 'getThemes'):
            return obj.getThemes()

        # The catalog expects AttributeErrors when a value can't be found
        raise AttributeError
Exemple #12
0
def objectAdded(obj, event):
    """ Checks if the object belongs to a theme centre. If it does and it
        is taggable, then it is tagged with the current theme. """

    if IThemeCentre.providedBy(obj):
        return

    themeCentre = getThemeCentre(obj)
    if themeCentre:
        themes = IThemeTagging(obj, None)
        if themes:
            themeCentreThemes = IThemeCentreSchema(themeCentre)
            if themeCentreThemes.tags not in themes.tags:
                themes.tags += [themeCentreThemes.tags]
    def testMergedThemes(self):
        """ air_quality is merged with air
            create and theme tag a news item
        """
        self.portal.invokeFactory('News Item', id='news2')
        obj = self.portal.news2
        themes = IThemeTagging(obj)
        themes.tags = ['air']
        self.portal.portal_catalog.reindexObject(self.portal.news2)
        self.portal.invokeFactory('News Item', id='news3')
        obj = self.portal.news3
        themes = IThemeTagging(obj)
        themes.tags = ['air_quality']
        self.portal.portal_catalog.reindexObject(self.portal.news3)
        processQueue()

        res = self.portal.portal_catalog.searchResults(
            getThemes=['air_quality'], portal_type='News Item')
        self.assertEqual(len(res), 1)
        # only air is mapped to air_quality not the other way around
        res = self.portal.portal_catalog.searchResults(getThemes=['air'],
                                                       portal_type='News Item')
        self.assertEqual(len(res), 1)
Exemple #14
0
 def afterSetUp(self):
     """ After setup
     """
     self.setRoles(['Manager'])
     portal = self.portal
     for i in range(0, 3):
         tid = 'test' + str(i)
         title = u'Test Item ' + str(i)
         item = portal[portal.invokeFactory('News Item',
                                            title=title,
                                            id=tid)]
         IThemeTagging(item).tags = [u'agriculture', u'air']
         alsoProvides(item, IPromoted)
         promo = Promotion(item)
         promo.locations = [u'Front Page', u'Themes']
         item.reindexObject()
         portal.portal_workflow.doActionFor(item, 'publish')
    def afterSetUp(self):
        """ After setup
        """
        setSite(self.portal)

        provideAdapter(ThemeTaggableMerged)
        provideAdapter(AttributeAnnotations,
                       provides=IAnnotations,
                       adapts=[IThemeTaggable])
        classImplements(ATNewsItem, IThemeTaggable)
        self.setRoles('Manager')

        # create and theme tag a news item
        self.portal.invokeFactory('News Item', id='news1')
        obj = self.portal.news1
        themes = IThemeTagging(obj)
        themes.tags = ['agriculture']
        self.portal.portal_catalog.reindexObject(self.portal.news1)
        self.portal.portal_catalog.reindexObject(self.portal)
        processQueue()
Exemple #16
0
def tagTranslation(obj, event):
    """ Tag Translation
    """
    canonical = obj.getCanonical()
    IThemeTagging(obj).tags = IThemeTagging(canonical).tags
Exemple #17
0
def rollback(self):
    """ Rollback themes
    """
    site = getSite()
    path = os.environ.get('EEACONVERTER_TEMP')
    path = os.path.join(path, 'roll-back.tsv')
    wf = site.portal_workflow

    res = {}
    with open(path, 'r') as ofile:
        reader = csv.reader(ofile, delimiter='\t')
        for row in reader:
            ptype = row[0]
            if ptype == 'Type':
                continue
            link = row[1]
            old_themes = json.loads(row[2])
            new_themes = json.loads(row[3])
            res[link] = (ptype, old_themes, new_themes)

    count = 0
    ret = []
    for link, val in res.items():
        if val[0] in ['Assessment', 'ExternalDataSpec']:
            continue
        obj = site.unrestrictedTraverse(link)
        old_themes = val[1]
        new_themes = val[2]
        tags = IThemeTagging(obj).tags

        if tags != new_themes:
            logger.warn("SKIP Themes manually changed for %s to %s", link, tags)
            continue

        if tags == old_themes:
            logger.warn("SKIP: Themes manually fixed for %s to %s", link, tags)
            continue

        IThemeTagging(obj).tags = old_themes
        obj.reindexObject(idxs=['getThemes'])
        count += 1

        # Log change to object history
        history = obj.workflow_history
        review_state = wf.getInfoFor(obj, 'review_state', 'None')
        for key in history:
            if 'linguaflow' in key:
                continue
            if 'BKUP' in key:
                continue
            history[key] += ({
                'action': 'Roll-back',
                'actor': 'voineali',
                'comments': (
                    'Rollback themes to "{themes}" from "{new_themes}"'.format(
                        themes=', '.join(old_themes),
                        new_themes=', '.join(new_themes))),
                'review_state': review_state,
                'time': DateTime()
                },)

    for link, val in res.items():
        if val[0] not in ['Assessment', 'ExternalDataSpec']:
            continue
        obj = site.unrestrictedTraverse(link)
        obj.reindexObject(idxs=['getThemes'])
        count += 1

    ret.append(str(count))
    return "\n".join(ret)
Exemple #18
0
 def _get_nondeprecated_tags(self):
     """ Use the parent tags
     """
     return IThemeTagging(self.parent).nondeprecated_tags
Exemple #19
0
 def _get_tags(self):
     """ Use the parent tags
     """
     return IThemeTagging(self.parent).tags
Exemple #20
0
 def getThemes(self):
     """ Getter
     """
     tagging = IThemeTagging(self)
     return tagging.tags
Exemple #21
0
 def get(self, instance, **kwargs):
     """ Get from annotation
     """
     return IThemeTagging(instance).tags
Exemple #22
0
 def themes(self):
     """ Themes
     """
     return IThemeTagging(self.context).tags
 def setThemes(self, value, **kw):
     """ Use the tagging adapter to set the themes. """
     value = [val for val in value if val is not None]
     tagging = IThemeTagging(self)
     tagging.tags = value
Exemple #24
0
 def set(self, instance, value, **kwargs):
     """ Save as annotation
     """
     IThemeTagging(instance).tags = [val for val in value if val]