diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-07-05 13:25:47 +0200 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-07-05 13:25:47 +0200 |
commit | ecca23e67b63ef6c9577652a7ea820645a3d9b55 (patch) | |
tree | 9666b059700531f6be00ff362798b585852ea4bc | |
parent | df0b5fb2fb74d1dec39bca6e60b04b49619caf81 (diff) | |
download | hyperkitty-ecca23e67b63ef6c9577652a7ea820645a3d9b55.tar.gz hyperkitty-ecca23e67b63ef6c9577652a7ea820645a3d9b55.tar.xz hyperkitty-ecca23e67b63ef6c9577652a7ea820645a3d9b55.zip |
Add an attachment field to replies and new emails
-rw-r--r-- | hyperkitty/lib/__init__.py | 19 | ||||
-rw-r--r-- | hyperkitty/templates/message_new.html | 2 | ||||
-rw-r--r-- | hyperkitty/templates/messages/reply_form.html | 2 | ||||
-rw-r--r-- | hyperkitty/views/forms.py | 2 | ||||
-rw-r--r-- | hyperkitty/views/message.py | 6 |
5 files changed, 23 insertions, 8 deletions
diff --git a/hyperkitty/lib/__init__.py b/hyperkitty/lib/__init__.py index 0317b92..fbfc38d 100644 --- a/hyperkitty/lib/__init__.py +++ b/hyperkitty/lib/__init__.py @@ -105,7 +105,8 @@ def daterange(start_date, end_date): class PostingFailed(Exception): pass -def post_to_list(request, mlist, subject, message, headers={}): +def post_to_list(request, mlist, subject, message, headers={}, + attachments=None): if not mlist: # Make sure the list exists to avoid posting to any email addess raise SuspiciousOperation("I don't know this mailing-list") @@ -117,15 +118,25 @@ def post_to_list(request, mlist, subject, message, headers={}): "your message has not been sent.") # send the message headers["User-Agent"] = "HyperKitty on %s" % request.build_absolute_uri("/") + if not request.user.first_name and not request.user.last_name: + from_email = request.user.email + else: + from_email = '"%s %s" <%s>' % (request.user.first_name, + request.user.last_name, + request.user.email) msg = EmailMessage( subject=subject, body=message, - from_email='"%s %s" <%s>' % - (request.user.first_name, request.user.last_name, - request.user.email), + from_email=from_email, to=[mlist.name], headers=headers, ) + # Attachments + if attachments: + if not isinstance(attachments, list): + attachments = [attachments] + for attach in attachments: + msg.attach(attach.name, attach.read()) msg.send() diff --git a/hyperkitty/templates/message_new.html b/hyperkitty/templates/message_new.html index 25e7c03..56d25f5 100644 --- a/hyperkitty/templates/message_new.html +++ b/hyperkitty/templates/message_new.html @@ -30,7 +30,7 @@ Create a new thread - {{ mlist.display_name|default:mlist.name|escapeemail }} - {% endif %} <div class="new-thread-form"> - <form method="post" + <form method="post" enctype="multipart/form-data" action="{% url 'message_new' mlist_fqdn=mlist.name %}"> {% csrf_token %} {{ post_form|crispy }} diff --git a/hyperkitty/templates/messages/reply_form.html b/hyperkitty/templates/messages/reply_form.html index 44dcc3a..1b722de 100644 --- a/hyperkitty/templates/messages/reply_form.html +++ b/hyperkitty/templates/messages/reply_form.html @@ -2,7 +2,7 @@ <a class="reply{% if not user.is_authenticated %} disabled" title="You must be logged-in to reply.{% endif %}" href="#">Reply</a> <div class="reply-form dropdown"> - <form method="post" + <form method="post" enctype="multipart/form-data" action="{% url 'message_reply' mlist_fqdn=mlist_fqdn message_id_hash=message_id_hash %}"> {% csrf_token %} <p class="reply-tools"> diff --git a/hyperkitty/views/forms.py b/hyperkitty/views/forms.py index 62175e7..034b7d9 100644 --- a/hyperkitty/views/forms.py +++ b/hyperkitty/views/forms.py @@ -103,7 +103,9 @@ class ReplyForm(forms.Form): subject = forms.CharField(label="", required=False, widget=forms.TextInput(attrs={ 'placeholder': 'New subject'})) message = forms.CharField(label="", widget=forms.Textarea) + attachment = forms.FileField(required=False) class PostForm(forms.Form): subject = forms.CharField() message = forms.CharField(widget=forms.Textarea) + attachment = forms.FileField(required=False) diff --git a/hyperkitty/views/message.py b/hyperkitty/views/message.py index 365a7a7..4266877 100644 --- a/hyperkitty/views/message.py +++ b/hyperkitty/views/message.py @@ -177,7 +177,8 @@ def reply(request, mlist_fqdn, message_id_hash): headers = {"In-Reply-To": "<%s>" % message.message_id, "References": "<%s>" % message.message_id, } try: - post_to_list(request, mlist, subject, form.cleaned_data["message"], headers) + post_to_list(request, mlist, subject, form.cleaned_data["message"], + headers, attachments=request.FILES.getlist('attachment')) except PostingFailed, e: return HttpResponse(str(e), content_type="text/plain", status=500) @@ -216,7 +217,8 @@ def new_message(request, mlist_fqdn): redirect_url += "?msg=sent-ok" try: post_to_list(request, mlist, form.cleaned_data['subject'], - form.cleaned_data["message"]) + form.cleaned_data["message"], + attachments=request.FILES.getlist("attachment")) except PostingFailed, e: failure = str(e) else: |