diff --git a/admin_reskin/admin.py b/admin_reskin/admin.py new file mode 100644 index 0000000..afd5d72 --- /dev/null +++ b/admin_reskin/admin.py @@ -0,0 +1,32 @@ +from django.contrib import admin +from django.http import HttpResponse +from django.urls import path +from django.utils.decorators import method_decorator +from django.views.decorators.csrf import csrf_exempt + +from . import models + + +@admin.register(models.Bookmark) +class BookmarkAdmin(admin.ModelAdmin): + list_display = ('name', 'url', 'is_active') + list_filter = ('is_active',) + list_editable = ('is_active',) + + def get_urls(self): + urls = super().get_urls() + custom_urls = [ + path('add-bookmark', self.admin_site.admin_view(self.add_bookmark_view), name='admin_reskin_add_bookmark'), + ] + return custom_urls + urls + + @method_decorator(csrf_exempt) + def add_bookmark_view(self, request): + if request.method == 'POST': + name = request.POST.get('name') + url = request.POST.get('url') + models.Bookmark.objects.create( + name=name, + url=url, + ) + return HttpResponse() diff --git a/admin_reskin/migrations/0001_initial.py b/admin_reskin/migrations/0001_initial.py new file mode 100644 index 0000000..1d88c41 --- /dev/null +++ b/admin_reskin/migrations/0001_initial.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2 on 2021-10-21 03:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Bookmark', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=45)), + ('url', models.CharField(max_length=1000)), + ('is_active', models.BooleanField(default=True)), + ], + ), + ] diff --git a/admin_reskin/migrations/__init__.py b/admin_reskin/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/admin_reskin/models.py b/admin_reskin/models.py new file mode 100644 index 0000000..39ea2d5 --- /dev/null +++ b/admin_reskin/models.py @@ -0,0 +1,10 @@ +from django.db import models + + +class Bookmark(models.Model): + name = models.CharField(max_length=45) + url = models.CharField(max_length=1000) + is_active = models.BooleanField(default=True) + + def __str__(self): + return self.name \ No newline at end of file diff --git a/admin_reskin/templates/admin/app_list.html b/admin_reskin/templates/admin/app_list.html index cc4b6a2..81f9813 100644 --- a/admin_reskin/templates/admin/app_list.html +++ b/admin_reskin/templates/admin/app_list.html @@ -3,6 +3,7 @@ {% if app_list %} {% for app in app_list|sort_apps %} +{% if not app.app_label == 'admin_reskin_bookmark' or request.user.is_superuser %}
{% translate 'You don’t have permission to view or edit anything.' %}
diff --git a/admin_reskin/templates/admin/base_site.html b/admin_reskin/templates/admin/base_site.html index caa48ab..5b47f44 100644 --- a/admin_reskin/templates/admin/base_site.html +++ b/admin_reskin/templates/admin/base_site.html @@ -5,6 +5,26 @@