Skip to content

Commit

Permalink
Merge pull request #6 from MohmdFo/main
Browse files Browse the repository at this point in the history
style(Issue): improve IssueAdmin UX and organization in Django admin
  • Loading branch information
sepehr-akbarzadeh authored Dec 5, 2024
2 parents 487557a + 01f8970 commit 9dca865
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ dmypy.json

# ruff
.ruff_cache/
media/*

# Cython debug symbols
cython_debug/
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django_sage_ticket"
version = "0.1.2"
version = "0.1.7"
description = "A Django-based ticketing system"
authors = ["Radin Ghaheremani <[email protected]>","Sepehr Akbarzadeh <[email protected]>"]
readme = "README.md"
Expand Down
6 changes: 3 additions & 3 deletions sage_ticket/admin/faq.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ class FaqAdmin(TabbedTranslationAdmin):
"""

admin_priority = 5
list_display = ("question", "category", "created_at", "modified_at")
list_filter = ("category", "created_at", "modified_at")
list_display = ("question", "category", "is_popular", "created_at", "modified_at")
list_filter = ("category", "is_popular", "created_at", "modified_at")
search_fields = ("question", "answer", "category__title")
list_select_related = ("category",)
fieldsets = (
(None, {"fields": ("question", "answer", "category")}),
(None, {"fields": ("question", "answer", "category", "is_popular")}),
(
"Timestamps",
{"fields": ("created_at", "modified_at"), "classes": ("collapse",)},
Expand Down
39 changes: 26 additions & 13 deletions sage_ticket/admin/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,41 @@ class DepartmentInline(admin.TabularInline):
@admin.register(Issue)
class IssueAdmin(admin.ModelAdmin):
inlines = [AttachmentInline, CommentInline]
list_display = ("subject", "state", "created_at")
list_filter = ("state", "created_at")
search_fields = ("subject", "message")
list_display = ("subject", "state", "department", "raised_by", "uid", "is_public", "is_unread", "is_archive", "created_at")
list_filter = ("state", "is_public", "is_unread", "is_archive", "created_at", "department")
search_fields = ("subject", "message", "raised_by__username", "department__title", "uid")
ordering = ("-created_at",)
readonly_fields = ("created_at", "modified_at")
readonly_fields = ("uid", "created_at", "modified_at")
autocomplete_fields = ("raised_by", "department")
save_on_top = True

fieldsets = (
(
None,
_("Issue Details"),
{
"fields": ("subject", "message", "state", "severity", "department", "raised_by"),
"description": _("Main details about the issue, including severity, state, and assignment."),
},
),
(
_("Status"),
{
"fields": ("is_public", "is_unread", "is_archive"),
"description": _("Flags indicating whether the issue is public, unread, or archived."),
},
),
(
_("Identifiers"),
{
"fields": ("subject", "message", "state", "department", "raised_by"),
"description": _(
"Fields related to the issue, including the subject, description, and current state."
),
"fields": ("uid",),
"description": _("A unique identifier for the issue."),
},
),
(
_("Details"),
_("Timestamps"),
{
"fields": ("created_at", "modified_at"),
"description": _(
"Auto-generated timestamps indicating when the issue was created_at and last updated."
),
"description": _("Timestamps indicating when the issue was created and last updated."),
},
),
)
2 changes: 2 additions & 0 deletions sage_ticket/apps.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _


class TicketConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "sage_ticket"
verbose_name = _("Ticket")

def ready(self) -> None:
pass
2 changes: 1 addition & 1 deletion sage_ticket/models/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Comment(TimeStampMixin):
class Meta:
verbose_name = _("Comment")
verbose_name_plural = _("Comments")
db_table = "sage_comment"
db_table = "sage_ticket_comment"

def __repr__(self):
return f"<Comment(id={self.id}, title={self.title},user={self.user_id}"
Expand Down
2 changes: 1 addition & 1 deletion sage_ticket/models/department.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Department(TimeStampMixin):
class Meta:
verbose_name = _("Department")
verbose_name_plural = _("Departments")
db_table = "sage_department"
db_table = "sage_ticket_department"

def __repr__(self):
return f"<Department(id={self.id}, title={self.title})>"
Expand Down
9 changes: 9 additions & 0 deletions sage_ticket/models/faq.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Meta:

verbose_name = _("FAQ Category")
verbose_name_plural = _("FAQ Categories")
db_table = "sage_ticket_faq_cat"

def __repr__(self):
return f"<FAQ Category: {self.title}>"
Expand Down Expand Up @@ -60,11 +61,19 @@ class Faq(TimeStampMixin):
db_comment="The category to which the faq belongs.",
)

is_popular = models.BooleanField(
verbose_name=_("Is Popular"),
default=False,
help_text=_("Indicates if the FAQ is popular."),
db_comment="Flag indicating whether the FAQ is popular.",
)

class Meta:
"""Meta Information"""

verbose_name = _("FAQ")
verbose_name_plural = _("FAQ")
db_table = "sage_ticket_faq"
db_table_comment = "Table storing frequently asked questions and their answers for user reference."

def __str__(self):
Expand Down
29 changes: 17 additions & 12 deletions sage_ticket/models/issue.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import uuid

from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import models
Expand All @@ -17,12 +19,6 @@ class Issue(TimeStampMixin):
help_text=_("The subject of the issue."),
db_comment="The subject of the issue.",
)
name = models.CharField(
max_length=255,
verbose_name=_("Name"),
help_text=_("The name of the issue reporter."),
db_comment="The name of the issue reporter.",
)
message = models.TextField(
verbose_name=_("Message"),
help_text=_("The detailed message of the issue."),
Expand Down Expand Up @@ -68,16 +64,25 @@ class Issue(TimeStampMixin):
help_text=_("Indicates if the issue is archived."),
db_comment="Indicates if the issue is archived.",
)
is_public = models.BooleanField(
verbose_name=_("Is Public"),
default=False,
help_text=_("Indicates if the issue is public."),
db_comment="Indicates if the issue is public.",
)
uid = models.UUIDField(
verbose_name=_("UID"),
default=uuid.uuid4,
unique=True,
editable=False,
help_text=_("A unique identifier for the issue."),
db_comment="A globally unique identifier for the issue.",
)

class Meta:
verbose_name = _("Issue")
verbose_name_plural = _("Issues")
db_table = "sage_issue"
constraints = [
models.CheckConstraint(
name="issue_state", check=models.Q(state__in=TicketStateEnum.values)
)
]
db_table = "sage_ticket_issue"

def clean(self):
"""Validate the issue's state transitions and ensure the state value is
Expand Down

0 comments on commit 9dca865

Please sign in to comment.