Rafał Pitoń 11 лет назад
Родитель
Сommit
01c0a60dd2

+ 1 - 1
docs/developers/admin_actions.rst

@@ -93,7 +93,7 @@ If you add custom mass action to view, besides adding new entry to ``mass_action
 
 .. function:: action_ACTION(self, request, items)
 
-``ACTION`` will be replaced with action dict ``action`` value. Request is ``HttpRequest`` instance used to call view and ``items`` is queryset with items selected for this action. This method should nothing or ``HttpResponse``. If you need to, you can raise ``MassActionError`` with error message as its first argument to interrupt mass action handler.
+``ACTION`` will be replaced with action dict ``action`` value. Request is ``HttpRequest`` instance used to call view and ``items`` is queryset with items selected for this action. This method should return nothing or ``HttpResponse``. If you need to, you can raise ``MassActionError`` with error message as its first argument to interrupt mass action handler.
 
 
 FormView

+ 1 - 1
misago/static/misago/admin/js/misago-tables.js

@@ -83,7 +83,7 @@ function tableMassActions(label_none, label_selected) {
     $controller.prop("disabled", true);
   }
 
-  if (items_num == selected_no) {
+  if (items_num > 0 && items_num == selected_no) {
     $master.addClass('active');
   } else {
     $master.removeClass('active');

+ 1 - 1
misago/templates/misago/admin/users/list.html

@@ -95,7 +95,7 @@
 
 
 {% block emptylist %}
-<td colspan="{{ 6|add:extra_actions_len }}">
+<td colspan="{{ 9|add:extra_actions_len }}">
   <p>{% trans "No users matching search criteria have been found." %}</p>
 </td>
 {% endblock emptylist %}

+ 18 - 0
misago/templates/misago/emails/activation/by_admin.html

@@ -0,0 +1,18 @@
+{% extends "misago/emails/base.html" %}
+{% load i18n misago_capture %}
+
+
+{% block content %}
+{% blocktrans trimmed with username=recipient.username %}
+{{ username }}, your account has been activated by forum administrator.
+{% endblocktrans %}
+<br>
+<br>
+{% capture trimmed as login_link %}
+<a href="{{ SITE_ADDRESS }}{% url LOGIN_URL %}">{% trans "this form" %}</a>
+{% endcapture %}
+{% blocktrans trimmed with login_form=login_link|safe %}
+You can now sign in to it using {{ login_form }}.
+{% endblocktrans %}
+<br>
+{% endblock content %}

+ 14 - 0
misago/templates/misago/emails/activation/by_admin.txt

@@ -0,0 +1,14 @@
+{% extends "misago/emails/base.txt" %}
+{% load i18n %}
+
+
+{% block content %}
+{% blocktrans trimmed with username=recipient.username %}
+{{ username }}, your account has been activated by forum administrator.
+{% endblocktrans %}
+
+{% blocktrans trimmed %}
+You can now sign in to it using the form below:
+{% endblocktrans %}
+{{ SITE_ADDRESS }}{% url LOGIN_URL %}
+{% endblock content %}

+ 38 - 0
misago/users/views/admin/users.py

@@ -5,9 +5,12 @@ from django.utils.translation import ugettext_lazy as _
 
 from misago.admin.auth import start_admin_session
 from misago.admin.views import generic
+from misago.conf import settings
+from misago.core.mail import mail_users
 
 from misago.users.forms.admin import (StaffFlagUserFormFactory, NewUserForm,
                                       EditUserForm, SearchUsersForm)
+from misago.users.models import ACTIVATION_REQUIRED_NONE, User
 
 
 class UserAdmin(generic.AdminBaseMixin):
@@ -35,6 +38,15 @@ class UsersList(UserAdmin, generic.ListView):
         ('username_slug', _("A to z")),
         ('-username_slug', _("Z to a")),
     )
+    selection_label = _('With users: 0')
+    empty_selection_label = _('Select users')
+    mass_actions = [
+        {
+            'action': 'activate',
+            'name': _("Activate accounts"),
+            'icon': 'fa fa-check',
+        }
+    ]
 
     def get_queryset(self):
         qs = super(UsersList, self).get_queryset()
@@ -43,6 +55,32 @@ class UsersList(UserAdmin, generic.ListView):
     def get_search_form(self, request):
         return SearchUsersForm
 
+    def action_activate(self, request, users):
+        inactive_users = []
+        for user in users:
+            if user.requires_activation:
+                inactive_users.append(user)
+
+        if not inactive_users:
+            message = _("You have to select inactive users.")
+            raise generic.MassActionError(message)
+        else:
+            activated_users_pks = [u.pk for u in inactive_users]
+            queryset = User.objects.filter(pk__in=activated_users_pks)
+            queryset.update(requires_activation=ACTIVATION_REQUIRED_NONE)
+
+            mail_subject = _("Your account on %(forum_title)s "
+                             "forums has been activated")
+            subject_formats = {'forum_title': settings.forum_name}
+            mail_subject = mail_subject % subject_formats
+
+            mail_subject =  mail_subject
+            mail_users(request, inactive_users, mail_subject,
+                       'misago/emails/activation/by_admin')
+
+            message = _("Selected users accounts have been activated.")
+            messages.success(request, message)
+
 
 class NewUser(UserAdmin, generic.ModelFormView):
     Form = NewUserForm