Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable manual sorting of selected taxonomy items #74

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ share/
include/
lib/
share/
pyvenv.cfg
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Changes
- Integrate taxonomies into collective.collectionfilter
[MrTango]

- add ``moveUp/Down`` functionality to widget
[petschki]


2.0.1 (2020-07-04)
------------------
Expand Down Expand Up @@ -45,6 +48,10 @@ Changes
- add uninstall handler to cleanup persistent utilites and generated behaviors
[petschki]

- simplify utility.py to always ensure items order. imported data is always
appended at the end of existing taxonomies
[petschki]

- Fix GenericSetup import/export in python3
[erral]

Expand Down
6 changes: 6 additions & 0 deletions base.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[buildout]
extensions = mr.developer
versions = versions

[code-analysis]
directory= ${buildout:directory}/src/collective/taxonomy
9 changes: 0 additions & 9 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,7 @@ recipe = zc.recipe.egg
eggs = zest.releaser[recommended]

[code-analysis]
recipe = plone.recipe.codeanalysis
directory = ${buildout:directory}/src/collective/taxonomy
pre-commit-hook = False
flake8-ignore = E501,C901
debug-statements = True
deprecated-aliases = True
imports = True
prefer-single-quotes = True
return-status-codes = False
utf8-header = True

[versions]
setuptools =
Expand Down
9 changes: 2 additions & 7 deletions src/collective/taxonomy/exportimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from collective.taxonomy.interfaces import ITaxonomy
from collective.taxonomy.vdex import ExportVdex
from collective.taxonomy.vdex import ImportVdex
from io import StringIO
from io import BytesIO
from lxml.etree import fromstring
from plone.behavior.interfaces import IBehavior
from six.moves import configparser
Expand All @@ -18,7 +16,7 @@ def parseConfigFile(data):
except Exception as exception:
raise exception

config.readfp(StringIO(data.decode("utf-8")))
config.readfp(six.StringIO(data.decode('utf-8')))
return config


Expand Down Expand Up @@ -111,10 +109,7 @@ def exportTaxonomy(context):
if value:
config.set("taxonomy", name, str(value).lower())

if six.PY3:
filehandle = StringIO()
else:
filehandle = BytesIO()
filehandle = six.StringIO()
config.write(filehandle)
context.writeDataFile(
"taxonomies/" + short_name + ".cfg", filehandle.getvalue(), "text/plain"
Expand Down
4 changes: 4 additions & 0 deletions src/collective/taxonomy/profiles/examples/types.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<object meta_type="Plone Types Tool" name="portal_types">
<object meta_type="Dexterity FTI" name="Document" />
</object>
6 changes: 6 additions & 0 deletions src/collective/taxonomy/profiles/examples/types/Document.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<object name="Document" meta_type="Dexterity FTI" i18n:domain="plone" xmlns:i18n="http://xml.zope.org/namespaces/i18n">
<property name="behaviors" purge="false">
<element value="collective.taxonomy.generated.test" />
</property>
</object>
1 change: 1 addition & 0 deletions src/collective/taxonomy/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
additional_z2_products=["Products.DateRecurringIndex"],
)


INTEGRATION_TESTING = IntegrationTesting(
bases=(FIXTURE,), name="TaxonomyFixture:Integration"
)
Expand Down
44 changes: 44 additions & 0 deletions src/collective/taxonomy/tests/test_edit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
from collective.taxonomy.testing import FUNCTIONAL_TESTING
from plone import api
from plone.app.testing.interfaces import SITE_OWNER_NAME
from plone.app.testing.interfaces import SITE_OWNER_PASSWORD
import unittest
from transaction import commit
from plone.testing.z2 import Browser


class TestEditing(unittest.TestCase):
"""Test Taxonomy Editing"""

layer = FUNCTIONAL_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.document = api.content.create(
container=self.portal, type='Document', title='Doc')
self.browser = Browser(self.layer['app'])
self.browser.handleErrors = False
self.browser.addHeader(
'Authorization', 'Basic {0}:{1}'.format(
SITE_OWNER_NAME, SITE_OWNER_PASSWORD))
commit()

def test_edit_doc(self):
self.browser.open(self.portal.absolute_url() + '/doc/edit')

# check for editing buttons
self.assertIn(
'name="form.widgets.test.taxonomy_test.from"',
self.browser.contents)
self.assertIn(
'name="form.widgets.test.taxonomy_test.to"',
self.browser.contents)
self.assertIn('name="from2toButton"', self.browser.contents)
self.assertIn('name="to2fromButton"', self.browser.contents)
self.assertIn('name="moveUpButton"', self.browser.contents)
self.assertIn('name="moveDownButton"', self.browser.contents)

tax_from = self.browser.getControl(
name='form.widgets.test.taxonomy_test.from')
self.assertEqual(tax_from.options, ['1', '2', '3', '5'])
8 changes: 1 addition & 7 deletions src/collective/taxonomy/tests/test_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.registry.interfaces import IRegistry
from plone.schemaeditor.utils import FieldAddedEvent
from plone.schemaeditor.utils import IEditableSchema
from zope import schema
from zope.component import queryUtility
from zope.event import notify
from zope.lifecycleevent import ObjectAddedEvent
import unittest


Expand Down Expand Up @@ -50,8 +45,7 @@ def test_indexer_with_field(self):

self.document.taxonomy_test = []
self.document.reindexObject()
query = {}
query["taxonomy_test"] = "1"
query = {'taxonomy_test': '1'}
self.assertEqual(len(portal_catalog(query)), 0)

taxo_val = taxonomy["en"][u"\u241fInformation Science\u241fChronology"]
Expand Down
23 changes: 1 addition & 22 deletions src/collective/taxonomy/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,33 +255,12 @@ def fix(path):
% (self.name, version, language)
)

