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

WIP AP-1849 django 4.1 upgrade #22

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
31 changes: 18 additions & 13 deletions simple_audit/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.utils.html import escape
from django.urls import reverse
from django.shortcuts import redirect
from django.conf.urls import url
from django.urls import path
from .models import Audit
from .signal import MODEL_LIST

Expand Down Expand Up @@ -43,6 +43,7 @@ def queryset(self, request, queryset):
return queryset


@admin.register(Audit)
class AuditAdmin(admin.ModelAdmin):
search_fields = (
"description",
Expand All @@ -62,8 +63,8 @@ class AuditAdmin(admin.ModelAdmin):
def get_urls(self):
urls = super(AuditAdmin, self).get_urls()
my_urls = [
url(
r"^revert/(?P<audit_id>\d+)/$",
path(
"revert/<int:audit_id>/",
self.admin_site.admin_view(self.revert_change),
name="simple_audit_audit_revert",
)
Expand All @@ -85,19 +86,25 @@ def revert_change(self, request, audit_id):

return redirect("admin:simple_audit_audit_changelist")

@admin.display(
description=_("Date"),
ordering="date",
)
def format_date(self, obj):
return obj.date.strftime("%d/%m/%Y %H:%M")

format_date.short_description = _("Date")
format_date.admin_order_field = "date"

@admin.display(
description=_("Description")
)
def audit_description(self, audit):
desc = "<br/>".join(escape(audit.description or "").split("\n"))
return desc

audit_description.allow_tags = True
audit_description.short_description = _("Description")

@admin.display(
description=_("Current Content")
)
def audit_content(self, audit):
obj_string = audit.obj_description or str(audit.content_object)

Expand All @@ -113,9 +120,11 @@ def audit_content(self, audit):
}
)

audit_content.short_description = _("Current Content")
audit_content.allow_tags = True

@admin.display(
description=_("User"),
ordering="audit_request__user",
)
def audit_user(self, audit):
if audit.audit_request:
return u"<a title='%s' href='%s?user=%d'>%s</a>" % (
Expand All @@ -127,9 +136,6 @@ def audit_user(self, audit):
else:
return u"%s" % (_("unknown"))

audit_user.admin_order_field = "audit_request__user"
audit_user.short_description = _("User")
audit_user.allow_tags = True

def queryset(self, request):
request.GET = request.GET.copy()
Expand All @@ -143,4 +149,3 @@ def has_add_permission(self, request):
return False


admin.site.register(Audit, AuditAdmin)
2 changes: 1 addition & 1 deletion simple_audit/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TrackingRequestOnThreadLocalMiddleware(MiddlewareMixin):

def _get_ip(self, request):
# get real ip
if "HTTP_X_FORWARDED_FOR" in request.META:
if "x-forwarded-for" in request.headers:
ip = request.META["HTTP_X_FORWARDED_FOR"]
elif "Client-IP" in request.META:
ip = request.META["Client-IP"]
Expand Down
4 changes: 2 additions & 2 deletions testproject/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Django==3.2.10
six==1.11.0
Django==4.1.6
six==1.16.0
1 change: 0 additions & 1 deletion testproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = False
Expand Down
10 changes: 5 additions & 5 deletions testproject/simple_app/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
from django.contrib import admin


@admin.register(Pizza)
class PizzaAdmin(admin.ModelAdmin):
list_display = ('name',)
filter_horizontal = ('toppings',)


@admin.register(Topping)
class ToppingAdmin(admin.ModelAdmin):
list_display = ('name',)


@admin.register(Message)
class MessageAdmin(admin.ModelAdmin):
list_display = ('title', 'text')


@admin.register(Owner)
class OwnerAdmin(admin.ModelAdmin):
list_display = ('name',)


@admin.register(VirtualMachine)
class VirtualMachineAdmin(admin.ModelAdmin):
list_display = ('name', 'cpus', 'owner')


admin.site.register(Message, MessageAdmin)
admin.site.register(Owner, OwnerAdmin)
admin.site.register(VirtualMachine, VirtualMachineAdmin)
admin.site.register(Pizza, PizzaAdmin)
admin.site.register(Topping, ToppingAdmin)