Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
smcmahon committed May 23, 2014
0 parents commit 9bff091
Show file tree
Hide file tree
Showing 19 changed files with 633 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.egg-info
*.pyc

10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Introduction
============

Registers an extender for plone.app.discussion commenting fields
that adds a "title" field.

Uses a browserlayer installed via generic setup.

Note: p.a.d already supports titles to some extent. If they're available,
they're used. But they aren't on the forms.
6 changes: 6 additions & 0 deletions collective/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
Binary file not shown.
Binary file added collective/comment_titles/._interfaces.py
Binary file not shown.
5 changes: 5 additions & 0 deletions collective/comment_titles/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- extra stuff goes here -*-


def initialize(context):
"""Initializer called when used as a Zope 2 product."""
53 changes: 53 additions & 0 deletions collective/comment_titles/commentextender.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# http://pythonhosted.org/plone.app.discussion/howtos/howto_extend_the_comment_form.html
# Customized to add "title" rather than "website"

from persistent import Persistent

from z3c.form.field import Fields

from zope import interface
from zope import schema

from zope.annotation import factory
from zope.component import adapts
from zope.interface import Interface
from zope.publisher.interfaces.browser import IDefaultBrowserLayer

from plone.z3cform.fieldsets import extensible

from plone.app.discussion.browser.comments import CommentForm
from plone.app.discussion.comment import Comment


# Interface to define the fields we want to add to the comment form.
class ICommentExtenderFields(Interface):
title = schema.TextLine(title=u"Title", required=False)


# Persistent class that implements the ICommentExtenderFields interface
class CommentExtenderFields(Persistent):
interface.implements(ICommentExtenderFields)
adapts(Comment)
title = u""

# CommentExtenderFields factory
CommentExtenderFactory = factory(CommentExtenderFields)


# Extending the comment form with the fields defined in the
# ICommentExtenderFields interface.
class CommentExtender(extensible.FormExtender):
adapts(Interface, IDefaultBrowserLayer, CommentForm)

fields = Fields(ICommentExtenderFields)

def __init__(self, context, request, form):
self.context = context
self.request = request
self.form = form

def update(self):
# Add the fields defined in ICommentExtenderFields to the form.
self.add(ICommentExtenderFields, prefix="")
# Move the title field to the top of the comment form.
self.move('title', before='text', prefix="")
30 changes: 30 additions & 0 deletions collective/comment_titles/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
i18n_domain="collective.comment_titles">

<five:registerPackage package="." initialize=".initialize" />

<genericsetup:registerProfile
name="default"
title="collective.comment_titles"
directory="profiles/default"
description="Installs the collective.comment_titles package"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

<adapter
factory=".commentextender.CommentExtenderFactory"
provides=".commentextender.ICommentExtenderFields"
layer=".interfaces.ExtenderLayer"
/>

<adapter
factory=".commentextender.CommentExtender"
provides="plone.z3cform.fieldsets.interfaces.IFormExtender"
layer=".interfaces.ExtenderLayer"
/>

</configure>
6 changes: 6 additions & 0 deletions collective/comment_titles/interfaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from zope.interface import Interface


class ExtenderLayer(Interface):
"""Marker interface that defines a Zope 3 browser layer.
"""
Binary file not shown.
8 changes: 8 additions & 0 deletions collective/comment_titles/profiles/default/browserlayer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!-- Register the package-specific browser layer,
so that it will be activated
when this product is installed. -->
<layers>
<layer name="collective.comment_titles.customization.layer"
interface="collective.comment_titles.interfaces.ExtenderLayer" />
</layers>
4 changes: 4 additions & 0 deletions collective/comment_titles/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<metadata>
<version>1000</version>
</metadata>
55 changes: 55 additions & 0 deletions collective/comment_titles/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import unittest

#from zope.testing import doctestunit
#from zope.component import testing
from Testing import ZopeTestCase as ztc

from Products.Five import fiveconfigure
from Products.PloneTestCase import PloneTestCase as ptc
from Products.PloneTestCase.layer import PloneSite
ptc.setupPloneSite()

import collective.comment_titles


class TestCase(ptc.PloneTestCase):

class layer(PloneSite):

@classmethod
def setUp(cls):
fiveconfigure.debug_mode = True
ztc.installPackage(collective.comment_titles)
fiveconfigure.debug_mode = False

@classmethod
def tearDown(cls):
pass


def test_suite():
return unittest.TestSuite([

# Unit tests
#doctestunit.DocFileSuite(
# 'README.txt', package='collective.comment_titles',
# setUp=testing.setUp, tearDown=testing.tearDown),

#doctestunit.DocTestSuite(
# module='collective.comment_titles.mymodule',
# setUp=testing.setUp, tearDown=testing.tearDown),


# Integration tests that use PloneTestCase
#ztc.ZopeDocFileSuite(
# 'README.txt', package='collective.comment_titles',
# test_class=TestCase),

#ztc.FunctionalDocFileSuite(
# 'browser.txt', package='collective.comment_titles',
# test_class=TestCase),

])

if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
7 changes: 7 additions & 0 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Changelog
=========

1.0dev (unreleased)
-------------------

- Initial release
52 changes: 52 additions & 0 deletions docs/INSTALL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
collective.comment_titles Installation
--------------------------------------

To install collective.comment_titles into the global Python environment (or a workingenv),
using a traditional Zope 2 instance, you can do this:

* When you're reading this you have probably already run
``easy_install collective.comment_titles``. Find out how to install setuptools
(and EasyInstall) here:
http://peak.telecommunity.com/DevCenter/EasyInstall

* If you are using Zope 2.9 (not 2.10), get `pythonproducts`_ and install it
via::

python setup.py install --home /path/to/instance

into your Zope instance.

* Create a file called ``collective.comment_titles-configure.zcml`` in the
``/path/to/instance/etc/package-includes`` directory. The file
should only contain this::

<include package="collective.comment_titles" />

.. _pythonproducts: http://plone.org/products/pythonproducts


Alternatively, if you are using zc.buildout and the plone.recipe.zope2instance
recipe to manage your project, you can do this:

* Add ``collective.comment_titles`` to the list of eggs to install, e.g.:

[buildout]
...
eggs =
...
collective.comment_titles

* Tell the plone.recipe.zope2instance recipe to install a ZCML slug:

[instance]
recipe = plone.recipe.zope2instance
...
zcml =
collective.comment_titles

* Re-run buildout, e.g. with:

$ ./bin/buildout

You can skip the ZCML slug if you are going to explicitly include the package
from another package's configure.zcml file.
Loading

0 comments on commit 9bff091

Please sign in to comment.