Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 3f36b4a
Merge: a1387c8 c389777
Author: Luca Fabbri <luca@keul.it>
Date:   Fri Sep 22 15:41:23 2017 +0200

    Merge branch 'fix-165' of https://github.com/abstract-open-solutions/Products.PloneFormGen into fix-165

commit a1387c8
Author: Luca Fabbri <luca@keul.it>
Date:   Wed Nov 9 11:06:41 2016 +0100

    Label and descripotion were not copyed on widget change

commit b93fb47
Author: Luca Fabbri <luca@keul.it>
Date:   Wed Nov 9 09:47:02 2016 +0100

    Restored usage of show_hm field

    See also smcmahon#165

commit 343414c
Author: Luca Fabbri <luca@keul.it>
Date:   Tue Nov 8 18:06:47 2016 +0100

    Fixed validation when date is not required (plus tests)

commit bebd64b
Author: Luca Fabbri <luca@keul.it>
Date:   Tue Nov 8 18:05:24 2016 +0100

    Missing test dependency

commit 56b4472
Author: Tom Gross <itconsense@gmail.com>
Date:   Mon May 9 13:14:22 2016 +0000

    fix date validator to work with new pattern widget output

commit f455f34
Author: Tom Gross <itconsense@gmail.com>
Date:   Mon May 9 13:14:04 2016 +0000

    ignor pycharm artefacts

commit 1098704
Author: Tom Gross <itconsense@gmail.com>
Date:   Mon May 9 10:31:47 2016 +0000

    use datepicker widget for datetime input smcmahon#164

commit f8aa1d7
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Sat Jul 8 20:29:41 2017 +0200

    Back to development: 1.8.5

    [ci skip]

commit 19ac10a
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Sat Jul 8 20:29:01 2017 +0200

    Preparing release 1.8.4

    [ci skip]

commit bf13b48
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Sat Jul 8 20:28:39 2017 +0200

    Cleanup the changelog a bit.

    [ci skip]

commit b13fbc0
Merge: e5163b3 54195c7
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Sat Jul 8 19:54:26 2017 +0200

    Merge pull request smcmahon#199 from jyukopla/fix-redundant-template-syntax

    Fix redundant fallback template value

commit e5163b3
Merge: 18085c3 9ced974
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Sat Jul 8 19:39:31 2017 +0200

    Merge pull request smcmahon#200 from jyukopla/fix/ratescalefield-unicode-error

    Fix/ratescalefield unicode error

commit 54195c7
Author: Jussi Rajala <zemm@iki.fi>
Date:   Fri Jul 7 09:26:32 2017 +0300

    Fix integration test to handle missing empty div

    b10ef37 caused an empty div between <form name="edit_form" and
    <div id="pfg-fieldwrapper"> to be absent. For some reasons,
    current integration test required something (anything) to be
    between the two elements. This handles the both cases where
    there is content between them or not.

commit 9ced974
Author: Valtteri Karppinen <karppinenvaltteri@gmail.com>
Date:   Thu Jul 6 11:21:18 2017 +0300

    update CHANGES.txt

commit 9f2fba2
Author: Valtteri Karppinen <karppinenvaltteri@gmail.com>
Date:   Thu Jul 6 11:20:16 2017 +0300

    Fix UnicodeDecodeError on ratescalefield with non-ascii values

commit b10ef37
Author: Jussi Rajala <zemm@iki.fi>
Date:   Wed Jul 5 15:56:32 2017 +0300

    Fix redundant template fallback value causing errors

    `|nothing` in conjunction with `structure` or `provider:` (not sure which)
    caused `ContentProviderLookupError: archetypes.edit.beforefieldsets|nothing`
    for me in some cases while debugging broken `RichTextField`.
    It seems that it might not be a valid syntax?

    In any case, it seems to be redundant, since there is also
    `tal:on-error="nothing"`, and subsequent equicalent
    `tal:replace="provider:archetypes.edit.afterfieldsets"`
    does not have it either.

