# Path: mqueue/models.py
# class MEvent(models.Model):
#     # required fields
#     content_type = models.ForeignKey(
#         ContentType,
#         null=True,
#         blank=True,
#         verbose_name=_("Content type"),
#         on_delete=SET_NULL,
#     )
#     obj_pk = models.IntegerField(
#         blank=True, null=True, verbose_name=_("Object primary key")
#     )
#     name = models.CharField(max_length=120, verbose_name=_("Name"))
#     # content fields
#     url = models.CharField(max_length=255, blank=True, verbose_name=_("Url"))
#     admin_url = models.CharField(
#         max_length=255, blank=True, verbose_name=_("Admin url")
#     )
#     notes = models.TextField(blank=True)
#     # meta
#     date_posted = models.DateTimeField(auto_now_add=True, verbose_name=_("Date posted"))
#     event_class = models.CharField(max_length=120, blank=True, verbose_name=_("Class"))
#     user = models.ForeignKey(
#         USER_MODEL,
#         null=True,
#         blank=True,
#         related_name="+",
#         on_delete=models.SET_NULL,
#         verbose_name=_("User"),
#     )
#     groups = models.ManyToManyField(
#         Group,
#         blank=True,
#         verbose_name=_("Groups"),
#     )
#     request = models.TextField(blank=True, verbose_name=_("Request"))
#     bucket = models.CharField(max_length=60, blank=True, verbose_name=_("Bucket"))
#     data = models.TextField(blank=True, verbose_name=_("Data"))
#     # manager
#     scope = models.CharField(
#         max_length=18,
#         choices=SCOPE,
#         default=SCOPE[0][0],
#         verbose_name=_("Scope"),
#     )
#     objects = MEventManager()
# 
#     class Meta:  # type: ignore
#         app_label = "mqueue"
#         verbose_name = _("Event")
#         verbose_name_plural = _("Events")
#         ordering = ["-date_posted"]
#         # permissions = (("view_mevent", "Can see Events"),)
# 
#     def __str__(self) -> str:
#         return f"{self.name} - {self.date_posted}"
# 
# Path: mqueue/utils.py
# def format_event_class(
#     obj=None, event_class: Union[str, None] = None  # type: ignore
# ) -> str:
#     event_html = ""
#     if event_class is None:
#         _event_class: str = obj.event_class  # type: ignore
#     else:
#         _event_class = event_class
#     printed_class = get_event_class_str(event_class).replace("_", " ").capitalize()
#     icon = ""
#     if _event_class in EVENT_ICONS_HTML.keys():
#         icon = EVENT_ICONS_HTML[_event_class] + "&nbsp;"
#         # printed_class = event_class
#     else:
#         event_class_lower = _event_class.lower()
#         if "created" in event_class_lower:
#             icon = EVENT_ICONS_HTML["Object created"] + "&nbsp;"
#             printed_class = "Object created"
#         elif "edited" in event_class_lower:
#             icon = EVENT_ICONS_HTML["Object edited"] + "&nbsp;"
#             printed_class = "Object edited"
#         elif "deleted" in event_class_lower:
#             icon = EVENT_ICONS_HTML["Object deleted"] + "&nbsp;"
#             printed_class = "Object deleted"
#         else:
#             icon = EVENT_ICONS_HTML["Default"] + "&nbsp;"
#             printed_class = "Default"
#         if "error" in event_class_lower:
#             icon = EVENT_ICONS_HTML["Error"] + "&nbsp;"
#             printed_class = "Error"
#         elif "debug" in event_class_lower:
#             icon = EVENT_ICONS_HTML["Debug"] + "&nbsp;"
#             printed_class = "Debug"
#         elif "warning" in event_class_lower:
#             icon = EVENT_ICONS_HTML["Warning"] + "&nbsp;"
#             printed_class = "Warning"
#         elif "info" in event_class_lower or "infos" in event_class_lower:
#             icon = EVENT_ICONS_HTML["Info"] + "&nbsp;"
#             printed_class = "Info"
#         elif "important" in event_class_lower:
#             icon = EVENT_ICONS_HTML["Important"] + "&nbsp;"
#             printed_class = "Important"
#     event_html += (
#         '<span class="'
#         + EVENT_CLASSES[printed_class]
#         + '">'
#         + icon
#         + printed_class
#         + "</span>"
#     )
#     if _event_class in EVENT_EXTRA_HTML.keys():
#         event_html += EVENT_EXTRA_HTML[_event_class]
#     return event_html


