Skip to content

Commit cbde116

Browse files
committed
Save attachments into FS. Fixes ietf-tools#342
- Legacy-Id: 2482
1 parent f581e0f commit cbde116

7 files changed

Lines changed: 28 additions & 8 deletions

File tree

ietf/liaisons/forms.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22

33
from django import forms
4+
from django.conf import settings
45
from django.forms.util import ErrorList
56
from django.template.loader import render_to_string
67

@@ -179,6 +180,9 @@ def save_attachments(self, instance):
179180
detail = instance,
180181
file_extension = extension,
181182
)
183+
attach_file = open('%sfile%s%s' % (settings.LIAISON_ATTACH_PATH, attach.pk, attach.file_extension), 'w')
184+
attach_file.write(attached_file.read())
185+
attach_file.close()
182186

183187

184188
class IncomingLiaisonForm(LiaisonForm):
@@ -281,6 +285,7 @@ class Meta:
281285
def __init__(self, *args, **kwargs):
282286
super(EditLiaisonForm, self).__init__(*args, **kwargs)
283287
self.edit = True
288+
self.initial.update({'attachments': self.instance.uploads_set.all()})
284289

285290
def set_from_field(self):
286291
self.fields['from_field'].initial = self.instance.from_body

ietf/liaisons/widgets.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from django.conf import settings
2+
from django.db.models.query import QuerySet
13
from django.forms.widgets import Select, Widget
24
from django.utils.safestring import mark_safe
35

@@ -54,9 +56,11 @@ class ShowAttachmentsWidget(Widget):
5456
def render(self, name, value, attrs=None):
5557
html = u'<div id="id_%s">' % name
5658
html += u'<span style="display: none" class="showAttachmentsEmpty">No files attached</span>'
57-
if not value:
58-
html += u'<div class="attachedFiles">No files attached</div>'
59+
html += u'<div class="attachedFiles">'
60+
if value and isinstance(value, QuerySet):
61+
for attach in value:
62+
html += u'<a class="initialAttach" href="%sfile%s%s">%s</a><br />' % (settings.LIAISON_ATTACH_URL, attach.file_id, attach.file_extension, attach.file_title, )
5963
else:
60-
pass
61-
html += u'</div>'
64+
html += u'No files attached'
65+
html += u'</div></div>'
6266
return mark_safe(html)

ietf/settings.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
DEFAULT_FROM_EMAIL = 'IETF Secretariat <ietf-secretariat-reply@' + IETF_DOMAIN + '>'
3333

34-
LIAISON_UNIVERSAL_FROM = 'Liaison Statement Management Tool <lsmt@' + IETF_DOMAIN + '>'
35-
3634
MANAGERS = ADMINS
3735

3836
DATABASE_ENGINE = 'mysql'
@@ -176,6 +174,11 @@
176174

177175
IPR_EMAIL_TO = ['ietf-ipr@ietf.org', ]
178176

177+
# Liaison Statement Tool settings
178+
LIAISON_UNIVERSAL_FROM = 'Liaison Statement Management Tool <lsmt@' + IETF_DOMAIN + '>'
179+
LIAISON_ATTACH_PATH = '/a/www/ietf-datatracker/documents/LIAISON/'
180+
LIAISON_ATTACH_URL = '/documents/LIAISON/'
181+
179182
# Put SECRET_KEY in here, or any other sensitive or site-specific
180183
# changes. DO NOT commit settings_local.py to svn.
181184
from settings_local import *

ietf/templates/liaisons/liaisondetail_edit.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h1>{% if liaison %}Edit liaison: {{ liaison }}{% else %}Send Liaison Statement{
1313
{% if not liaison %}
1414
<ul>
1515
<li>If you wish to submit your liaison statement by e-mail, then please send it to <a href="mailto:statements@ietf.org">statements@ietf.org</a></li>
16-
<li>Fields marked with <span class="requiredField">*</span> are required. For detailed descriptions of the fields see <a href="https://datatracker.ietf.org/liaison/help/fields/">Field help</a></li>
16+
<li>Fields marked with <span class="fieldRequired">*</span> are required. For detailed descriptions of the fields see <a href="https://datatracker.ietf.org/liaison/help/fields/">Field help</a></li>
1717
</ul>
1818
{% endif %}
1919

ietf/templates/liaisons/liaisonform.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{% endblock %}
99
</div>
1010

11-
<div class="baseform">
11+
<div class="baseform{% if form.edit %} baseformedit{% endif %}">
1212
{% if form.errors %}
1313
<div class="formErrors">
1414
Please correct the errors below.

static/css/liaisons.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@
5252
}
5353

5454
#id_title,
55+
.baseformedit #id_from_field,
56+
.baseformedit #id_replyto,
57+
.baseformedit #id_organization,
58+
.baseformedit #id_to_poc,
59+
.baseformedit #id_response_contact,
60+
.baseformedit #id_technical_contact,
61+
.baseformedit #id_cc1,
5562
.baseform textarea {
5663
width: 80%;
5764
}

static/js/liaisons.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
config.showOn = $('#' + fieldset.find('.showAttachsOn').html());
2323
config.showOnDisplay = config.showOn.find('.attachedFiles');
24+
count = config.showOnDisplay.find('.initialAttach').length;
2425
config.showOnEmpty = config.showOn.find('.showAttachmentsEmpty').html();
2526
config.enabledLabel = fieldset.find('.attachEnabledLabel').html();
2627
};

0 commit comments

Comments
 (0)