commit 18085c3
Merge: fd2b4a6 82f9062
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Tue Jun 6 23:20:46 2017 +0200

    Merge pull request smcmahon#195 from rodfersou/issue_194

    Remove collective.cover adapter reference

commit 82f9062
Author: Rodrigo Ferreira de Souza <rodfersou@gmail.com>
Date:   Tue May 23 23:07:11 2017 -0300

    Remove collective.cover adapter reference

commit fd2b4a6
Merge: eb3d189 6ae0258
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Sat Jun 3 23:35:27 2017 +0200

    Merge pull request smcmahon#197 from smcmahon/fix-bootstrap

    Fixed bootstrapping.

commit 6ae0258
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Sat Jun 3 23:11:42 2017 +0200

    Use Plone 5.0.6 for now.

    5.0.7 gives failures in the tests.
    Seems fine in normal usage.

commit f2333cb
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Sat Jun 3 23:01:42 2017 +0200

    Tests: set browser.handleErrors to False.

    That way we get a proper traceback, instead of a general internal server error.

commit 06e68fd
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Sat Jun 3 21:50:23 2017 +0200

    Fixed bootstrapping.

    Both locally and on Travis.
    Note that you need to specify the zc.buildout version when bootstrapping:
    python bootstrap-buildout.py --buildout-version=2.5.3
    For setuptools we use the latest that ez_setup.py gives us, which will remain 33.1.1.

commit eb3d189
Merge: faa4352 82c18e9
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Tue Mar 7 18:35:48 2017 +0100

    Merge pull request smcmahon#192 from mikerenfro/fix-column-titles

    Adding getColumnNames logic to getColumnTitles

commit 82c18e9
Author: Mike Renfro <mike+github@renf.ro>
Date:   Sun Mar 5 19:03:03 2017 -0600

    Adding getColumnNames logic to getColumnTitles

commit faa4352
Merge: 10bbf17 c345b27
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Wed Mar 1 14:12:53 2017 +0100

    Merge pull request smcmahon#191 from datakurre/master

    Add missing </div> into quickedit.pt

commit c345b27
Author: Asko Soukka <asko.soukka@iki.fi>
Date:   Fri Feb 24 16:17:25 2017 +0200

    Update changelog

commit 67f1d49
Author: Asko Soukka <asko.soukka@iki.fi>
Date:   Fri Feb 24 16:16:15 2017 +0200

    Add missing closing </div> into quickedit template

commit 10bbf17
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Thu Dec 8 15:45:31 2016 +0100

    Fixed UnicodeDecodeError when vocabulary value is a non-ascii string.

    This could happen in selection and multi selection fields.

commit f5fa695
Merge: 6e7018b 7d99f56
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Fri Dec 16 14:16:02 2016 +0100

    Merge pull request smcmahon#187 from tkimnguyen/master

    change captcha verification message for smcmahon#186

commit 7d99f56
Author: T. Kim Nguyen <tkn@alumni.uwaterloo.ca>
Date:   Wed Dec 14 13:28:16 2016 -0600

    change captcha verification message for smcmahon#186

commit 6e7018b
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Tue Dec 6 15:25:10 2016 +0100

    Back to development: 1.8.4

    [ci skip]

commit 0adae57
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Tue Dec 6 15:24:31 2016 +0100

    Preparing release 1.8.3

    [ci skip]

commit 6829d2f
Author: Philip Bauer <bauer@starzel.de>
Date:   Tue Dec 6 11:27:53 2016 +0100

    Transform value to unicode before translating. Fix smcmahon#182

commit 709f625
Author: Steve McMahon <steve@dcn.org>
Date:   Tue Nov 22 11:32:04 2016 -0800

    Back to development: 1.8.3

commit e13a9db
Author: Steve McMahon <steve@dcn.org>
Date:   Tue Nov 22 11:30:53 2016 -0800

    Preparing release 1.8.2

