Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.7.x: Add option to allow using field title instead of name when saving data #208

Open
wants to merge 1 commit into
base: 1.7-maintenance
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Change History
1.7.24 (unreleased)
-------------------

- Nothing changed yet.
- Add option to use field title instead of name when exporting using
save data adapter.
[malthe]


1.7.23 (2017-07-08)
Expand Down
20 changes: 18 additions & 2 deletions Products/PloneFormGen/content/saveDataAdapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ class FormSaveDataAdapter(FormActionAdapter):
description=_(u'help_usecolumnnames_text', default=u"Do you wish to have column names on the first line of downloaded input?"),
),
),
BooleanField("UseFieldTitleForColumn",
required=False,
searchable=False,
widget=BooleanWidget(
label=_(u'label_usefieldtitleforcolumn_text', default=u"Use Field Title for Column"),
description=_(u'help_usefieldtitleforcolumn_text', default=u"Do you wish to use the field title instead of the name for the column header?"),
),
),
ExLinesField('SavedFormInput',
edit_accessor='getSavedFormInputForEdit',
mutator='setSavedFormInput',
Expand Down Expand Up @@ -400,7 +408,11 @@ def download_tsv(self, REQUEST=None, RESPONSE=None):
RESPONSE.setHeader("Content-Type", 'text/tab-separated-values;charset=%s' % self.getCharset())

if getattr(self, 'UseColumnNames', False):
res = "%s\n" % '\t'.join(self.getColumnNames(excludeServerSide=False))
if getattr(self, "UseFieldTitleForColumn", False):
meth = self.getColumnTitles
else:
meth = self.getColumnNames
res = "%s\n" % '\t'.join(meth(excludeServerSide=False))
if isinstance(res, unicode):
res = res.encode(self.getCharset())
else:
Expand All @@ -425,8 +437,12 @@ def download_csv(self, REQUEST=None, RESPONSE=None):
RESPONSE.setHeader("Content-Type", 'text/comma-separated-values;charset=%s' % self.getCharset())

if getattr(self, 'UseColumnNames', False):
if getattr(self, "UseFieldTitleForColumn", False):
meth = self.getColumnTitles
else:
meth = self.getColumnNames
delimiter = self.csvDelimiter()
res = "%s\n" % delimiter.join(self.getColumnNames(excludeServerSide=False))
res = "%s\n" % delimiter.join(meth(excludeServerSide=False))
if isinstance(res, unicode):
res = res.encode(self.getCharset())
else:
Expand Down
10 changes: 10 additions & 0 deletions Products/PloneFormGen/locales/da/LC_MESSAGES/ploneformgen.po
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,11 @@ msgstr "Denne tekst vil blive vist over de valgte inputs"
msgid "help_usecolumnnames_text"
msgstr "Vil du have kolonnenavne p� f�rste linie?"

#. Default: "Do you wish to use the field title instead of the name for the column header?"
#: ./content/saveDataAdapter.py:154
msgid "help_usefieldtitleforcolumn_text"
msgstr "Vil du anvende titel i stedet for navn p� f�rste linie?"

#. Default: "Useful for stopping spam"
#: ./content/fields.py:939
msgid "help_validate_link_spam_text"
Expand Down Expand Up @@ -1636,6 +1641,11 @@ msgstr ""
msgid "label_usecolumnnames_text"
msgstr "Inkluder kolonnenavne"

#. Default: "Use Field Title for Column"
#: ./content/saveDataAdapter.py:98
msgid "label_usefieldtitleforcolumn_text"
msgstr "Brug titel i stedet for navn"

#. Default: "Reject Text with Links?"
#: ./content/fields.py:938
msgid "label_validate_link_spam_text"
Expand Down
10 changes: 10 additions & 0 deletions Products/PloneFormGen/locales/ploneformgen.pot
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,11 @@ msgstr ""
msgid "help_usecolumnnames_text"
msgstr ""

#. Default: "Do you wish to use the field title instead of the name for the column header?"
#: ./content/saveDataAdapter.py:154
msgid "help_usefieldtitleforcolumn_text"
msgstr ""

#. Default: "Useful for stopping spam"
#: ./content/fields.py:939
msgid "help_validate_link_spam_text"
Expand Down Expand Up @@ -1354,6 +1359,11 @@ msgstr ""
msgid "label_usecolumnnames_text"
msgstr ""

#. Default: "Use Field Title for Column"
#: ./content/saveDataAdapter.py:98
msgid "label_usefieldtitleforcolumn_text"
msgstr ""

#. Default: "Reject Text with Links?"
#: ./content/fields.py:938
msgid "label_validate_link_spam_text"
Expand Down