Skip to content

Commit

Permalink
Add resend button to message admin page
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanw committed Mar 11, 2013
1 parent f0a392d commit 74881d6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
5 changes: 3 additions & 2 deletions froide/foirequest/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ def get_postal_attachment_form(self):
from froide.foirequest.forms import PostalAttachmentForm
return PostalAttachmentForm()

def send(self):
def send(self, notify=True):
if settings.FROIDE_CONFIG['dryrun']:
recp = self.recipient_email.replace("@", "+")
self.recipient_email = "%s@%s" % (recp, settings.FROIDE_CONFIG['dryrun_domain'])
Expand All @@ -1140,7 +1140,8 @@ def send(self):
[self.recipient_email])
self.sent = True
self.save()
FoiRequest.message_sent.send(sender=self.request, message=self)
if notify:
FoiRequest.message_sent.send(sender=self.request, message=self)


def upload_to(instance, filename):
Expand Down
2 changes: 1 addition & 1 deletion froide/foirequest/request_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
url(r"^(?P<slug>[-\w]+)/approve/(?P<attachment>\d+)/$", 'approve_attachment', name="foirequest-approve_attachment"),
url(r"^(?P<slug>[-\w]+)/approve/message/(?P<message>\d+)/$", 'approve_message', name="foirequest-approve_message"),
url(r"^(?P<slug>[-\w]+)/make-same/(?P<message_id>\d+)/$", 'make_same_request', name="foirequest-make_same_request"),

url(r"^(?P<slug>[-\w]+)/resend/$", 'resend_message', name="foirequest-resend_message"),
# Redaction
url(r"^(?P<slug>[-\w]+)/redact/(?P<attachment_id>\d+)/$", 'redact_attachment', name="foirequest-redact_attachment"),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "admin/change_form.html" %}
{% load i18n %}
{% block object-tools-items %}
{% if not original.sent %}
<li><form method="post" action="{% url 'foirequest-resend_message' slug=original.request.slug %}">{% csrf_token %}
<input type="hidden" name="message" value="{{ original.pk }}"/>
<button type="submit" class="btn">{% blocktrans %}Resend message{% endblocktrans %}</button>
</form></li>
{% endif %}
{{ block.super }}
{% endblock %}

15 changes: 15 additions & 0 deletions froide/foirequest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,3 +866,18 @@ def extend_deadline(request, slug):
_('Deadline has been extended.'))
FoiEvent.objects.create_event('deadline_extended', foirequest)
return redirect(foirequest)


@require_POST
def resend_message(request, slug):
foirequest = get_object_or_404(FoiRequest, slug=slug)
if not request.user.is_authenticated():
return render_403(request)
if not request.user.is_staff:
return render_403(request)
try:
mes = FoiMessage.objects.get(sent=False, request=foirequest, pk=int(request.POST.get('message', 0)))
except FoiMessage.DoesNotExist:
raise Http404
mes.send(notify=False)
return redirect('admin:foirequest_foimessage_change', mes.id)

0 comments on commit 74881d6

Please sign in to comment.