Commit d6baaf8e authored by Ivan Tyagov's avatar Ivan Tyagov

Make it possible to add attachments to a post.

parent 76282344
<base_category_list>
<portal_type id="Discussion Post">
<item>successor</item>
</portal_type>
<portal_type id="Discussion Thread">
<item>contributor</item>
<item>source</item>
......
<?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>
......@@ -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
......
......@@ -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>
......
......@@ -95,6 +95,7 @@
<list>
<string>your_title</string>
<string>your_text_content</string>
<string>your_file</string>
<string>your_captcha</string>
</list>
</value>
......
<?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>
......@@ -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>
......
......@@ -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>
......
<?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>
......@@ -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>
......
135
\ No newline at end of file
136
\ No newline at end of file
Discussion Post | successor
Discussion Thread | contributor
Discussion Thread | source
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment