Skip to content

Commit

Permalink
Cria modelo para rastrear eventos de proc de Top100ArticlesFile
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelpezzuto committed Aug 30, 2024
1 parent bd13da4 commit 09d7d29
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 4 deletions.
3 changes: 3 additions & 0 deletions tracker/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ class EventReportCreateError(Exception):

class EventReportDeleteEventsError(Exception):
...

class Top100ArticleFileReportCreateError(Exception):
...
37 changes: 37 additions & 0 deletions tracker/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.core.files.base import ContentFile
from django.db import models
from django.utils.translation import gettext_lazy as _
from wagtail.admin.panels import FieldPanel

from core.models import CommonControlField
from tracker import choices
Expand Down Expand Up @@ -188,3 +189,39 @@ def create(cls, user):
raise EventReportCreateError(
f"Unable to create EventReport. Exception: {e}"
)


class Top100ArticlesFileEvent(CommonControlField):
file = models.ForeignKey("metrics.Top100ArticlesFile", on_delete=models.SET_NULL, null=True, blank=True)
status = models.CharField(_("Status"), max_length=64, null=True, blank=True)
lines = models.IntegerField(_("Lines"), null=True, blank=True)
message = models.TextField(_("Message"), null=True, blank=True)

def __str__(self):
return f"{self.file.filename}"

panels = [
FieldPanel("file"),
FieldPanel("status"),
FieldPanel("lines"),
FieldPanel("message"),
]

class Meta:
verbose_name_plural = _("Top 100 Article File Reports")

@classmethod
def create(cls, user, file, status, lines, message):
try:
obj = cls()
obj.creator = user
obj.file = file
obj.status = status
obj.lines = lines
obj.message = message
obj.save()
except Exception as e:
raise Top100ArticleFileReportCreateError(
f"Unable to create Top100ArticleFileReport. Exception: {e}"
)

47 changes: 43 additions & 4 deletions tracker/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
from django.utils.translation import gettext as _
from wagtail.snippets.views.snippets import SnippetViewSet
from wagtail.snippets.views.snippets import SnippetViewSet, SnippetViewSetGroup
from wagtail.snippets.models import register_snippet

from config.menu import get_menu_order

from .models import UnexpectedEvent
from .models import (
UnexpectedEvent,
Top100ArticlesFileEvent
)


class UnexpectedEventSnippetViewSet(SnippetViewSet):
model = UnexpectedEvent
menu_label = _("Unexpected Events")
icon = 'warning'
menu_order = get_menu_order("tracker")
add_to_admin_menu = True
add_to_admin_menu = False

list_display = (
"exception_type",
Expand All @@ -34,4 +37,40 @@ class UnexpectedEventSnippetViewSet(SnippetViewSet):
)


register_snippet(UnexpectedEventSnippetViewSet)
class Top100ArticlesFileEventSnippetViewSet(SnippetViewSet):
model = Top100ArticlesFileEvent
menu_label = _("Top100 Articles File Events")
icon = 'warning'
menu_order = get_menu_order("tracker")
add_to_admin_menu = False

list_display = (
"file",
"status",
"lines",
"message",
"created",
)
list_filter = (
"status",
"lines",
)
search_fields = (
"file",
"created",
)


class TrackerViewSetGroup(SnippetViewSetGroup):
menu_name = 'tracker'
menu_label = _("Tracker")
icon = "folder-open-inverse"
menu_order = get_menu_order("tracker")

items = (
UnexpectedEventSnippetViewSet,
Top100ArticlesFileEventSnippetViewSet,
)


register_snippet(TrackerViewSetGroup)

0 comments on commit 09d7d29

Please sign in to comment.