commit b90e67d
Merge: 1cf9556 87a4799
Author: Steve McMahon <steve@dcn.org>
Date:   Tue Nov 22 11:24:53 2016 -0800

    Merge pull request smcmahon#181 from smcmahon/issue-178-helptext-master

    Fixed showing translations of help text. [master]

commit 1cf9556
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Fri Nov 18 18:37:43 2016 +0100

    Added commented-out xlwt egg.

    With this eXceL WriTer you can test the excel export of the Save Data Adapter.

commit 70d0bd8
Merge: c71a53b d8a03a2
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Fri Nov 18 18:27:47 2016 +0100

    Merge remote-tracking branch 'tmog/xls_export'

commit 87a4799
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Fri Nov 18 13:00:49 2016 +0100

    Fixed showing translations of help text.

    Since security release 1.78.1, help text was showing up with only the
    message id, for example `help_placeholder`.

    This fixes issue smcmahon#178.

commit c71a53b
Author: Harald Friessnegger <harald@webmeisterei.com>
Date:   Thu Sep 3 18:24:52 2015 +0200

    use formActionOverride in embedded view if it has been set

commit c389777
Author: Luca Fabbri <luca@keul.it>
Date:   Wed Nov 9 11:06:41 2016 +0100

    Label and descripotion were not copyed on widget change

commit 42029d8
Author: Luca Fabbri <luca@keul.it>
Date:   Wed Nov 9 09:47:02 2016 +0100

    Restored usage of show_hm field

    See also smcmahon#165

commit 7e96bd2
Author: Luca Fabbri <luca@keul.it>
Date:   Tue Nov 8 18:06:47 2016 +0100

    Fixed validation when date is not required (plus tests)

commit b44b89e
Author: Luca Fabbri <luca@keul.it>
Date:   Tue Nov 8 18:05:24 2016 +0100

    Missing test dependency

commit e920d86
Author: Tom Gross <itconsense@gmail.com>
Date:   Mon May 9 13:14:22 2016 +0000

    fix date validator to work with new pattern widget output

commit b283f0c
Author: Tom Gross <itconsense@gmail.com>
Date:   Mon May 9 13:14:04 2016 +0000

    ignor pycharm artefacts

commit cf16bef
Author: Tom Gross <itconsense@gmail.com>
Date:   Mon May 9 10:31:47 2016 +0000

    use datepicker widget for datetime input smcmahon#164

commit af24c55
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Tue May 3 12:05:13 2016 +0200

    Back to development: 1.8.2

    [ci skip]

commit b9590e5
Author: Steve McMahon <steve@dcn.org>
Date:   Sun May 1 10:43:14 2016 -0700

    Eliminate XSS vulnerability in field help field

commit d8a03a2
Author: Thomas Clement Mogensen <mogensen@diku.dk>
Date:   Fri Feb 26 14:25:25 2016 +0100

    format web links and numbers as such in excel download. Format based on actual data, not field settings.

commit c86a891
Author: Thomas Clement Mogensen <mogensen@diku.dk>
Date:   Thu Feb 25 13:37:01 2016 +0100

    fix encoding issue in excel document creation

commit be18ed6
Author: Thomas Clement Mogensen <mogensen@diku.dk>
Date:   Wed Feb 24 12:04:35 2016 +0100

    Add option to download data from saveDataAdapter in excel format

commit fc9592b
Author: Steve McMahon <steve@dcn.org>
Date:   Thu Oct 1 09:01:44 2015 -0700

    Update README.rst

commit cf425b1
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Thu Oct 1 04:50:52 2015 +0200

    Back to development: 1.8.1

    [ci skip]

commit 4ba658b
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Thu Oct 1 04:48:21 2015 +0200

    Preparing release 1.8.0

    [ci skip]

commit 164be3c
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Thu Oct 1 04:47:05 2015 +0200

    check-manifest: ignore .gitattributes

commit 881063c
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Thu Oct 1 04:45:35 2015 +0200

    Fixed rst long description.

commit 4c46113
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Thu Oct 1 02:16:37 2015 +0200

    Removed deprecated property use_folder_tabs.

