From d6baaf8e0fb688dde1da84835511ccd480572bb1 Mon Sep 17 00:00:00 2001 From: Ivan Tyagov <ivan@nexedi.com> Date: Wed, 17 Jul 2013 15:27:50 +0300 Subject: [PATCH] Make it possible to add attachments to a post. --- .../base_category_list.xml | 3 + .../DiscussionPost_getAttachmentList.xml | 84 ++++++++++++++++ .../DiscussionPost_getSummaryAsHTML.xml | 13 +++ ...scussionThread_createNewDiscussionPost.xml | 15 ++- ...read_viewCreateNewDiscussionPostDialog.xml | 1 + .../your_file.xml | 96 +++++++++++++++++++ .../WebSection_createNewDiscussionThread.xml | 16 +++- ...on_viewCreateNewDiscussionThreadDialog.xml | 1 + .../your_file.xml | 96 +++++++++++++++++++ .../erp5_discussion/erp5_discussion.css.xml | 8 +- bt5/erp5_discussion/bt/revision | 2 +- .../template_portal_type_base_category_list | 1 + 12 files changed, 331 insertions(+), 5 deletions(-) create mode 100644 bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionPost_getAttachmentList.xml create mode 100644 bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionThread_viewCreateNewDiscussionPostDialog/your_file.xml create mode 100644 bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/WebSection_viewCreateNewDiscussionThreadDialog/your_file.xml diff --git a/bt5/erp5_discussion/PortalTypeBaseCategoryTemplateItem/base_category_list.xml b/bt5/erp5_discussion/PortalTypeBaseCategoryTemplateItem/base_category_list.xml index 6065368b59..29cb41f710 100644 --- a/bt5/erp5_discussion/PortalTypeBaseCategoryTemplateItem/base_category_list.xml +++ b/bt5/erp5_discussion/PortalTypeBaseCategoryTemplateItem/base_category_list.xml @@ -1,4 +1,7 @@ <base_category_list> + <portal_type id="Discussion Post"> + <item>successor</item> + </portal_type> <portal_type id="Discussion Thread"> <item>contributor</item> <item>source</item> diff --git a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionPost_getAttachmentList.xml b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionPost_getAttachmentList.xml new file mode 100644 index 0000000000..389e200ce1 --- /dev/null +++ b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionPost_getAttachmentList.xml @@ -0,0 +1,84 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="PythonScript" module="Products.PythonScripts.PythonScript"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>Script_magic</string> </key> + <value> <int>3</int> </value> + </item> + <item> + <key> <string>_bind_names</string> </key> + <value> + <object> + <klass> + <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/> + </klass> + <tuple/> + <state> + <dictionary> + <item> + <key> <string>_asgns</string> </key> + <value> + <dictionary> + <item> + <key> <string>name_container</string> </key> + <value> <string>container</string> </value> + </item> + <item> + <key> <string>name_context</string> </key> + <value> <string>context</string> </value> + </item> + <item> + <key> <string>name_m_self</string> </key> + <value> <string>script</string> </value> + </item> + <item> + <key> <string>name_subpath</string> </key> + <value> <string>traverse_subpath</string> </value> + </item> + </dictionary> + </value> + </item> + </dictionary> + </state> + </object> + </value> + </item> + <item> + <key> <string>_body</string> </key> + <value> <string>"""\n + Return list of attachments for a post.\n + We use proxy roles as not in all cases current user is allowed to get attachments but still we need\n + to provide a link to them which when used will ask for login.\n +"""\n +result = []\n +for successor in context.getSuccessorValueList():\n + result.append({\'title\': successor.getTitle(),\n + \'url\': successor.absolute_url()})\n +return result\n +</string> </value> + </item> + <item> + <key> <string>_params</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>_proxy_roles</string> </key> + <value> + <tuple> + <string>Assignor</string> + </tuple> + </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>DiscussionPost_getAttachmentList</string> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionPost_getSummaryAsHTML.xml b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionPost_getSummaryAsHTML.xml index d2a0d68211..458aa0a5a4 100644 --- a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionPost_getSummaryAsHTML.xml +++ b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionPost_getSummaryAsHTML.xml @@ -50,6 +50,7 @@ discussion_post_creation_date python: here.Base_FormatDate(discussion_post_object.getCreationDate());\n discussion_post_validation_state_title discussion_post_object/getTranslatedValidationStateTitle;\n discussion_post_stripped_html discussion_post_object/asStrippedHTML;\n + attachment_list discussion_post_object/DiscussionPost_getAttachmentList;\n isUserAllowedToPost python: discussion_post_object.getParentValue().DiscussionThread_isUserAllowedToPost()">\n \n <div class="discussion-post-header">\n @@ -76,6 +77,18 @@ \n <div class="discussion-post-body-container"\n tal:content="structure discussion_post_stripped_html"></div>\n +\n + <div class="attachment"\n + tal:condition="python: len(attachment_list)">\n + <p>Attachments:</p>\n + <ul>\n + <li tal:repeat="attachment attachment_list">\n + <a tal:attributes="href attachment/url"\n + tal:content="attachment/title"></a>\n + </li>\n + </ul>\n + </div>\n + \n \n <div tal:condition="python: author_signature is not None"\n class="discussion-post-author-signature-container"\n diff --git a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionThread_createNewDiscussionPost.xml b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionThread_createNewDiscussionPost.xml index ad5414068e..2c743f14d0 100644 --- a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionThread_createNewDiscussionPost.xml +++ b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionThread_createNewDiscussionPost.xml @@ -78,6 +78,19 @@ discussion_post = discussion_thread.newContent(\n language = portal.Localizer.get_selected_language(),\n text_format = \'text/html\')\n \n +# handle attachments\n +if getattr(file, \'filename\', \'\') != \'\':\n + document_kw = {\'batch_mode\': True,\n + \'redirect_to_document\': False,\n + \'file\': file}\n + document = context.Base_contribute(**document_kw)\n +\n + # set relation between post and document\n + discussion_post.setSuccessorValueList([document])\n +\n + # depending on security model this should be changed accordingly\n + document.publish()\n +\n # depending on security model Post can be submitted for review\n portal_status_message = context.Base_translateString("New post created.")\n \n @@ -104,7 +117,7 @@ else:\n </item> <item> <key> <string>_params</string> </key> - <value> <string>title, text_content, form_id=\'view\', predecessor=None,**kw</string> </value> + <value> <string>title, text_content, form_id=\'view\', predecessor=None, file=None, **kw</string> </value> </item> <item> <key> <string>_proxy_roles</string> </key> diff --git a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionThread_viewCreateNewDiscussionPostDialog.xml b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionThread_viewCreateNewDiscussionPostDialog.xml index accdf6b4df..f34541f33a 100644 --- a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionThread_viewCreateNewDiscussionPostDialog.xml +++ b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionThread_viewCreateNewDiscussionPostDialog.xml @@ -95,6 +95,7 @@ <list> <string>your_title</string> <string>your_text_content</string> + <string>your_file</string> <string>your_captcha</string> </list> </value> diff --git a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionThread_viewCreateNewDiscussionPostDialog/your_file.xml b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionThread_viewCreateNewDiscussionPostDialog/your_file.xml new file mode 100644 index 0000000000..a9def637b7 --- /dev/null +++ b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionThread_viewCreateNewDiscussionPostDialog/your_file.xml @@ -0,0 +1,96 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="ProxyField" module="Products.ERP5Form.ProxyField"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>delegated_list</string> </key> + <value> + <list> + <string>title</string> + </list> + </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>your_file</string> </value> + </item> + <item> + <key> <string>message_values</string> </key> + <value> + <dictionary> + <item> + <key> <string>external_validator_failed</string> </key> + <value> <string>The input failed the external validator.</string> </value> + </item> + </dictionary> + </value> + </item> + <item> + <key> <string>overrides</string> </key> + <value> + <dictionary> + <item> + <key> <string>field_id</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>form_id</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>target</string> </key> + <value> <string></string> </value> + </item> + </dictionary> + </value> + </item> + <item> + <key> <string>tales</string> </key> + <value> + <dictionary> + <item> + <key> <string>field_id</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>form_id</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>target</string> </key> + <value> <string></string> </value> + </item> + </dictionary> + </value> + </item> + <item> + <key> <string>values</string> </key> + <value> + <dictionary> + <item> + <key> <string>field_id</string> </key> + <value> <string>my_file_field</string> </value> + </item> + <item> + <key> <string>form_id</string> </key> + <value> <string>Base_viewFieldLibrary</string> </value> + </item> + <item> + <key> <string>target</string> </key> + <value> <string>Click to edit the target</string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string>File Attachment</string> </value> + </item> + </dictionary> + </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/WebSection_createNewDiscussionThread.xml b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/WebSection_createNewDiscussionThread.xml index 40a9153f24..70c8a07e42 100644 --- a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/WebSection_createNewDiscussionThread.xml +++ b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/WebSection_createNewDiscussionThread.xml @@ -127,6 +127,19 @@ discussion_post = discussion_thread.newContent(\n portal_status_message = "New discussion created in background."\n discussion_thread.publish()\n \n +# handle attachments\n +if getattr(file, \'filename\', \'\') != \'\':\n + document_kw = {\'batch_mode\': True,\n + \'redirect_to_document\': False,\n + \'file\': file}\n + document = context.Base_contribute(**document_kw)\n +\n + # set relation between post and document\n + discussion_post.setSuccessorValueList([document])\n +\n + # depending on security model this should be changed accordingly\n + document.publish()\n +\n if send_notification_text not in (\'\', None):\n # we can send notifications\n person_list = []\n @@ -171,13 +184,14 @@ return context.Base_redirect(form_id,\n </item> <item> <key> <string>_params</string> </key> - <value> <string>title, text_content, form_id=\'view\', predecessor=None, description=None, subject_list=None, classification=None, group_list=None, site_list=None, send_notification_text=None, reference=None,**kw</string> </value> + <value> <string>title, text_content, form_id=\'view\', predecessor=None, description=None, subject_list=None, classification=None, group_list=None, site_list=None, send_notification_text=None, reference=None, file=None, **kw</string> </value> </item> <item> <key> <string>_proxy_roles</string> </key> <value> <tuple> <string>Assignor</string> + <string>Manager</string> </tuple> </value> </item> diff --git a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/WebSection_viewCreateNewDiscussionThreadDialog.xml b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/WebSection_viewCreateNewDiscussionThreadDialog.xml index c6fa61ecd7..ae4c27f1d1 100644 --- a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/WebSection_viewCreateNewDiscussionThreadDialog.xml +++ b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/WebSection_viewCreateNewDiscussionThreadDialog.xml @@ -96,6 +96,7 @@ <string>your_title</string> <string>your_send_notification_text</string> <string>your_text_content</string> + <string>your_file</string> <string>your_captcha</string> </list> </value> diff --git a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/WebSection_viewCreateNewDiscussionThreadDialog/your_file.xml b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/WebSection_viewCreateNewDiscussionThreadDialog/your_file.xml new file mode 100644 index 0000000000..a9def637b7 --- /dev/null +++ b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/WebSection_viewCreateNewDiscussionThreadDialog/your_file.xml @@ -0,0 +1,96 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="ProxyField" module="Products.ERP5Form.ProxyField"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>delegated_list</string> </key> + <value> + <list> + <string>title</string> + </list> + </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>your_file</string> </value> + </item> + <item> + <key> <string>message_values</string> </key> + <value> + <dictionary> + <item> + <key> <string>external_validator_failed</string> </key> + <value> <string>The input failed the external validator.</string> </value> + </item> + </dictionary> + </value> + </item> + <item> + <key> <string>overrides</string> </key> + <value> + <dictionary> + <item> + <key> <string>field_id</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>form_id</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>target</string> </key> + <value> <string></string> </value> + </item> + </dictionary> + </value> + </item> + <item> + <key> <string>tales</string> </key> + <value> + <dictionary> + <item> + <key> <string>field_id</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>form_id</string> </key> + <value> <string></string> </value> + </item> + <item> + <key> <string>target</string> </key> + <value> <string></string> </value> + </item> + </dictionary> + </value> + </item> + <item> + <key> <string>values</string> </key> + <value> + <dictionary> + <item> + <key> <string>field_id</string> </key> + <value> <string>my_file_field</string> </value> + </item> + <item> + <key> <string>form_id</string> </key> + <value> <string>Base_viewFieldLibrary</string> </value> + </item> + <item> + <key> <string>target</string> </key> + <value> <string>Click to edit the target</string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string>File Attachment</string> </value> + </item> + </dictionary> + </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/erp5_discussion.css.xml b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/erp5_discussion.css.xml index 573a517891..c5d248f8be 100644 --- a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/erp5_discussion.css.xml +++ b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/erp5_discussion.css.xml @@ -12,7 +12,7 @@ </item> <item> <key> <string>_EtagSupport__etag</string> </key> - <value> <string>ts51500035.8</string> </value> + <value> <string>ts74061029.5</string> </value> </item> <item> <key> <string>__name__</string> </key> @@ -27,6 +27,10 @@ <value> <string>/*\n ERP5 discussion forum.\n */\n +.attachment {\n + width:100%;\n + float:left;\n +}\n \n .discussion-post-header{\n background-color: #efefef;\n @@ -96,7 +100,7 @@ blockquote {\n </item> <item> <key> <string>size</string> </key> - <value> <int>964</int> </value> + <value> <int>1008</int> </value> </item> <item> <key> <string>title</string> </key> diff --git a/bt5/erp5_discussion/bt/revision b/bt5/erp5_discussion/bt/revision index 50f0bcd375..d55f9f7457 100644 --- a/bt5/erp5_discussion/bt/revision +++ b/bt5/erp5_discussion/bt/revision @@ -1 +1 @@ -135 \ No newline at end of file +136 \ No newline at end of file diff --git a/bt5/erp5_discussion/bt/template_portal_type_base_category_list b/bt5/erp5_discussion/bt/template_portal_type_base_category_list index 3b0bd46e64..1e88093694 100644 --- a/bt5/erp5_discussion/bt/template_portal_type_base_category_list +++ b/bt5/erp5_discussion/bt/template_portal_type_base_category_list @@ -1,2 +1,3 @@ +Discussion Post | successor Discussion Thread | contributor Discussion Thread | source \ No newline at end of file -- 2.30.9