diff --git a/src/postorius/forms.py b/src/postorius/forms.py index a13d814..3853ed7 100644 --- a/src/postorius/forms.py +++ b/src/postorius/forms.py @@ -843,3 +843,20 @@ required=False, widget=forms.Select(), choices=((address, address) for address in user_emails)) + + +class HeldMessagesModerationForm(forms.Form): + + class HeldMessageMultipleChoiceField(forms.MultipleChoiceField): + + def validate(self, value): + pass + + choices = HeldMessageMultipleChoiceField( + widget=forms.CheckboxSelectMultiple, + ) + + def clean_choices(self): + if len(self.cleaned_data['choices']) < 1: + raise forms.ValidationError(_('Please select at least one message to perform an action')) + return self.cleaned_data['choices'] diff --git a/src/postorius/static/postorius/css/style.css b/src/postorius/static/postorius/css/style.css index 04c2f9b..390fa13 100755 --- a/src/postorius/static/postorius/css/style.css +++ b/src/postorius/static/postorius/css/style.css @@ -1,6 +1,9 @@ html { overflow-y: scroll; } +.hidden { + display: none; +} body { color: #444; @@ -307,7 +310,3 @@ .well .archival-options-form li { display: block; } - -.hidden { - display: none; -} diff --git a/src/postorius/templates/postorius/lists/held_messages.html b/src/postorius/templates/postorius/lists/held_messages.html index cc359d4..924c052 100644 --- a/src/postorius/templates/postorius/lists/held_messages.html +++ b/src/postorius/templates/postorius/lists/held_messages.html @@ -1,68 +1,84 @@ {% extends postorius_base_template %} {% load url from future %} {% load i18n %} - -{% block subtitle %} -{% trans "Held Messages | " as page_title %}{{ page_title|add:list.fqdn_listname}} -{% endblock %} - {% load nav_helpers %} -{% block body_class %}list_summary{% endblock %} +{% block subtitle %} +{% trans 'Held Messages' %} | {{ list.fqdn_listname }} +{% endblock %} {% block main %} - {% list_nav 'list_held_messages' "Held Messages" %} + {% list_nav 'list_held_messages' 'Held Messages' %} + {% if list.held|length > 0 %} +
+ {% if form.choices.errors %} + {% for error in form.choices.errors %} +
{{ error }}
+ {% endfor %} + {% endif %} + {% csrf_token %} + + + + + + + + + + + + + + + + + {% for msg in list.held %} + + + + + + - {% if list.held|length > 0 %} + - - {% endfor %} - -
{% trans 'Perform action on selected messages' %} + + + +
{% trans 'Subject' %}{% trans 'Sender' %}{% trans 'Reason' %}{% trans 'Hold Date' %}
{{ msg.subject }}{{ msg.sender }}{{ msg.reason }}{{ msg.hold_date }} + {% trans 'View' %} + {% trans 'Accept' %} + {% trans 'Reject' %} + {% trans 'Discard' %} - - - - - - - - - - - - {% for msg in list.held %} - - - - - + + + + {% endfor %} + +
{% trans 'Subject' %}{% trans 'Sender' %}{% trans 'Reason' %}{% trans 'Hold Date' %} 
{{ msg.subject }}{{ msg.sender }}{{ msg.reason }}{{ msg.hold_date }}
+ + {% else %} +

{% trans 'There are currently no held messages.' %}

+ {% endif %} +{% endblock %} -
- {% trans 'View' %} - {% trans 'Accept' %} - {% trans 'Defer' %} - {% trans 'Reject' %} - {% trans 'Discard' %} - - -
- - {% else %} - -

{% trans 'There are currently no held messages.' %}

- - {% endif %} - +{% block additionaljs %} + {% endblock %} diff --git a/src/postorius/urls.py b/src/postorius/urls.py index 729dc8e..b604584 100644 --- a/src/postorius/urls.py +++ b/src/postorius/urls.py @@ -83,7 +83,7 @@ 'reject$', 'reject_held_message', name='reject_held_message'), url(r'^held_messages$', - 'list_held_messages', + ListModerationView.as_view(), name='list_held_messages'), url(r'^remove/(?P[^/]+)/' '(?P
[^/]+)', diff --git a/src/postorius/views/list.py b/src/postorius/views/list.py index 0104aa6..c8fe250 100644 --- a/src/postorius/views/list.py +++ b/src/postorius/views/list.py @@ -384,6 +384,44 @@ return redirect('mass_removal', self.mailing_list.list_id) +class ListModerationView(MailingListView): + + """Class for moderating held messages""" + + @staticmethod + def _perform_action(message_ids, action): + for message_id in message_ids: + action(message_id) + + @method_decorator(list_moderator_required) + def get(self, request, *args, **kwargs): + return render_to_response('postorius/lists/held_messages.html', + {'list': self.mailing_list, 'form':HeldMessagesModerationForm()}, + context_instance=RequestContext(request)) + + @method_decorator(list_moderator_required) + def post(self, request, *args, **kwargs): + form = HeldMessagesModerationForm(request.POST) + if form.is_valid(): + message_ids = form.cleaned_data['choices'] + try: + if 'accept' in request.POST: + ListModerationView._perform_action(message_ids, self.mailing_list.accept_message) + messages.success(request, _('The selected messages were accepted')) + elif 'reject' in request.POST: + ListModerationView._perform_action(message_ids, self.mailing_list.reject_message) + messages.success(request, _('The selected messages were rejected')) + elif 'discard' in request.POST: + ListModerationView._perform_action(message_ids, self.mailing_list.discard_message) + messages.success(request, _('The selected messages were discarded')) + except MailmanApiError: + return utils.render_api_error(request) + except HTTPError as e: + messages.error(request, e.msg) + return render_to_response('postorius/lists/held_messages.html', + {'list': self.mailing_list, 'form':form}, + context_instance=RequestContext(request)) + @list_owner_required def csv_view(request, list_id): """Export all the subscriber in csv @@ -628,19 +666,6 @@ @list_moderator_required -def list_held_messages(request, list_id): - """Shows a list of held messages. - """ - try: - the_list = List.objects.get_or_404(fqdn_listname=list_id) - except MailmanApiError: - return utils.render_api_error(request) - return render_to_response('postorius/lists/held_messages.html', - {'list': the_list}, - context_instance=RequestContext(request)) - - -@list_moderator_required def accept_held_message(request, list_id, msg_id): """Accepts a held message. """