-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"""Backend Admin pages""" | ||
from django.contrib import admin | ||
|
||
from backend.forms import AdminSongForm | ||
from backend.models import Song | ||
|
||
|
||
@admin.register(Song) | ||
class SongAdmin(admin.ModelAdmin): | ||
"""Song Admin config""" | ||
|
||
form = AdminSongForm | ||
list_display = ["name", "get_categories"] | ||
|
||
@admin.display(description="Categories") | ||
def get_categories(self, obj): | ||
"""Displays all categorties in a string""" | ||
return "\n".join([p.name for p in obj.categories.all()]) | ||
|
||
get_categories.admin_order_field = "categories__name" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Category admin classes""" | ||
from django.contrib import admin | ||
from django.http import HttpResponseRedirect | ||
from django.urls import reverse, reverse_lazy | ||
from django.utils.html import format_html | ||
from django.utils.http import urlencode | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from category.models import Category | ||
|
||
|
||
@admin.register(Category) | ||
class CategoryAdmin(admin.ModelAdmin): | ||
"""Category Admin Model""" | ||
|
||
list_display = ["name", "tenant_name"] | ||
# list_display_links = ["tenant_name"] | ||
actions = ["move_tenant"] | ||
|
||
@admin.display(description=_("Tenant")) | ||
def tenant_name(self, obj): | ||
"""Shows Tenant name""" | ||
link = reverse("admin:tenants_tenant_change", args=[obj.tenant.id]) | ||
return format_html('<a href="{}">{}</a>', link, obj.tenant.name) | ||
|
||
@admin.action(description=_("Move Category to a different Tenant")) | ||
def move_tenant(self, request, queryset): | ||
"""Moves Categories to a different Tenant""" | ||
ids = queryset.values_list("id", flat=True) | ||
url = f"{reverse_lazy('category:move')}?{urlencode({'pk': list(ids)}, True)}" | ||
return HttpResponseRedirect(url) | ||
|
||
tenant_name.admin_order_field = "tenant__id" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{% extends "admin/base/migrate.html" %} | ||
{% load i18n %} | ||
{% load bootstrap4 %} | ||
|
||
{% block title %}{% trans "Migrating categories to Tenant" %}{% endblock %} | ||
{% block content_title %}{% trans "Migrating categories to Tenant" %}{% endblock %} | ||
{% block object_name %}{% trans "Categories" %}{% endblock %} | ||
{% block target %}{% trans "To Tenant" %}{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{% extends "admin/base.html" %} | ||
{% load i18n %} | ||
{% load bootstrap4 %} | ||
|
||
{% block title %}{% endblock %} | ||
{% block content_title %}{% endblock %} | ||
{% block content %} | ||
<form method="post"> | ||
{% csrf_token %} | ||
{{ formset.management_form }} | ||
{{ formset.non_form_errors.as_ul }} | ||
<h4>{% block object_name %}{% endblock %}</h4> | ||
<div id="sortable" class="mb-3"> | ||
{% for form in formset.forms %} | ||
<div> | ||
{% for hidden in form.hidden_fields %} | ||
{{ hidden }} | ||
{% endfor %} | ||
{% for field in form.visible_fields %} | ||
{% bootstrap_field field layout="horizontal" show_label=False size="small"%} | ||
{% endfor %} | ||
<hr> | ||
</div> | ||
{% endfor %} | ||
</div> | ||
<hr> | ||
<h4>{% block target %}{% endblock %}</h4> | ||
{% bootstrap_form form %} | ||
{% buttons %} | ||
<button type="submit">{% trans "Submit" %}</button> | ||
{% endbuttons %} | ||
</form> | ||
{{ form.media }} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""PDF Admin classes""" | ||
from urllib.parse import urlencode | ||
|
||
from django.contrib import admin | ||
from django.http import HttpResponseRedirect | ||
from django.urls import reverse_lazy, reverse | ||
from django.utils.html import format_html | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from pdf.models.request import PDFRequest | ||
|
||
|
||
@admin.register(PDFRequest) | ||
class RequestAdmin(admin.ModelAdmin): | ||
"""Request Model Admin""" | ||
|
||
list_display = ["id", "title", "update_date", "type", "file", "status", "tenant_name"] | ||
actions = ["move_tenant"] | ||
|
||
@admin.display(description=_("Tenant")) | ||
def tenant_name(self, obj): | ||
"""Shows Tenant name""" | ||
link = reverse("admin:tenants_tenant_change", args=[obj.tenant.id]) | ||
return format_html('<a href="{}">{}</a>', link, obj.tenant.name) | ||
|
||
@admin.action(description=_("Move Request to a different Tenant")) | ||
def move_tenant(self, request, queryset): | ||
"""Move Request to a different Tenant""" | ||
ids = queryset.values_list("id", flat=True) | ||
url = f"{reverse_lazy('pdf:move')}?{urlencode({'pk': list(ids)}, True)}" | ||
return HttpResponseRedirect(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{% extends "admin/base/migrate.html" %} | ||
{% load i18n %} | ||
{% load bootstrap4 %} | ||
|
||
{% block title %}{% trans "Migrating PDFRequests to Tenant" %}{% endblock %} | ||
{% block content_title %}{% trans "Migrating PDFRequests to Tenant" %}{% endblock %} | ||
{% block object_name %}{% trans "PDFRequest" %}{% endblock %} | ||
{% block target %}{% trans "To Tenant" %}{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Admin models for Tenants""" | ||
from django.conf import settings | ||
from django.contrib import admin | ||
from django.urls import reverse_lazy, reverse | ||
from django.utils.html import format_html | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from category.models import Category | ||
from tenants.forms import TenantForm | ||
from tenants.models import Tenant | ||
|
||
|
||
@admin.register(Tenant) | ||
class TenantAdmin(admin.ModelAdmin): | ||
"""Tenant Admin view""" | ||
|
||
list_display = ["name", "hostname_link", "display_name"] | ||
form = TenantForm | ||
|
||
@admin.display(description=_("Tenant")) | ||
def hostname_link(self, obj): | ||
"""Shows link to the tenants homepage""" | ||
link = reverse("chords:index") | ||
return format_html('<a href="{}{}">{}</a>', obj.hostname, link, obj.hostname) | ||
|
||
def save_model(self, request, obj, form, change): | ||
"""Overrides saving method to create default category and redirect index page to it""" | ||
if obj.index_redirect == "/": | ||
obj.index_redirect = reverse_lazy("category:index", kwargs={"slug": "default"}) | ||
super().save_model(request, obj, form, change) | ||
if not Category.objects.filter(tenant=obj).exists(): | ||
Category.objects.create( | ||
tenant=obj, name="Default Category", slug="default", locale=settings.LANGUAGES[0][0], generate_pdf=False | ||
) | ||
|
||
|
||
admin.site.login_template = "registration/login.html" |