Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pending users Admin filters #2186

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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