# Make sure we update the modification time.
self.data[language] = tree

# The following structure is used to expunge updated entries.
inv = {}
if not clear:
for i, key in order.items():
inv[key] = i

seen = set()
for key, value in items:
if key in seen:
logger.warning("Duplicate key entry: %r" % (key,))

seen.add(key)
update = key in tree
tree[key] = value
order[count] = key
count += 1

# If we're updating, then we have to pop out the old ordering
# information in order to maintain relative ordering of new items.
if update:
i = inv.get(key)
if i is not None:
del order[i]

self.data[language] = tree
self.count[language] = count

def translate(
Expand Down
50 changes: 28 additions & 22 deletions src/collective/taxonomy/widget_input.pt
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,16 @@ function selectionError() {
tal:content="nocall:entry/content" i18n:translate=""/>
</select>
</td>
</tr>
<tr>
<td style="text-align: center; padding-top: 5px; padding-bottom: 5px;">
<button onclick="javascript:to2from()"
name="to2fromButton" type="button" value="&uarr;"
tal:attributes="onClick string:javascript:to2from('${view/id}')"
>&uarr;</button>
<button onclick="javascript:from2to()"
name="from2toButton" type="button" value="&darr;"
name="from2toButton" type="button" value="&rarr;"
tal:attributes="onClick string:javascript:from2to('${view/id}')"
>&darr;</button>
>&rarr;</button>
<button onclick="javascript:to2from()"
name="to2fromButton" type="button" value="&larr;"
tal:attributes="onClick string:javascript:to2from('${view/id}')"
>&larr;</button>
</td>
</tr>
<tr>
<td style="text-align: right">
<select id="to" name="to" class="" multiple="" size="5" style="width: 100%"
tal:attributes="id string:${view/id}-to;
Expand Down Expand Up @@ -217,20 +213,30 @@ function selectionError() {
tal:attributes="value entry/value"
tal:content="nocall:entry/content" i18n:translate=""/>
</select>
<input name="foo-empty-marker" type="hidden"
tal:attributes="name string:${view/name}-empty-marker"/>
<span id="toDataContainer"
tal:attributes="id string:${view/id}-toDataContainer">
<script type="text/javascript" tal:content="string:
copyDataForSubmit('${view/id}');">
/* <![CDATA[ */
// initial copying of field "field.to" --> "field"
copyDataForSubmit("<i tal:replace="${view/id}"/>");
/* ]]> */
</script>
</span>

</td>
<td>
<button onclick="javascript:to2from()"
name="moveUpButton" type="button" value="&uarr;"
tal:attributes="onClick string:javascript:moveUp('${view/id}')"
>&uarr;</button>
<button onclick="javascript:from2to()"
name="moveDownButton" type="button" value="&darr;"
tal:attributes="onClick string:javascript:moveDown('${view/id}')"
>&darr;</button>
</td>
</tr>
</table>
<input name="foo-empty-marker" type="hidden"
tal:attributes="name string:${view/name}-empty-marker"/>
<span id="toDataContainer"
tal:attributes="id string:${view/id}-toDataContainer">
<script type="text/javascript" tal:content="string:
copyDataForSubmit('${view/id}');">
/* <![CDATA[ */
// initial copying of field "field.to" --> "field"
copyDataForSubmit("<i tal:replace="${view/id}"/>");
/* ]]> */
</script>
</span>
</html>
32 changes: 32 additions & 0 deletions test-5.0.x.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[buildout]
extends =
https://raw.githubusercontent.com/collective/buildout.plonetest/master/test-5.0.x.cfg
https://raw.githubusercontent.com/collective/buildout.plonetest/master/qa.cfg
# https://raw.githubusercontent.com/plone/plone.app.mosaic/master/versions.cfg
base.cfg

parts +=
test
code-analysis
createcoverage

package-name = collective.taxonomy
package-extras = [test]
test-eggs =

[code-analysis]
flake8-ignore = E501,E241

[versions]
setuptools =
zc.buildout =
coverage = >=3.7
plone.app.robotframework = 1.5.0
# We no longer get a versions seperate from coredev buildout for these so have to upgrade them ourselves
robotframework-selenium2screenshots = 0.8.1
robotframework-selenium2library = 3.0.0
robotframework = 3.0.4
robotframework-seleniumlibrary = 3.2.0
robotsuite = 2.0.0
selenium = >=3.4.0
plone.recipe.codeanalysis = 2.3
24 changes: 24 additions & 0 deletions test-5.1.x.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[buildout]
extends =
https://raw.githubusercontent.com/collective/buildout.plonetest/master/test-5.1.x.cfg
https://raw.githubusercontent.com/collective/buildout.plonetest/master/qa.cfg
https://raw.githubusercontent.com/plone/plone.app.robotframework/master/versions.cfg
base.cfg

parts +=
test
code-analysis
createcoverage

package-name = collective.taxonomy
package-extras = [test]
test-eggs =

[code-analysis]
flake8-ignore = E501,E241

[versions]
setuptools =
zc.buildout =
coverage = >=3.7
plone.app.robotframework = 1.5.0
24 changes: 24 additions & 0 deletions test-5.2.x.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[buildout]
extends =
https://raw.githubusercontent.com/collective/buildout.plonetest/master/test-5.2.x.cfg
https://raw.githubusercontent.com/collective/buildout.plonetest/master/qa.cfg
https://raw.githubusercontent.com/plone/plone.app.robotframework/master/versions.cfg
base.cfg

parts +=
test
code-analysis
createcoverage

package-name = collective.taxonomy
package-extras = [test]
test-eggs =

[code-analysis]
flake8-ignore = E501,E241

[versions]
setuptools =
zc.buildout =
coverage = >=3.7
plone.app.robotframework = 1.5.0