Skip to content

Commit

Permalink
Merge pull request #2186 from IFRCGo/feature/pending-users-admin-filters
Browse files Browse the repository at this point in the history
Pending users Admin filters
  • Loading branch information
szabozoltan69 authored Jun 28, 2024
2 parents 619042c + 702d279 commit 843f5b5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/templates/admin/submit_line.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
{% if show_save_and_next %}<input type="submit" value="{% trans 'Save and view next one' %}" name="_save_next">{% endif %}
{% if show_save_and_add_another %}<input type="submit" value="{% trans 'Save and add another' %}" name="_addanother">{% endif %}
{% 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 %}
{% if show_approve_user %}<input type="submit" value="{% trans 'Approve user' %}" name="_approve_user">{% endif %}
{% if show_close %}<a href="{% url opts|admin_urlname:'changelist' %}" class="closelink">{% trans 'Close' %}</a>{% endif %}
{% endblock %}
</div>
22 changes: 21 additions & 1 deletion registrations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.contrib import admin
from django.http import HttpResponseRedirect
from django.template.loader import render_to_string
from django_admin_listfilter_dropdown.filters import RelatedDropdownFilter
from reversion_compare.admin import CompareVersionAdmin

import registrations.models as models
Expand All @@ -22,11 +23,16 @@ class PendingAdmin(CompareVersionAdmin):
"get_phone",
"justification",
"created_at",
"email_verified",
)
search_fields = ("user__username", "user__email", "admin_contact_1", "admin_contact_2")
list_display = ("get_username_and_mail", "get_region", "get_country", "created_at", "email_verified")
actions = ("activate_users",)
list_filter = ["email_verified"]
list_filter = (
"email_verified",
("user__profile__country__region", RelatedDropdownFilter),
("user__profile__country", RelatedDropdownFilter),
)

change_form_template = "admin/pending_change_form.html"
change_list_template = "admin/pending_change_list.html"
Expand Down Expand Up @@ -146,6 +152,20 @@ def response_change(self, request, obj):
return HttpResponseRedirect(".")
return super().response_change(request, obj)

def change_view(self, request, object_id, form_url="", extra_context=None):
extra_context = {
"show_approve_user": True,
"show_save": False,
"show_save_and_add_another": False,
"show_save_and_continue": False,
}
return self.changeform_view(request, object_id, form_url, extra_context)

def save_model(self, request, obj, form, change):
if "_approve_user" in request.POST:
self.activate_users(request, [obj])
super().save_model(request, obj, form, change)

def get_actions(self, request):
actions = super(PendingAdmin, self).get_actions(request)
return actions
Expand Down

0 comments on commit 843f5b5

Please sign in to comment.