Skip to content

Commit

Permalink
move imaging control panel to cmfplone
Browse files Browse the repository at this point in the history
  • Loading branch information
vangheem committed May 7, 2015
1 parent f90d939 commit 5c504d9
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 64 deletions.
10 changes: 10 additions & 0 deletions Products/CMFPlone/controlpanel/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
xmlns:five="http://namespaces.zope.org/five"
xmlns:browser="http://namespaces.zope.org/browser">

<!-- needed for control panel permission -->
<include package="plone.app.imaging" />

<permission id="plone.app.controlpanel.TinyMCE"
title="Plone Site Setup: TinyMCE">
<role name="Manager"/>
Expand Down Expand Up @@ -232,4 +235,11 @@
permission="cmf.ManagePortal"
/>

<browser:page
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
name="imaging-controlpanel"
class=".imaging.ImagingControlPanel"
permission="plone.app.controlpanel.Imaging"
/>

</configure>
18 changes: 18 additions & 0 deletions Products/CMFPlone/controlpanel/browser/imaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from Products.CMFPlone import PloneMessageFactory as _
from Products.CMFPlone.interfaces.controlpanel import IImagingSchema
from logging import getLogger
from plone.app.registry.browser import controlpanel

log = getLogger('Plone')


class ImagingControlPanelForm(controlpanel.RegistryEditForm):

id = "ImagingSettings"
label = _(u"Image Handling")
schema = IImagingSchema
schema_prefix = "plone"


class ImagingControlPanel(controlpanel.ControlPanelFormWrapper):
form = ImagingControlPanelForm
1 change: 1 addition & 0 deletions Products/CMFPlone/interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from controlpanel import ITinyMCEToolbarSchema
from controlpanel import ITypesSchema
from controlpanel import IUserGroupsSettingsSchema
from controlpanel import IImagingSchema
from events import IConfigurationChangedEvent
from events import IReorderedEvent
from events import ISiteManagerCreatedEvent
Expand Down
30 changes: 30 additions & 0 deletions Products/CMFPlone/interfaces/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1386,3 +1386,33 @@ class IUserGroupsSettingsSchema(Interface):
u"listing all of them."),
default=False
)


class IImagingSchema(Interface):
allowed_sizes = schema.List(
title=_(u'Allowed image sizes'),
description=_(u'Specify all allowed maximum image dimensions, '
'one per line. '
'The required format is <name> <width>:<height>.'),
value_type=schema.TextLine(),
default=[
"large 768:768",
"preview 400:400",
"mini 200:200",
"thumb 128:128",
"tile 64:64",
"icon 32:32",
"listing 16:16"],
required=False,
)

quality = schema.Int(
title=_(u'Scaled image quality'),
description=_(u'A value for the quality of scaled images, from 1 '
'(lowest) to 95 (highest). A value of 0 will mean '
'plone.scaling\'s default will be used, which is '
'currently 88.'),
min=0,
max=95,
default=88
)
7 changes: 7 additions & 0 deletions Products/CMFPlone/profiles/default/controlpanel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,11 @@
i18n:attributes="title">
<permission>Plone Site Setup: TinyMCE</permission>
</configlet>
<configlet title="Image Handling" action_id="ImagingSettings" appId="ImagingSettings"
category="Products" condition_expr=""
icon_expr="string:$portal_url/image_icon.png"
url_expr="string:${portal_url}/@@imaging-controlpanel" visible="True"
i18n:attributes="title">
<permission>Plone Site Setup: Imaging</permission>
</configlet>
</object>
2 changes: 1 addition & 1 deletion Products/CMFPlone/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<metadata>
<version>5004</version>
<version>5005</version>
</metadata>
13 changes: 0 additions & 13 deletions Products/CMFPlone/profiles/default/propertiestool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,4 @@
<property name="external_logout_url" type="string"/>
<property name="external_login_iframe" type="boolean"/>
</object>
<object name="imaging_properties" meta_type="Plone Property Sheet">
<property name="title">Image handling properties</property>
<property name="allowed_sizes" type="lines">
<element value="large 768:768"/>
<element value="preview 400:400"/>
<element value="mini 200:200"/>
<element value="thumb 128:128"/>
<element value="tile 64:64"/>
<element value="icon 32:32"/>
<element value="listing 16:16"/>
</property>
<property name="quality" type="int">88</property>
</object>
</object>
2 changes: 2 additions & 0 deletions Products/CMFPlone/profiles/dependencies/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
prefix="plone" />
<records interface="Products.CMFPlone.interfaces.IUserGroupsSettingsSchema"
prefix="plone" />
<records interface="Products.CMFPlone.interfaces.IImagingSchema"
prefix="plone" />
<record interface="Products.ResourceRegistries.interfaces.settings.IResourceRegistriesSettings" field="resourceBundlesForThemes">
<value purge="false">
<element key="(default)">
Expand Down
79 changes: 29 additions & 50 deletions Products/CMFPlone/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from zope.deprecation import deprecated
from zope.i18n import translate
from zope.publisher.interfaces.browser import IBrowserRequest
from zope import schema

import OFS
from AccessControl import getSecurityManager, Unauthorized
Expand All @@ -30,10 +31,10 @@
from App.ImageFile import ImageFile
from DateTime import DateTime
from DateTime.interfaces import DateTimeError
from Products.CMFCore.interfaces import IPropertiesTool
from Products.CMFCore.permissions import ManageUsers
from Products.CMFCore.utils import ToolInit as CMFCoreToolInit
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone import PloneMessageFactory as _

import transaction

Expand Down Expand Up @@ -62,8 +63,8 @@

