Skip to content

Commit

Permalink
black plonish
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Feb 9, 2019
1 parent cb219ba commit e6f8313
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 121 deletions.
87 changes: 57 additions & 30 deletions bootstrap-buildout.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,42 @@
parser = OptionParser(usage=usage)
parser.add_option("-v", "--version", help="use a specific zc.buildout version")

parser.add_option("-t", "--accept-buildout-test-releases",
dest='accept_buildout_test_releases',
action="store_true", default=False,
help=("Normally, if you do not specify a --version, the "
"bootstrap script and buildout gets the newest "
"*final* versions of zc.buildout and its recipes and "
"extensions for you. If you use this flag, "
"bootstrap and buildout will get the newest releases "
"even if they are alphas or betas."))
parser.add_option("-c", "--config-file",
help=("Specify the path to the buildout configuration "
"file to be used."))
parser.add_option("-f", "--find-links",
help=("Specify a URL to search for buildout releases"))
parser.add_option("--allow-site-packages",
action="store_true", default=False,
help=("Let bootstrap.py use existing site packages"))
parser.add_option("--setuptools-version",
help="use a specific setuptools version")
parser.add_option(
"-t",
"--accept-buildout-test-releases",
dest='accept_buildout_test_releases',
action="store_true",
default=False,
help=(
"Normally, if you do not specify a --version, the "
"bootstrap script and buildout gets the newest "
"*final* versions of zc.buildout and its recipes and "
"extensions for you. If you use this flag, "
"bootstrap and buildout will get the newest releases "
"even if they are alphas or betas."
),
)
parser.add_option(
"-c",
"--config-file",
help=(
"Specify the path to the buildout configuration " "file to be used."
),
)
parser.add_option(
"-f",
"--find-links",
help=("Specify a URL to search for buildout releases"),
)
parser.add_option(
"--allow-site-packages",
action="store_true",
default=False,
help=("Let bootstrap.py use existing site packages"),
)
parser.add_option(
"--setuptools-version", help="use a specific setuptools version"
)


options, args = parser.parse_args()
Expand All @@ -89,6 +106,7 @@
# this will remove them from the path to ensure that incompatible versions
# of setuptools are not in the path
import site

# inside a virtualenv, there is no 'getsitepackages'.
# We can't remove these reliably
if hasattr(site, 'getsitepackages'):
Expand All @@ -113,27 +131,36 @@

ws = pkg_resources.working_set

cmd = [sys.executable, '-c',
'from setuptools.command.easy_install import main; main()',
'-mZqNxd', tmpeggs]
cmd = [
sys.executable,
'-c',
'from setuptools.command.easy_install import main; main()',
'-mZqNxd',
tmpeggs,
]

find_links = os.environ.get(
'bootstrap-testing-find-links',
options.find_links or
('http://downloads.buildout.org/'
if options.accept_buildout_test_releases else None)
)
options.find_links
or (
'http://downloads.buildout.org/'
if options.accept_buildout_test_releases
else None
),
)
if find_links:
cmd.extend(['-f', find_links])

setuptools_path = ws.find(
pkg_resources.Requirement.parse('setuptools')).location
pkg_resources.Requirement.parse('setuptools')
).location

requirement = 'zc.buildout'
version = options.version
if version is None and not options.accept_buildout_test_releases:
# Figure out the most recent final version of zc.buildout.
import setuptools.package_index

_final_parts = '*final-', '*final'

def _final_version(parsed_version):
Expand All @@ -147,7 +174,8 @@ def _final_version(parsed_version):
return True

index = setuptools.package_index.PackageIndex(
search_path=[setuptools_path])
search_path=[setuptools_path]
)
if find_links:
index.add_find_links((find_links,))
req = pkg_resources.Requirement.parse(requirement)
Expand All @@ -170,8 +198,7 @@ def _final_version(parsed_version):
cmd.append(requirement)

