Skip to content

Commit

Permalink
Minor cleanup (pep8, readability, ReST)
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Oct 8, 2015
1 parent f95576c commit b49b806
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 87 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt → CHANGES.rst
Expand Up @@ -4,6 +4,9 @@ Changelog
2.0.4 (unreleased)
------------------

- Minor cleanup (pep8, readability, ReST)
[jensens]

- Fixed problem causing file timestamps to show up incorrectly
[obct537]

Expand Down
10 changes: 4 additions & 6 deletions README.txt → README.rst
@@ -1,9 +1,8 @@
Introduction
============

This package contains resources for integrating ACE (http://ace.ajax.org/) into
Plone, with a file manager that can edit ``plone.resource`` resource directories
in the ZODB.
This package contains resources for integrating `ACE embeddable code editor <http://ace.ajax.org>`_ into Plone.
It provides a file manager that can edit ``plone.resource`` resource directories in the ZODB.

ACE can be found under ``++resource++plone.resourceeditor/ace/*``.

Expand All @@ -15,13 +14,12 @@ and the following in the body::

<metal:block use-macro="resourceDirectory/@@plone.resourceeditor.filemanager/macros/filemanager">

In both of these cases, ``resourceDirectory`` should be an in-ZODB
``plone.resource`` resource directory instance.
In both of these cases, ``resourceDirectory`` should be an in-ZODB ``plone.resource`` resource directory instance.

The macros assume that jQuery is already loaded.


Versions
========

2.x is for Plone 5.0 and up.
2.x is for Plone 5.0 and up.
8 changes: 2 additions & 6 deletions plone/__init__.py
@@ -1,6 +1,2 @@
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError: # pragma: no cover
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# -*- coding: utf-8 -*-
__import__('pkg_resources').declare_namespace(__name__)
78 changes: 44 additions & 34 deletions plone/resourceeditor/browser.py
@@ -1,25 +1,25 @@
import json
import os.path
import re
from time import localtime, strftime
import urllib
from urlparse import urlparse

# -*- coding: utf-8 -*-
from AccessControl import Unauthorized
from OFS.Image import File, Image
from plone.resource.file import FilesystemFile
from plone.resource.interfaces import IResourceDirectory
from Products.CMFCore.utils import getToolByName
from Products.Five.browser.decode import processInputs
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from plone.resource.file import FilesystemFile
from plone.resource.interfaces import IResourceDirectory
import posixpath
from time import localtime, strftime
from urlparse import urlparse
from zExceptions import NotFound
from zope.cachedescriptors import property
from zope.cachedescriptors import property as zproperty
from zope.component import queryMultiAdapter
from zope.component.hooks import getSite
from zope.i18n import translate
from zope.i18nmessageid import MessageFactory
from zope.publisher.browser import BrowserView
import json
import os.path
import posixpath
import re
import urllib

_ = MessageFactory(u"plone")

Expand All @@ -42,7 +42,7 @@ class FileManagerActions(BrowserView):
imageExtensions = ['png', 'gif', 'jpg', 'jpeg', 'ico']
previewTemplate = ViewPageTemplateFile('preview.pt')

@property.Lazy
@zproperty.Lazy
def resourceDirectory(self):
return self.context

Expand All @@ -63,10 +63,7 @@ def getExtension(self, obj=None, path=None):
return ext

def getFile(self, path):

path = path.encode('utf-8')

path = self.normalizePath(path)
path = self.normalizePath(path.encode('utf-8'))
ext = self.getExtension(path=path)
result = {'ext': ext}
self.request.response.setHeader('Content-Type', 'application/json')
Expand Down Expand Up @@ -128,13 +125,12 @@ def getInfo(self, obj, path='/'):
size = 0

if isinstance(obj, File):
properties['dateModified'] = obj.bobobase_modification_time().strftime('%c')
properties['dateModified'] = obj.bobobase_modification_time().strftime('%c') # noqa
size = obj.get_size() / 1024

fileType = self.getExtension(obj)
if isinstance(obj, FilesystemFile):
stats = os.stat(obj.path)
created = localtime(stats.st_ctime)
modified = localtime(stats.st_mtime)
properties['dateModified'] = strftime('%c', modified)
size = stats.st_size / 1024
Expand Down Expand Up @@ -177,8 +173,10 @@ def saveFile(self, path, value):
reg = re.compile('url\(([^)]+)\)')
urls = reg.findall(value)

# Trim off the @@plone.resourceeditor bit to just give us the theme url
location = self.request.URL[0:self.request.URL.find('@@plone.resourceeditor')]
# Trim off the @@plone.resourceeditor bit to just give us the
# theme url
limit = self.request.URL.find('@@plone.resourceeditor')
location = self.request.URL[0:limit]
base = urlparse(location)
for url in urls:
asset = urlparse(url.strip("'").strip('"'))
Expand Down Expand Up @@ -230,8 +228,12 @@ def addFolder(self, path, name):
parent.makeDirectory(name)
except UnicodeDecodeError:
error = translate(
_(u'filemanager_invalid_foldername',
default=u"Invalid folder name."), context=self.request)
_(
u'filemanager_invalid_foldername',
default=u"Invalid folder name."
),
context=self.request
)
code = 1

self.request.response.setHeader('Content-Type', 'application/json')
Expand All @@ -240,7 +242,7 @@ def addFolder(self, path, name):
'name': name,
'error': error,
'code': code,
})
})

def addFile(self, path, name):
"""Add a new empty file in the given directory
Expand Down Expand Up @@ -343,8 +345,11 @@ def renameFile(self, path, newName):
if newName != oldName:
if newName in parent:
error = translate(
_(u'filemanager_error_file_exists',
default=u"File already exists."), context=self.request)
_(
u'filemanager_error_file_exists',
default=u"File already exists."
),
context=self.request)
code = 1
else:
parent.rename(oldName, newName)
Expand Down Expand Up @@ -413,6 +418,7 @@ def getDirectory(folder, relpath=''):
path = self.request.get("path", '')
return self.delete(path)


class FileManager(BrowserView):
"""Render the file manager and support its AJAX requests.
"""
Expand Down Expand Up @@ -526,28 +532,28 @@ def __call__(self):
def setup(self):
processInputs(self.request)

@property.Lazy
@zproperty.Lazy
def portalUrl(self):
return getToolByName(self.context, 'portal_url')()

@property.Lazy
@zproperty.Lazy
def resourceDirectory(self):
return self.context

@property.Lazy
@zproperty.Lazy
def resourceType(self):
return self.resourceDirectory.__parent__.__parent__.__name__

@property.Lazy
@zproperty.Lazy
def baseUrl(self):
return "%s/++%s++%s" % (self.portalUrl, self.resourceType,
self.resourceDirectory.__name__)

@property.Lazy
@zproperty.Lazy
def fileConnector(self):
return "%s/@@%s" % (self.baseUrl, self.__name__,)

@property.Lazy
@zproperty.Lazy
def filemanagerConfiguration(self):
return """\
var FILE_ROOT = '/';
Expand Down Expand Up @@ -635,7 +641,7 @@ def getInfo(self, path, getSize=False):
}

if isinstance(obj, File):
properties['dateModified'] = obj.bobobase_modification_time().strftime('%c')
properties['dateModified'] = obj.bobobase_modification_time().strftime('%c') # noqa
size = obj.get_size() / 1024
if size < 1024:
size_specifier = u'kb'
Expand Down Expand Up @@ -721,8 +727,12 @@ def addFolder(self, path, name):
parent.makeDirectory(name)
except UnicodeDecodeError:
error = translate(
_(u'filemanager_invalid_foldername',
default=u"Invalid folder name."), context=self.request)
_(
u'filemanager_invalid_foldername',
default=u"Invalid folder name."
),
context=self.request
)
code = 1

return {
Expand Down
20 changes: 13 additions & 7 deletions plone/resourceeditor/testing.py
@@ -1,8 +1,8 @@
from plone.app.testing import PloneSandboxLayer
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import IntegrationTesting
# -*- coding: utf-8 -*-
from plone.app.testing import applyProfile

from plone.app.testing import IntegrationTesting
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import PloneSandboxLayer
from zope.configuration import xmlconfig


Expand All @@ -12,12 +12,18 @@ class PloneResourceEditor(PloneSandboxLayer):
def setUpZope(self, app, configurationContext):
# Load ZCML
import plone.resourceeditor
xmlconfig.file('configure.zcml', plone.resourceeditor, context=configurationContext)
xmlconfig.file(
'configure.zcml',
plone.resourceeditor,
context=configurationContext
)

def setUpPloneSite(self, portal):
# install plone.resource
applyProfile(portal, 'plone.resource:default')

PLONE_RESOURCE_EDITOR_FIXTURE = PloneResourceEditor()
PLONE_RESOURCE_EDITOR_INTEGRATION_TESTING = \
IntegrationTesting(bases=(PLONE_RESOURCE_EDITOR_FIXTURE,), name="plone.resourceeditor:Integration")
PLONE_RESOURCE_EDITOR_INTEGRATION_TESTING = IntegrationTesting(
bases=(PLONE_RESOURCE_EDITOR_FIXTURE,),
name="plone.resourceeditor:Integration"
)
4 changes: 2 additions & 2 deletions plone/resourceeditor/tests.py
@@ -1,6 +1,6 @@
import unittest2 as unittest

# -*- coding: utf-8 -*-
from plone.resourceeditor.testing import PLONE_RESOURCE_EDITOR_INTEGRATION_TESTING
import unittest2 as unittest


class TestResourceEditorOperations(unittest.TestCase):
Expand Down
68 changes: 36 additions & 32 deletions setup.py
Expand Up @@ -2,36 +2,40 @@

version = '2.0.4.dev0'

setup(name='plone.resourceeditor',
version=version,
description="Integrates ACE editor into Plone",
long_description=open("README.txt").read() + "\n" +
open("CHANGES.txt").read(),
classifiers=[
"Framework :: Plone",
"Programming Language :: Python",
],
keywords='',
author='',
author_email='',
url='https://github.com/plone/plone.resourceeditor',
license='GPL',
packages=find_packages(exclude=['ez_setup']),
namespace_packages=['plone'],
include_package_data=True,
zip_safe=False,
install_requires=[
'setuptools',
'zope.interface',
'zope.component',
'zope.publisher',
'zope.schema',
'plone.resource',
'Zope2',
setup(
name='plone.resourceeditor',
version=version,
description="Integrates ACE editor into Plone",
long_description=(
open("README.rst").read() +
"\n" +
open("CHANGES.rst").read()
),
classifiers=[
"Framework :: Plone",
"Programming Language :: Python",
],
extras_require = {
'test': ['plone.app.testing']
},
entry_points="""
""",
)
keywords='',
author='',
author_email='',
url='https://github.com/plone/plone.resourceeditor',
license='GPL',
packages=find_packages(exclude=['ez_setup']),
namespace_packages=['plone'],
include_package_data=True,
zip_safe=False,
install_requires=[
'plone.resource',
'setuptools',
'zope.component',
'zope.interface',
'zope.publisher',
'zope.schema',
'Zope2',
],
extras_require={
'test': ['plone.app.testing']
},
entry_points="""
""",
)

0 comments on commit b49b806

Please sign in to comment.