# Log methods
from log import log
from log import log_exc
from log import log_deprecated
from log import log_exc # noqa
from log import log_deprecated # noqa

This comment has been minimized.

Copy link
@mauritsvanrees

mauritsvanrees Oct 1, 2015

Member

@vangheem Which tool is actually influenced by this noqa comment? It has no effect for pyflakes or pep8, at least not the way I have set it up.

When an import like this is not used, which pyflakes complains about, but we still want to keep it, I always add a line that simply mentions the import. And I add a comment # pyflakes at this new line, which has no influence on any tools, but only serves as an explanation for developers on why this line is there. So:

from log import log_exc
log_exc  # pyflakes

I have also seen the following in other files:

from my.package import unused_import  # nopep8

This also has no effect on tools that I know. If pep8 listens to this, then that is nice, but pyflakes will still warn that the import is unused.

I am just wondering if I am missing some other tool, or a different way of setting things up.

This comment has been minimized.

Copy link
@thet

thet Oct 1, 2015

Member

I confirm, for pyflakes the # noqa line has no effect. I have configured syntastic in vim to use flake8 ( https://pypi.python.org/pypi/flake8 ), which combines pyflakes, pep8 and some McCabe complexity checkers. For flake8, # noqa works fine. I'm quite happy with flake8.
We should define the preferred way for code checking in https://github.com/plone/plone.api/blob/master/docs/contribute/conventions.rst (or are the conventions meanwhile managed somewhere else? /cc @svx )

This comment has been minimized.

Copy link
@tisto

tisto Oct 1, 2015

Member

We should use/recommend flake8 and make #noqa the standard.


_marker = []

Expand Down Expand Up @@ -125,7 +126,7 @@ def isIDAutoGenerated(context, id):

pt = getToolByName(context, 'portal_types')
portaltypes = pt.listContentTypes()
portaltypes.extend([pt.lower() for pt in portaltypes])
portaltypes.extend([t.lower() for t in portaltypes])

try:
parts = id.split('.')
Expand All @@ -135,8 +136,7 @@ def isIDAutoGenerated(context, id):
type = ' '.join(obj_type.split('_'))
# New autogenerated ids may have a lower case portal type
if ((type in portaltypes or obj_type in portaltypes) and
DateTime(date_created) and
float(random_number)):
DateTime(date_created) and float(random_number)):
return True
except (ValueError, AttributeError, IndexError, DateTimeError):
pass
Expand Down Expand Up @@ -182,9 +182,9 @@ def pretty_title_or_id(context, obj, empty_value=_marker):
of whether obj is a catalog brain or an object, but returning an
empty title marker if the id is not set (i.e. it's auto-generated).
"""
#if safe_hasattr(obj, 'aq_explicit'):
# if safe_hasattr(obj, 'aq_explicit'):
# obj = obj.aq_explicit
#title = getattr(obj, 'Title', None)
# title = getattr(obj, 'Title', None)
title = None
if base_hasattr(obj, 'Title'):
title = getattr(obj, 'Title', None)
Expand Down Expand Up @@ -561,20 +561,20 @@ def _unrestricted_rename(container, id, new_id):
try:
container._checkId(new_id)
except:
raise CopyError, MessageDialog(
title='Invalid Id',
message=sys.exc_info()[1],
action='manage_main')
raise CopyError(MessageDialog(
title='Invalid Id',
message=sys.exc_info()[1],
action='manage_main'))
ob = container._getOb(id)
if not ob.cb_isMoveable():
raise CopyError, eNotSupported % escape(id)
raise CopyError(eNotSupported % escape(id))
try:
ob._notifyOfCopyTo(container, op=1)
except:
raise CopyError, MessageDialog(
title='Rename Error',
message=sys.exc_info()[1],
action='manage_main')
raise CopyError(MessageDialog(
title='Rename Error',
message=sys.exc_info()[1],
action='manage_main'))
container._delObject(id)
ob = aq_base(ob)
ob._setId(new_id)
Expand Down Expand Up @@ -677,40 +677,8 @@ def set_own_login_name(member, loginname):
pas.updateLoginName(member.getId(), loginname)


def getAllowedSizes():
"""Get image-scale sizes.
"""
ptool = queryUtility(IPropertiesTool)
if ptool is None:
return None
props = getattr(ptool, 'imaging_properties', None)
if props is None:
return None
sizes = {}
for line in props.getProperty('allowed_sizes'):
line = line.strip()
if line:
name, width, height = pattern.match(line).groups()
name = name.strip().replace(' ', '_')
sizes[name] = int(width), int(height)
return sizes


def getQuality():
"""Get quality used in image-scaling
"""
ptool = queryUtility(IPropertiesTool)
if ptool:
props = getattr(ptool, 'imaging_properties', None)
if props:
quality = props.getProperty('quality')
if quality:
return quality
return QUALITY_DEFAULT


def ajax_load_url(url):
if url and not 'ajax_load' in url:
if url and 'ajax_load' not in url:
sep = '?' in url and '&' or '?' # url parameter seperator
url = '%s%sajax_load=1' % (url, sep)
return url
Expand Down Expand Up @@ -746,3 +714,14 @@ def bodyfinder(text):
if bodyend == -1:
return text
return text[bodystart:bodyend]


# XXX nasty? better than re-writting same method. Circular import issues here
def getAllowedSizes():
from plone.app.imaging.utils import getAllowedSizes as func
return func()


def getQuality():
from plone.app.imaging.utils import getQuality as func
return func()

0 comments on commit 5c504d9

Please sign in to comment.