if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0:
raise Exception(
"Failed to execute command:\n%s" % repr(cmd)[1:-1])
raise Exception("Failed to execute command:\n%s" % repr(cmd)[1:-1])

######################################################################
# Import and run buildout
Expand Down
17 changes: 8 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@


long_description = (
open('README.rst').read()
+ '\n' +
'Contributors\n'
open('README.rst').read() + '\n' + 'Contributors\n'
'============\n'
+ '\n' +
open('CONTRIBUTORS.rst').read()
+ '\n' +
open('CHANGES.rst').read()
+ '\n')
+ '\n'
+ open('CONTRIBUTORS.rst').read()
+ '\n'
+ open('CHANGES.rst').read()
+ '\n'
)


setup(
Expand Down Expand Up @@ -52,7 +51,7 @@
'plone.app.testing',
'plone.app.contenttypes',
'plone.app.robotframework[debug]',
],
]
},
entry_points="""
[z3c.autoinclude.plugin]
Expand Down
6 changes: 4 additions & 2 deletions src/collective/isotope/browser/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ class IsotopeSettingsControlpanelForm(controlpanel.RegistryEditForm):

schema = ICollectiveIsotopeSettings
label = _(u'Isotope View Settings')
description = _(u'Site-wide settings to control the Isotope View for '
u'collections and folders')
description = _(
u'Site-wide settings to control the Isotope View for '
u'collections and folders'
)

def updateFields(self):
super(IsotopeSettingsControlpanelForm, self).updateFields()
Expand Down
21 changes: 11 additions & 10 deletions src/collective/isotope/browser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from itertools import ifilter
from itertools import imap
from itertools import izip

# from plone import api
from plone.app.contenttypes.browser.collection import CollectionView
from plone.app.contenttypes.browser.folder import FolderView
Expand Down Expand Up @@ -38,7 +39,9 @@
class IsotopeViewConfigurationForm(form.Form):
fields = field.Fields(ICollectiveIsotopeViewSettings)
label = _(u"Isotope View Configuration")
description = _(u"Configuration of layout, filters, and sorting for this view")
description = _(
u"Configuration of layout, filters, and sorting for this view"
)

def getContent(self):
annotations = IAnnotations(self.context)
Expand All @@ -60,6 +63,7 @@ def handleApply(self, action):
messages = IStatusMessage(self.request)
messages.add(_(u"Your configuration has been saved"), type=u"info")


IsotopeConfigurationView = wrap_form(IsotopeViewConfigurationForm)


Expand All @@ -73,6 +77,7 @@ def call_or_attr(obj, name):
value = value()
return value


def itemize(value):
"""return value one item at a time from a generator
Expand All @@ -82,8 +87,9 @@ def itemize(value):
one at a time
If value is a dict type, return the keys one at a time
"""
if (not isinstance(value, basestring) and
isinstance(value, collections.Iterable)):
if not isinstance(value, basestring) and isinstance(
value, collections.Iterable
):
for item in value:
yield item
else:
Expand All @@ -98,9 +104,7 @@ class IsotopeViewMixin(object):
def settings_dict(self):
registry = getUtility(IRegistry)
isotope_settings = registry.forInterface(ICollectiveIsotopeSettings)
settings = {
'itemSelector': '.isotope-item',
}
settings = {'itemSelector': '.isotope-item'}
names = ICollectiveIsotopeLayoutSettings.names()
for name in names:
value = getattr(isotope_settings, name, _marker)
Expand Down Expand Up @@ -157,10 +161,7 @@ class to which this mixin is added.
continue
values = self._get_filter_values(filter, raw)
label = self._get_filter_label(filter)
results[filter] = {
'label': label,
'values': values,
}
results[filter] = {'label': label, 'values': values}
return results

def filters_for_item(self, result):
Expand Down
77 changes: 47 additions & 30 deletions src/collective/isotope/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class IValueConverter(Interface):
metadata column into a human readable value suitable for presentation in a
UI.
"""

