Skip to content

Commit 843f5b5

Browse files
Merge pull request #2186 from IFRCGo/feature/pending-users-admin-filters
Pending users Admin filters
2 parents 619042c + 702d279 commit 843f5b5

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

api/templates/admin/submit_line.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
{% if show_save_and_next %}<input type="submit" value="{% trans 'Save and view next one' %}" name="_save_next">{% endif %}
1313
{% if show_save_and_add_another %}<input type="submit" value="{% trans 'Save and add another' %}" name="_addanother">{% endif %}
1414
{% if show_save_and_continue %}<input type="submit" value="{% if can_change %}{% trans 'Save and continue editing' %}{% else %}{% trans 'Save and view' %}{% endif %}" name="_continue">{% endif %}
15+
{% if show_approve_user %}<input type="submit" value="{% trans 'Approve user' %}" name="_approve_user">{% endif %}
1516
{% if show_close %}<a href="{% url opts|admin_urlname:'changelist' %}" class="closelink">{% trans 'Close' %}</a>{% endif %}
1617
{% endblock %}
1718
</div>

registrations/admin.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.contrib import admin
33
from django.http import HttpResponseRedirect
44
from django.template.loader import render_to_string
5+
from django_admin_listfilter_dropdown.filters import RelatedDropdownFilter
56
from reversion_compare.admin import CompareVersionAdmin
67

78
import registrations.models as models
@@ -22,11 +23,16 @@ class PendingAdmin(CompareVersionAdmin):
2223
"get_phone",
2324
"justification",
2425
"created_at",
26+
"email_verified",
2527
)
2628
search_fields = ("user__username", "user__email", "admin_contact_1", "admin_contact_2")
2729
list_display = ("get_username_and_mail", "get_region", "get_country", "created_at", "email_verified")
2830
actions = ("activate_users",)
29-
list_filter = ["email_verified"]
31+
list_filter = (
32+
"email_verified",
33+
("user__profile__country__region", RelatedDropdownFilter),
34+
("user__profile__country", RelatedDropdownFilter),
35+
)
3036

3137
change_form_template = "admin/pending_change_form.html"
3238
change_list_template = "admin/pending_change_list.html"
@@ -146,6 +152,20 @@ def response_change(self, request, obj):
146152
return HttpResponseRedirect(".")
147153
return super().response_change(request, obj)
148154

155+
def change_view(self, request, object_id, form_url="", extra_context=None):
156+
extra_context = {
157+
"show_approve_user": True,
158+
"show_save": False,
159+
"show_save_and_add_another": False,
160+
"show_save_and_continue": False,
161+
}
162+
return self.changeform_view(request, object_id, form_url, extra_context)
163+
164+
def save_model(self, request, obj, form, change):
165+
if "_approve_user" in request.POST:
166+
self.activate_users(request, [obj])
167+
super().save_model(request, obj, form, change)
168+
149169
def get_actions(self, request):
150170
actions = super(PendingAdmin, self).get_actions(request)
151171
return actions

0 commit comments

Comments
 (0)