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 3c5d131..2b93ace 100644 Binary files a/website/db.sqlite3 and b/website/db.sqlite3 differ 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