def convert(value):
"""Convert a give value into a human readable value
Expand Down Expand Up @@ -49,8 +50,11 @@ def _validate(self, value):
if isinstance(ftype, tuple):
ftype = ftype[0]
# Perform a naive type coercion
if (fvalue is not NO_VALUE and
ftype is not None and not isinstance(fvalue, ftype)):
if (
fvalue is not NO_VALUE
and ftype is not None
and not isinstance(fvalue, ftype)
):
if ftype is bool and fvalue.lower() == 'false':
fvalue = False
try:
Expand All @@ -70,58 +74,66 @@ class IFilterSchema(Interface):
description=_(u'Enter the name of a catalog metadata column'),
vocabulary='collective.isotope.vocabularies.friendly_columns',
required=False,
missing_value=u''
missing_value=u'',
)
label = field.TextLine(
title=_(u'Label'),
description=_(
u'If desired, enter the human-readable label for this column'
),
required=False,
missing_value=u''
missing_value=u'',
)


class ICollectiveIsotopeFilterSettings(Interface):
"""Settings to control filtering options"""

available_filters = schema.List(
title=_(u'Available Filters'),
description=_(u'List the filters that will be available for Istotope '
u'views throughout your site.'),
description=_(
u'List the filters that will be available for Istotope '
u'views throughout your site.'
),
value_type=ImportableTextDictRow(
title=_(u'Filter'),
schema=IFilterSchema
)
title=_(u'Filter'), schema=IFilterSchema
),
)

available_sorts = schema.List(
title=_(u'Available Sorts'),
description=_(u'List the sortable attributes that will be available '
u'for Istotope views throughout your site.'),
description=_(
u'List the sortable attributes that will be available '
u'for Istotope views throughout your site.'
),
value_type=ImportableTextDictRow(
title=_(u'Sort'),
schema=IFilterSchema
)
title=_(u'Sort'), schema=IFilterSchema
),
)


class ICollectiveIsotopeLayoutSettings(Interface):
"""Settings for the options that control the javascript Isotope library
"""

layoutMode = schema.Choice(
title=_(u'Layout Mode'),
description=_(u'Select the default layout mode to be used on all '
u'isotope views throughout your website'),
description=_(
u'Select the default layout mode to be used on all '
u'isotope views throughout your website'
),
values=[u'masonry', u'fitRows', u'vertical'],
default=u'masonry'
default=u'masonry',
)

percentPosition = schema.Bool(
title=_(u'Use percentPosition'),
description=_(u'Set the horizontal position of items by percent '
u'rather than pixel size. This works best with items '
u'that are sized by percentage. On by default'),
default=True
description=_(
u'Set the horizontal position of items by percent '
u'rather than pixel size. This works best with items '
u'that are sized by percentage. On by default'
),
default=True,
)


Expand All @@ -133,24 +145,29 @@ class ICollectiveIsotopeSettings(

class ICollectiveIsotopeViewSettings(Interface):
"""Settings for configuration of individual views"""

filter = schema.List(
title=_(u'Filtering'),
description=_(u'Select the ttributes on which users will be able to '
u'filter the items listed in this view. If no values '
u'are selected, user filtering will be disabled'),
description=_(
u'Select the ttributes on which users will be able to '
u'filter the items listed in this view. If no values '
u'are selected, user filtering will be disabled'
),
required=False,
value_type=schema.Choice(
vocabulary='collective.isotope.vocabularies.available_filters',
)
vocabulary='collective.isotope.vocabularies.available_filters'
),
)

sort = schema.List(
title=_(u'Sorting'),
description=_(u'Select the attributes on which users will be able to '
u'sort the items listed in this view. If no value is '
u'selected, user sorting will be disabled.'),
description=_(
u'Select the attributes on which users will be able to '
u'sort the items listed in this view. If no value is '
u'selected, user sorting will be disabled.'
),
required=False,
value_type=schema.Choice(
vocabulary='collective.isotope.vocabularies.available_sorts'
)
),
)
Loading

0 comments on commit e6f8313

Please sign in to comment.