from typing import Any, List, Union
from django.http.request import HttpRequest
from django.utils.safestring import SafeText
from django.utils.translation import gettext_lazy as _
from django.contrib import admin
from django.utils.html import format_html
from .models import MEvent
from .utils import format_event_class
    ]
    list_filter = (
        "event_class",
        ("content_type", admin.RelatedOnlyFieldListFilter),
        ("user", admin.RelatedOnlyFieldListFilter),
        "scope",
    )
    search_fields = ["name", "user__username", "event_class", "bucket"]
    link_to_object.allow_tags = True
    link_to_object.short_description = _("See on site")
    link_to_object_admin.allow_tags = True
    link_to_object_admin.short_description = _("See in admin")
    format_event_class.allow_tags = True
    format_event_class.short_description = _("Class")
    filters_on_top = True
    list_select_related = (
        "user",
        "content_type",
    )

    class Media:
        css = {
            "all": (
                "mqueue/mqueue.css",
                "https://cdn.jsdelivr.net/npm/font-awesome@4.7.0"
                + "/css/font-awesome.min.css",
            )
        }

    def get_readonly_fields(

# Path: mqueue/models.py
# class MEvent(models.Model):
#     # required fields
#     content_type = models.ForeignKey(
#         ContentType,
#         null=True,
#         blank=True,
#         verbose_name=_("Content type"),
#         on_delete=SET_NULL,
#     )
#     obj_pk = models.IntegerField(
#         blank=True, null=True, verbose_name=_("Object primary key")
#     )
#     name = models.CharField(max_length=120, verbose_name=_("Name"))
#     # content fields
#     url = models.CharField(max_length=255, blank=True, verbose_name=_("Url"))
#     admin_url = models.CharField(
#         max_length=255, blank=True, verbose_name=_("Admin url")
#     )
#     notes = models.TextField(blank=True)
#     # meta
#     date_posted = models.DateTimeField(auto_now_add=True, verbose_name=_("Date posted"))
#     event_class = models.CharField(max_length=120, blank=True, verbose_name=_("Class"))
#     user = models.ForeignKey(
#         USER_MODEL,
#         null=True,
#         blank=True,
#         related_name="+",
#         on_delete=models.SET_NULL,
#         verbose_name=_("User"),
#     )
#     groups = models.ManyToManyField(
#         Group,
#         blank=True,
#         verbose_name=_("Groups"),
#     )
#     request = models.TextField(blank=True, verbose_name=_("Request"))
#     bucket = models.CharField(max_length=60, blank=True, verbose_name=_("Bucket"))
#     data = models.TextField(blank=True, verbose_name=_("Data"))
#     # manager
#     scope = models.CharField(
#         max_length=18,
#         choices=SCOPE,
#         default=SCOPE[0][0],
#         verbose_name=_("Scope"),
#     )
#     objects = MEventManager()
# 
#     class Meta:  # type: ignore
#         app_label = "mqueue"
#         verbose_name = _("Event")
#         verbose_name_plural = _("Events")
#         ordering = ["-date_posted"]
#         # permissions = (("view_mevent", "Can see Events"),)
# 
#     def __str__(self) -> str:
#         return f"{self.name} - {self.date_posted}"
# 
# Path: mqueue/utils.py
# def format_event_class(
#     obj=None, event_class: Union[str, None] = None  # type: ignore
# ) -> str:
#     event_html = ""
#     if event_class is None:
#         _event_class: str = obj.event_class  # type: ignore
#     else:
#         _event_class = event_class
#     printed_class = get_event_class_str(event_class).replace("_", " ").capitalize()
#     icon = ""
#     if _event_class in EVENT_ICONS_HTML.keys():
#         icon = EVENT_ICONS_HTML[_event_class] + "&nbsp;"
#         # printed_class = event_class
#     else:
#         event_class_lower = _event_class.lower()
#         if "created" in event_class_lower:
#             icon = EVENT_ICONS_HTML["Object created"] + "&nbsp;"
#             printed_class = "Object created"
#         elif "edited" in event_class_lower:
#             icon = EVENT_ICONS_HTML["Object edited"] + "&nbsp;"
#             printed_class = "Object edited"
#         elif "deleted" in event_class_lower:
#             icon = EVENT_ICONS_HTML["Object deleted"] + "&nbsp;"
#             printed_class = "Object deleted"
#         else:
#             icon = EVENT_ICONS_HTML["Default"] + "&nbsp;"
#             printed_class = "Default"
#         if "error" in event_class_lower:
#             icon = EVENT_ICONS_HTML["Error"] + "&nbsp;"
#             printed_class = "Error"
#         elif "debug" in event_class_lower:
#             icon = EVENT_ICONS_HTML["Debug"] + "&nbsp;"
#             printed_class = "Debug"
#         elif "warning" in event_class_lower:
#             icon = EVENT_ICONS_HTML["Warning"] + "&nbsp;"
#             printed_class = "Warning"
#         elif "info" in event_class_lower or "infos" in event_class_lower:
#             icon = EVENT_ICONS_HTML["Info"] + "&nbsp;"
#             printed_class = "Info"
#         elif "important" in event_class_lower:
#             icon = EVENT_ICONS_HTML["Important"] + "&nbsp;"
#             printed_class = "Important"
#     event_html += (
#         '<span class="'
#         + EVENT_CLASSES[printed_class]
#         + '">'
#         + icon
#         + printed_class
#         + "</span>"
#     )
#     if _event_class in EVENT_EXTRA_HTML.keys():
#         event_html += EVENT_EXTRA_HTML[_event_class]
#     return event_html


# Path: mqueue/admin.py
from typing import Any, List, Union
from django.http.request import HttpRequest
from django.utils.safestring import SafeText
from django.utils.translation import gettext_lazy as _
from django.contrib import admin
from django.utils.html import format_html
from .models import MEvent
from .utils import format_event_class

    ]
    list_filter = (
        "event_class",
        ("content_type", admin.RelatedOnlyFieldListFilter),
        ("user", admin.RelatedOnlyFieldListFilter),
        "scope",
    )
    search_fields = ["name", "user__username", "event_class", "bucket"]
    link_to_object.allow_tags = True
    link_to_object.short_description = _("See on site")
    link_to_object_admin.allow_tags = True
    link_to_object_admin.short_description = _("See in admin")
    format_event_class.allow_tags = True
    format_event_class.short_description = _("Class")
    filters_on_top = True
    list_select_related = (
        "user",
        "content_type",
    )

    class Media:
        css = {
            "all": (
                "mqueue/mqueue.css",
                "https://cdn.jsdelivr.net/npm/font-awesome@4.7.0"
                + "/css/font-awesome.min.css",
            )
        }

    def get_readonly_fields(

        self, request: HttpRequest, obj: Union[MEvent, None] = None