Skip to content

Commit

Permalink
Refs #9558 - Moved data annotations to Daviz settings Control Panel
Browse files Browse the repository at this point in the history
  • Loading branch information
avoinea committed Dec 17, 2012
1 parent f3ba22a commit a51b79d
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 27 deletions.
2 changes: 2 additions & 0 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Changelog
----------------------
* Upgrade step: Within "Plone > Site setup > Add-ons" click on
upgrade button available for eea.app.visualization
* Change: Moved data annotations to Daviz settings Control Panel
[voineali refs #9558]
* Change: Cleanup old 'sections' code
[avoinea]
* Feature: Added confirm dialog in order to prevent accidentally disable of
Expand Down
8 changes: 8 additions & 0 deletions eea/app/visualization/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@

from zope.i18nmessageid.message import MessageFactory
EEAMessageFactory = MessageFactory('eea')

DATA_ANNOTATIONS = [
'', 'n/a', 'n.a.', 'na', 'n.a',
'.', ':', '-', '_', '/', '\\', "[]", "{}", "()", "<>", "*",
'empty', "<empty>", 'not set', "<not set>", "notset",
"<notset>", 'none', "<none>", "missing", "<missing>",
'undefined', "<undefined>", "null", "<null>"
]
34 changes: 20 additions & 14 deletions eea/app/visualization/controlpanel/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">

<!-- ZMI Edit view -->
<browser:page
name="zmi_edit_html"
for="*"
class=".davizsettings.DavizSettingsZMIEditForm"
permission="zope2.ViewManagementScreens"
<!-- ZMI Edit view -->
<browser:page
name="zmi_edit_html"
for="*"
class=".davizsettings.DavizSettingsZMIEditForm"
permission="zope2.ViewManagementScreens"
/>

<!-- Control panel -->
<browser:page
name="daviz-settings"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
class=".davizsettings.DavizSettingsControlPanelEditForm"
permission="cmf.ManagePortal"
<!-- Control panel -->
<browser:page
name="daviz-settings"
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
class=".davizsettings.DavizSettingsControlPanelEditForm"
permission="cmf.ManagePortal"
/>

<utility
name="eea.app.visualizations.DataSection"
factory=".controlpanel.DataSection"
/>

</configure>
26 changes: 26 additions & 0 deletions eea/app/visualization/controlpanel/controlpanel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
""" Daviz Settings Section
"""
from zope import schema
from zope.interface import implements
from zope.formlib.form import FormFields
from eea.app.visualization.controlpanel.interfaces import IDavizSection
from eea.app.visualization.config import EEAMessageFactory as _

class DataSection(object):
""" Daviz Settings Section
"""
implements(IDavizSection)
prefix = 'data'
title = 'Data Settings'

def __init__(self):
self.form_fields = FormFields(
schema.Text(
__name__='data.annotations',
title=_(u"Annotations"),
description=_("Data annotations - lowercase - to be "
"ignored/handled as annotations when processing "
"data tables. One per line "
"(e.g. 'n/a', 'n.a.', ':')"),
required=False),
)
7 changes: 4 additions & 3 deletions eea/app/visualization/controlpanel/davizsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ def handle_save_action_daviz(self, saction, data):
value = self.request.get(field_name, None)
self.context.settings[field] = value

self.request.SESSION['messages'] = ["Saved changes. (%s)"
self.request.SESSION['messages'] = ["Saved changes. (%s)"
% (datetime.now())]
self.request.RESPONSE.redirect(self.context.absolute_url() +
self.request.RESPONSE.redirect(self.context.absolute_url() +
'/manage_workspace')


Expand Down Expand Up @@ -133,6 +133,8 @@ def handle_save_action_daviz(self, saction, data):
if self.prefix:
field_name = self.prefix + "." + field
value = self.request.get(field_name, None)
if isinstance(value, (str, unicode)):
value = value.replace('\r\n', '\n')
self.context.settings[field] = value
IStatusMessage(self.request).addStatusMessage(u"Settings saved")
self.request.response.redirect("@@daviz-settings")
Expand All @@ -142,4 +144,3 @@ def handle_cancel_action_daviz(self, saction, data):
""" Cancel action """
IStatusMessage(self.request).addStatusMessage(u"Edit cancelled")
self.request.response.redirect("@@overview-controlpanel")

29 changes: 20 additions & 9 deletions eea/app/visualization/converter/types/guess.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from plone.i18n.normalizer.interfaces import IIDNormalizer
from eea.app.visualization.converter.types.interfaces import IGuessType
from eea.app.visualization.converter.types.interfaces import IGuessTypes
from eea.app.visualization.config import DATA_ANNOTATIONS
from eea.app.visualization.interfaces import IDavizSettings

REGEX = re.compile(r"[\W]+")

Expand Down Expand Up @@ -35,14 +37,21 @@ class GuessTypes(object):
"""
implements(IGuessTypes)

#XXX Move this to ControlPanel
missing = (
'', 'n/a', 'n.a.', 'na', 'n.a',
'.', ':', '-', '_', '/', '\\', "[]", "{}", "()", "<>", "*",
'empty', "<empty>", 'not set', "<not set>", "notset", "<notset>",
'none', "<none>", "missing", "<missing>", 'undefined', "<undefined>",
"null", "<null>"
)
@property
def missing(self):
""" Missing annotations
"""
tool = queryUtility(IDavizSettings)
if not tool:
return set(DATA_ANNOTATIONS)

anno = tool.settings.get('data.annotations')
if anno is None:
return set(DATA_ANNOTATIONS)

anno = set(anno.splitlines())
anno.add('')
return anno

def column_type(self, column):
""" Get column and type from column name
Expand Down Expand Up @@ -111,10 +120,12 @@ def guessBody(self, table, header, output):
utilities = getUtilitiesFor(IGuessType)
utilities = sorted(utilities, cmp=compare)

missing = self.missing

for row in table:
for index, cell in enumerate(row):
# Skip missing values
if cell.lower().strip() in self.missing:
if cell.lower().strip() in missing:
continue

label = header[index]
Expand Down
6 changes: 6 additions & 0 deletions eea/app/visualization/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
IVisualizationEditResources
)

# Settings
from eea.app.visualization.controlpanel.interfaces import IDavizSettings
from eea.app.visualization.controlpanel.interfaces import IDavizSection

__all__ = (
IPossibleVisualization.__name__,
IVisualizationEnabled.__name__,
Expand All @@ -61,4 +65,6 @@
IVisualizationViews.__name__,
IVisualizationViewResources.__name__,
IVisualizationEditResources.__name__,
IDavizSettings.__name__,
IDavizSection.__name__,
)
5 changes: 5 additions & 0 deletions eea/app/visualization/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
handler="eea.app.visualization.upgrades.evolve62.fix_column_labels"
/>

<genericsetup:upgradeStep
title="Add daviz data settings to portal_daviz"
handler="eea.app.visualization.upgrades.evolve62.update_davizSettings"
/>

<genericsetup:upgradeDepends
title="Import profile steps with changes: javascripts"
import_steps="jsregistry"
Expand Down
20 changes: 19 additions & 1 deletion eea/app/visualization/upgrades/evolve62.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
""" Evolve to version 6.2
"""
import logging
from zope.component import queryAdapter
from zope.component import queryAdapter, queryUtility
from zope.component.interface import interfaceToName
from eea.app.visualization.interfaces import IVisualizationConfig
from eea.app.visualization.interfaces import IVisualizationEnabled
from eea.app.visualization.interfaces import IDavizSettings
from eea.app.visualization.config import DATA_ANNOTATIONS
from Products.CMFCore.utils import getToolByName
logger = logging.getLogger("eea.app.visualization.upgrades")

Expand Down Expand Up @@ -36,3 +38,19 @@ def fix_column_labels(context):
if isinstance(config['label'], str):
config['label'] = config['label'].decode('utf-8')
mutator.json = data

def update_davizSettings(context):
""" Add data settings to daviz settings
"""
logger.info('Adding daviz data settings...')
tool = queryUtility(IDavizSettings)
if not tool:
logger.info('Adding daviz data settings... Nothing to do')
return

if tool.settings.get('data.annotations'):
logger.info('Adding daviz data settings... Nothing to do')
return

tool.settings['data.annotations'] = u"\n".join(DATA_ANNOTATIONS)
logger.info('Adding daviz data settings... DONE')

0 comments on commit a51b79d

Please sign in to comment.