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..f3419b6 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; diff --git a/src/postorius/templates/postorius/lists/held_messages.html b/src/postorius/templates/postorius/lists/held_messages.html index cc359d4..3ce6fa8 100644 --- a/src/postorius/templates/postorius/lists/held_messages.html +++ b/src/postorius/templates/postorius/lists/held_messages.html @@ -11,23 +11,36 @@ {% block body_class %}list_summary{% endblock %} {% block main %} + {% list_nav 'list_held_messages' "Held Messages" %} {% if list.held|length > 0 %} - +
+ {% if form.choices.errors %} +
{{ form.choices.errors.0 }}
+ {% endif %} + {% csrf_token %} - - - - - - - - - + + + + + + + + + + + + {% for msg in list.held %} + @@ -36,7 +49,6 @@
{% trans 'Subject' %}{% trans 'Sender' %}{% trans 'Reason' %}{% trans 'Hold Date' %} 
{% trans 'Perform action on selected messages' %} + + + +
{% trans 'Subject' %}{% trans 'Sender' %}{% trans 'Reason' %}{% trans 'Hold Date' %}
{{ msg.subject }} {{ msg.sender }} {{ msg.reason }} {% trans 'View' %} {% trans 'Accept' %} - {% trans 'Defer' %} {% trans 'Reject' %} {% trans 'Discard' %} @@ -58,7 +70,7 @@ {% endfor %}
- +
{% else %}

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

@@ -66,3 +78,11 @@ {% endif %} {% endblock %} +{% block additionaljs %} + +{% endblock %} \ No newline at end of file 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. """