View attachments in Web Form

This commit is contained in:
JodeQ 2018-09-13 22:52:15 +02:00
parent bdbf604317
commit 43a98fbd60
3 changed files with 1394 additions and 1331 deletions

View file

@ -166,6 +166,26 @@
</div>
{% if show_attachments and not frappe.form_dict.new -%}
<div class="attachments">
<h3>{{ _("Attachments") }}</h3>
{% for attachment in attachments %}
<div class="attachment">
<a class="no-decoration attachment-link" href="{{ attachment.file_url }}" target="blank">
<div class="row">
<div class="col-xs-9">
<span class="file-name">{{ attachment.file_name }}</span>
</div>
<div class="col-xs-3">
<span class="pull-right file-size">{{ attachment.file_size }}</span>
</div>
</div>
</a>
</div>
{% endfor %}
</div>
{%- endif %}
{% if allow_comments and not frappe.form_dict.new -%}
<div class="comments">
<br><br>
@ -204,6 +224,12 @@ frappe.boot = {
}
};
{% if show_attachments and not frappe.form_dict.new -%}
$(".file-size").each(function() {
$(this).text(frappe.form.formatters.FileSize($(this).text()));
});
{%- endif %}
// for backward compatibility of some libs
frappe.sys_defaults = frappe.boot.sysdefaults;
{% if row_template %}web_form_settings.web_form_row_template = "{{ row_template }}";{% endif %}

File diff suppressed because it is too large Load diff

View file

@ -187,6 +187,10 @@ def get_context(context):
context.reference_doctype = context.doc.doctype
context.reference_name = context.doc.name
if self.show_attachments:
context.attachments = frappe.get_all('File', filters= {"attached_to_name": context.reference_name, "attached_to_doctype": context.reference_doctype, "is_private": 0},
fields=['file_name','file_url', 'file_size'])
if self.allow_comments:
context.comment_list = get_comment_list(context.doc.doctype,
context.doc.name)