commit 26e16d8
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Thu Oct 1 02:11:59 2015 +0200

    Removed unused property typesLinkToFolderContentsInFC.

    In core Plone this was briefly changed to plone.types_link_to_folder_contents,
    but it was not actually used.

commit cb426ca
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Thu Oct 1 01:55:29 2015 +0200

    Revert "Moved our types_not_searched settings to the registry."

    This reverts commit 6b4256e.

    It needs a fix in plone.app.registry so that typeinfo is loaded before
    registry.xml, otherwise an install fails.

commit 6b4256e
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Thu Oct 1 01:11:04 2015 +0200

    Moved our types_not_searched settings to the registry.

commit 8f3e395
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Thu Oct 1 01:04:32 2015 +0200

    Moved our default_page_types setting to the registry.

commit e2e34fb
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Wed Sep 30 20:33:39 2015 +0200

    Rename UTF-8 and utf8 to lowercase utf-8.

    They are all the same and this what Plone uses everywhere (or should be).

commit 3695500
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Wed Sep 30 20:31:41 2015 +0200

    Get email settings from registry.  Fixes several Plone 5 errors.

    Do not use ``plone_utils.getSiteEncoding()``, because this is
    deprecated and always returns ``utf-8''.

commit 8375e49
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Wed Sep 30 20:00:21 2015 +0200

    Load widget specific css on quickedit form.

    We were defining both javascript and css of the addable widgets,
    but were only adding the javascript, not the css.

    The calendar widget is still not really working there.  But if we are
    loading this css when viewing a form, we should load it while
    quickediting the form.  On Plone 4.3 it helped.

commit 37c2148
Merge: 276df36 3aeb6be
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Fri Sep 11 15:59:36 2015 +0200

    Merge remote-tracking branch '4teamwork/fix_embedded_view'

commit 276df36
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Fri Sep 11 15:59:32 2015 +0200

    Tell git to merge CHANGES.txt in union mode.

    bobtemplates.plone does that.

commit 944a6ff
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Fri Sep 11 14:55:09 2015 +0200

    Removed inline javascript that tried to block inline validation.

    It had no effect anymore on Plone 5, as no inline validation is done
    here anyway.

    And it interferes with themes that load jQuery near the bottom instead
    of in the head.

commit 3aeb6be
Author: Thomas Buchberger <t.buchberger@4teamwork.ch>
Date:   Fri Sep 11 11:58:10 2015 +0200

    Fix embedded view by removing global_defines macro.

commit 5ed1635
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Wed Sep 9 20:39:55 2015 +0200

    Back to development: 1.8.0b5

    [ci skip]

commit 4cba4e5
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Wed Sep 9 20:35:02 2015 +0200

    Preparing release 1.8.0b4

    [ci skip]

commit 8499d48
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Wed Sep 9 20:33:43 2015 +0200

    Fixed manifest.

commit 2054b2b
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Wed Sep 9 20:24:05 2015 +0200

    No longer convert long description to ascii.

    Works fine, at least with any recent zest.releaser version.  The
    current text files are already ascii-only, so there the problem never
    occurs, but should be fine anyway.

commit 03428e8
Author: Maurits van Rees <maurits@vanrees.org>
Date:   Tue Sep 8 19:45:26 2015 +0200

    Changed our content types to use TinyMCEWidget instead of RichWidget.

    The old one only showed a plain textarea.
    Fixes issue smcmahon#152.
  • Loading branch information
keul committed Sep 22, 2017
1 parent 7a9b719 commit 82a2faf
Show file tree
Hide file tree
Showing 40 changed files with 546 additions and 208 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
CHANGES.txt merge=union
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -17,3 +17,4 @@ parts
src
var
._*
.idea
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -7,11 +7,11 @@ cache:
- buildout-cache
install:
- mkdir -p buildout-cache/{eggs,downloads}
- python bootstrap-buildout.py
- python bootstrap-buildout.py --buildout-version=2.5.3
- bin/buildout
script:
- bin/test

notifications:
email:
- steve@dcn.org
- steve@dcn.org
102 changes: 100 additions & 2 deletions CHANGES.txt
@@ -1,9 +1,106 @@
Change History
==============

1.8.5 (unreleased)
------------------

1.8.0.beta4 (unreleased)
------------------------
- Use datepicker widget for datetime input
[tomgross]


1.8.4 (2017-07-08)
------------------

- Fix UnicodeDecodeError: RateScaleField with non-ascii values and without
Thank-you-page.
Fixes `issue #98 <https://github.com/smcmahon/Products.PloneFormGen/issues/98>`_.
[vkarppinen]

- Remove collective.cover adapter reference.
(Closes `#194 <https://github.com/smcmahon/Products.PloneFormGen/issues/194>`_.
[rodfersou]

- Fixed UnicodeDecodeError when vocabulary value is a non-ascii string.
This could happen in selection and multi selection fields.
[maurits]

- Change captcha verification message for `#186 <https://github.com/smcmahon/Products.PloneFormGen/issues/186>`_.
[tkimnguyen]

- Fix issue where quickedit view caused rendering issues because
of a tag not being closed.
[datakurre]

- Fix issue where logic in FormSaveDataAdapter's getColumnTitles was
different than the logic for getColumnNames.
[mikerenfro]

- Fix redundant template fallback value.
[zemm]


1.8.3 (2016-12-06)
------------------

- Transform value to unicode before translating. Fix #182
[pbauer]


1.8.2 (2016-11-22)
------------------

- Fixed showing translations of help text. Since security release
1.8.1, help text was showing up with only the message id, for
example ``help_placeholder``.
Fixes `issue #178 <https://github.com/smcmahon/Products.PloneFormGen/issues/178>`_.
[maurits]

- Use formActionOverride action in embedded view. [fRiSi]

- Add option to download data from saveDataAdapter in excel format
Excel download depends on the availability of the 'xlwt' python package.
[tmog]


1.8.1 (2016-05-01)
------------------

- CGI escape field help (description); prevent method call.
Eliminates XSS vulnerability that could be exploited by users with the ability
to create forms.
[smcmahon]


1.8.0 (2015-10-01)
------------------

- Moved our default_page_types setting to the registry.
[maurits]

- Get email settings from registry. Fixes several Plone 5 errors.
Do not use ``plone_utils.getSiteEncoding()``, because this is
deprecated and always returns ``utf-8``.
[maurits]

- Load widget specific css on quickedit form.
[maurits]

- Fix embedded view by removing deprecated global defines macro.
[buchi]

- Removed inline javascript that tried to block inline validation. It
had no effect anymore on Plone 5, as no inline validation is done
here anyway. And it interferes with themes that load jQuery near
the bottom instead of in the head.
[maurits]


1.8.0b4 (2015-09-09)
--------------------

- Changed our content types to use TinyMCEWidget instead of
RichWidget. The old one only showed a plain textarea. Fixes issue
#152.

- Fixed ``propertiestool.xml`` to not break importing
``types_not_searched``.
Expand Down Expand Up @@ -45,3 +142,4 @@ Change History
[thet]

For previous changes, see docs/HISTORY.txt.

2 changes: 1 addition & 1 deletion MANIFEST.in
@@ -1,4 +1,4 @@
include *
include *cfg *rst *txt
recursive-include docs *
recursive-include Products/PloneFormGen *
global-exclude *.pyc
Expand Down
6 changes: 5 additions & 1 deletion Products/PloneFormGen/browser/embedded.py
Expand Up @@ -83,7 +83,11 @@ def __call__(self):
if self.action is not None:
self.request.set('pfg_form_action', self.action)
else:
self.request.set('pfg_form_action', self.request['URL'])
actionOverride = getattr(self.context, 'formActionOverride', None)
if actionOverride:
self.request.set('pfg_form_action', actionOverride)
else:
self.request.set('pfg_form_action', self.request['URL'])

self.status = IStatusMessage(self.request)
self.request.set('messages', self.status.show())
Expand Down
11 changes: 11 additions & 0 deletions Products/PloneFormGen/browser/quickedit.pt
Expand Up @@ -58,6 +58,16 @@
<tal:expr replace="structure here/getHeaderInjection | nothing" />
</metal:javascript_head>

<metal:css fill-slot="style_slot">
<tal:css condition="css"
repeat="item css">
<style type="text/css"
media="all"
tal:condition="python:exists('portal/%s' % item)"
tal:content="structure string:&lt;!-- @import url($portal_url/$item); --&gt;">
</style>
</tal:css>
</metal:css>

<body>
<metal:content-core fill-slot="content-core">
Expand Down Expand Up @@ -293,6 +303,7 @@
</div>
</tal:block>
</div>
</div>
</div>

<p tal:replace="structure here/formEpilogue | nothing" />
Expand Down
7 changes: 0 additions & 7 deletions Products/PloneFormGen/configure.zcml
Expand Up @@ -137,11 +137,4 @@
<subscriber handler=".events.form_adapter_pasted" />
<subscriber handler=".events.form_adapter_moved" />

<adapter
zcml:condition="installed collective.cover"
for="Products.PloneFormGen.interfaces.form.IPloneFormGenForm"
provides="collective.cover.interfaces.ICoverUIDsProvider"
factory="collective.cover.tiles.list.GenericUIDsProvider"
/>

</configure>
43 changes: 43 additions & 0 deletions Products/PloneFormGen/content/field_utils.py
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
from Products.Archetypes.Renderer import renderer
from Products.CMFPlone.utils import safe_unicode
from zope.i18n import translate

import cgi


class ATWidgetWrapper(object):
"""
Wrap a Products.Archetypes.generator.widget.widget class
to intercept the Description method.
"""

def __init__(self, obj):
self.obj = obj

def __call__(self, mode, instance, context=None):
return self.obj(mode, instance, context)

def __getattr__(self, name):
if name == 'Description':
return self.wDescription
return getattr(self.obj, name)

def wDescription(self, instance, **kwargs):
value = self.obj.description
if value:
value = translate(safe_unicode(value), context=instance.REQUEST)
return cgi.escape(value)
else:
return value


def widget(self, field_name, mode="view", field=None, **kwargs):
"""Returns the rendered widget.
"""

if field is None:
field = self.Schema()[field_name]
widget = ATWidgetWrapper(field.widget)
return renderer.render(field_name, mode, widget, self, field=field,
**kwargs)
69 changes: 42 additions & 27 deletions Products/PloneFormGen/content/fields.py
Expand Up @@ -9,6 +9,8 @@

from Products.Archetypes.public import *
from Products.Archetypes.utils import shasattr
from Products.Archetypes.Widget import DateWidget
from Products.Archetypes.Widget import DatetimeWidget

from Products.ATContentTypes.content.base import registerATCT
from Products.ATContentTypes.content.base import ATCTContent
Expand Down Expand Up @@ -505,20 +507,37 @@ def __init__(self, oid, **kwargs):
self.fgField = DateTimeField('fg_date_field',
searchable=0,
required=0,
accessor = 'nullAccessor',
write_permission = View,
widget=CalendarWidget(),
widget=DatetimeWidget(),
)


security.declareProtected(ModifyPortalContent, 'setFgShowHM')
def setFgShowHM(self, value, **kw):
""" set show_hm """

if type(value) == BooleanType:
self.fgField.widget.show_hm = value
if not type(value) == BooleanType:
value = value == '1'
old_widget = self.fgField.widget
if not value:
# BBB: changing patters options is not working so we re-init the
# inner widget
self.fgField.widget = DateWidget()
self.fgField.widget._properties['pattern_options']['time'] = value
self.fgField.widget.pattern_options['time'] = value
else:
self.fgField.widget.show_hm = value == '1'
self.fgField.widget = DatetimeWidget()
try:
del self.fgField.widget.pattern_options['time']
del self.fgField.widget._properties['pattern_options']['time']
except KeyError:
pass

# Copy data from the old widget
self.fgField.__name__
for attr in ('label', 'description'):
setattr(self.fgField.widget, attr, getattr(old_widget, attr))

self.fgField.widget.show_hm = value
self.fgShowHM = value


Expand Down Expand Up @@ -571,7 +590,6 @@ def _toLocalizedTime(self, time, long_format=None):
tool = getToolByName(self, 'translation_service')
return tool.ulocalized_time(time, long_format=long_format)


def htmlValue(self, REQUEST):
""" return from REQUEST, this field's value, rendered as XHTML.
"""
Expand All @@ -594,23 +612,16 @@ def htmlValue(self, REQUEST):

return cgi.escape(value)


def specialValidator(self, value, field, REQUEST, errors):
""" Archetypes isn't validating non-required dates --
so we need to.
BBB: this not seem true anymore on Plone 5
"""

fname = field.getName()
month = REQUEST.form.get('%s_month'%fname, '01')
day = REQUEST.form.get('%s_month'%fname, '01')

if (month == '00') and (day == '00'):
value = ''
REQUEST.form[fname] = ''

if value and not field.required:
value = value or REQUEST.form.get(fname)
if value or field.required:
try:
dt = DateTime(value)
DateTime(value)
except (DateTimeSyntaxError, DateError):
return "Validation failed(isValidDate): this is not a valid date."
return 0
Expand Down Expand Up @@ -768,8 +779,7 @@ def formatVocabDL(self):
def htmlValue(self, REQUEST):
""" Return value instead of key """

utils = getToolByName(self, 'plone_utils')
charset = utils.getSiteEncoding()
charset = 'utf-8'

value = REQUEST.form.get(self.__name__, '')

Expand All @@ -780,7 +790,10 @@ def htmlValue(self, REQUEST):
vocabulary = self.fgField.Vocabulary(self)
v = vocabulary.getValue(vu) or vu

return cgi.escape(v.encode(charset))
# v might be unicode or string. We need string.
if isinstance(v, unicode):
v = v.encode(charset)
return cgi.escape(v)


registerATCT(FGSelectionField, PROJECTNAME)
Expand Down Expand Up @@ -876,8 +889,7 @@ def formatVocabDL(self):
def htmlValue(self, REQUEST):
""" Return value instead of key """

utils = getToolByName(self, 'plone_utils')
charset = utils.getSiteEncoding()
charset = 'utf-8'

value = REQUEST.form.get(self.__name__, [])

Expand All @@ -890,11 +902,14 @@ def htmlValue(self, REQUEST):
# so decode the key before lookup
ku = k.decode(charset)
v = vocabulary.getValue(ku) or ku
# v might be unicode or string. We need string.
if isinstance(v, unicode):
v = v.encode(charset)
result.append(v)

value = u', '.join(result)
value = ', '.join(result)

return cgi.escape(value.encode(charset))
return cgi.escape(value)


registerATCT(FGMultiSelectField, PROJECTNAME)
Expand Down Expand Up @@ -1050,7 +1065,7 @@ def __init__(self, oid, **kwargs):
default_content_type = 'text/html',
default_output_type = 'text/x-html-safe',
allowable_content_types = zconf.ATDocument.allowed_content_types,
widget = RichWidget(
widget = TinyMCEWidget(
allow_file_upload = False,
),
)
Expand Down Expand Up @@ -1104,7 +1119,7 @@ class FGRichLabelField(BaseFormField):
default_content_type = 'text/html',
default_output_type = 'text/x-html-safe',
allowable_content_types = zconf.ATDocument.allowed_content_types,
widget=RichWidget(label=_(u'label_fglabelbody_text', default=u'Label body'),
widget=TinyMCEWidget(label=_(u'label_fglabelbody_text', default=u'Label body'),
description=_(u'help_fglabelbody_text', default=u"""
The text to display in the form.
"""),
Expand Down

0 comments on commit 82a2faf

Please sign in to comment.