From 2dae59225844fc3c515a652bf48709142b584cfa Mon Sep 17 00:00:00 2001 From: Pratyush Desai Date: Sat, 8 Jan 2022 11:49:19 +0530 Subject: [PATCH] snippetadmin init, logentries --- .gitignore | 7 ++-- website/db.sqlite3 | Bin 155648 -> 155648 bytes website/snippets/admin.py | 79 +++++++++++++++++++++++++++++++++++++- 3 files changed, 81 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 306b406..0bcdbc3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ -venv -.vscode -__pycache__ +venv/ +.vscode/ +__pycache__/ db.sqlite3 -website/db.sqlite3 diff --git a/website/db.sqlite3 b/website/db.sqlite3 index 3c5d131b5a6542828c0bfe38e44ca16181e2de95..2b93ace7cda55dd51f3f4895b332598fe0661730 100644 GIT binary patch delta 440 zcmZoTz}awsbAmLZ(L@<%Mx%`h75a>vn{VoC7;y9FGBEP(XW-kY$^Gf*4 ztPBmTOpWy{4GoMfjVC+i>##5|Fif7<*w4eo|DA!6|1|^uYyQ`p1sm@3Pkvp`!wHlH zVFre#hHVXuEDGCM448iNGqNl*U=rZs1&TBBUt-|Dv{|s=1izjRBPW9+zc?==BcqXl zk&&)}p{{|2f&tJ{Ln~urJqtraGaydN&rd35VPf8P0caiv6Yn+#zT3RpHa4!})o4;; zV)bnfcC56pEX~g?G%7aBOHVg6NG>bM&n(TT$hIs>GtW&+E}72!pK*()Nx6rWPjRTf zS&5fLNlsL;sfDv^d9iV#r$KQ*j#G9>nv5Jw{M#A$@9=L2dS*4hstU6&BO!M%O~1p>qyf};n1TNh|6!oU?fmj`%#LvH OW7@^E{gFJAoC5$b(S0xg delta 297 zcmZoTz}awsbAmLZ?nD`9M%|4G75a=En{VoC7;rN%Ffj4$XW-A}+rP1KGvDO>c_n-% zR)&^V#)f*vrWWRgrjs4>b$A*D7%=gmvFf^_(%TIPRHt;ktEGS5K$%rhn45~;Ea&^>q@w83K z&rd2&%1?3tG4!(XlZ*_EjC2hQbqy>O41jJhv@*5SGch+eGcw`=Ig|f21OIm*0Ro%F z8gB7VeqGPQ$-ykn2{x&zVOs+ui^5`-2?onqE-)&vG4kDJ;JdxC@gm>$+y59f8QB>5 k?=bM+*(_LaiGTVXekKi|z#|6!M?ira{M#SNGs!ss0Gj1lMF0Q* diff --git a/website/snippets/admin.py b/website/snippets/admin.py index 8c38f3f..ee99978 100644 --- a/website/snippets/admin.py +++ b/website/snippets/admin.py @@ -1,3 +1,80 @@ from django.contrib import admin +from django.contrib.admin.models import LogEntry, DELETION -# Register your models here. +from django.utils.html import escape +from django.utils.safestring import mark_safe + +from django.urls import reverse + +from snippets.models import * + + + +#LogEntry +@admin.register(LogEntry) +class LogEntryAdmin(admin.ModelAdmin): + # to have a date-based drilldown navigation in the admin page + date_hierarchy = "action_time" + + # to filter the resultes by users, content types and action flags + list_filter = ["user", "content_type", "action_flag"] + + # when searching the user will be able to search in both object_repr and change_message + search_fields = ["object_repr", "change_message"] + + list_display = [ + "action_time", + "user", + "content_type", + "action_flag", + "object_link", + ] + + def has_add_permission(self, request): + return False + + def has_change_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False + + def has_view_permission(self, request, obj=None): + return request.user.is_staff + + def object_link(self, obj): + if obj.action_flag == DELETION: + link = escape(obj.object_repr) + else: + ct = obj.content_type + link = '%s' % ( + reverse( + "admin:%s_%s_change" % (ct.app_label, ct.model), + args=[obj.object_id], + ), + escape(obj.object_repr), + ) + return mark_safe(link) + + object_link.admin_order_field = "object_repr" + object_link.short_description = "object" + + +@admin.register(Snippet) +class SnippetAdmin(admin.ModelAdmin): + + date_hierarchy = "created" + ordering= ['-created'] + # add hyperlinked highlighted view and + # possibly code preview js magic + list_filter = ('owner', 'language', 'style') + list_display = ['id', + 'title', + 'owner', + 'created', + 'language'] + search_fields = ['owner', 'title', 'language'] + +# @admin.register) +# class SnippetAdmin(admin.ModelAdmin): + # pass \ No newline at end of file