Skip to content

Commit

Permalink
feat(Tutorial): add Tutorial with all those dependecies
Browse files Browse the repository at this point in the history
  • Loading branch information
MohmdFo committed Dec 5, 2024
1 parent 01f8970 commit 403965b
Show file tree
Hide file tree
Showing 45 changed files with 2,080 additions and 37 deletions.
344 changes: 343 additions & 1 deletion poetry.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 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.7"
version = "0.1.8"
description = "A Django-based ticketing system"
authors = ["Radin Ghaheremani <[email protected]>","Sepehr Akbarzadeh <[email protected]>"]
readme = "README.md"
Expand All @@ -17,6 +17,10 @@ django = [
]
django-sage-tools = "^0.3.5"
django-modeltranslation = "^0.19.11"
django-import-export = "^4.3.3"
django-ckeditor-5 = "^0.2.15"
sorl-thumbnail = "^12.11.0"
readtime = "^3.0.0"

[tool.poetry.group.dev.dependencies]
black = "^24.4.2"
Expand Down
8 changes: 8 additions & 0 deletions sage_ticket/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from .department import DepartmentAdmin
from .issue import IssueAdmin
from .faq import FaqCategoryAdmin, FaqAdmin
from .tutorial import TutorialAdmin
from .tutorial_faq import TutorialFaqAdmin
from .category import TutorialCategoryAdmin
from .tag import TutorialTagAdmin

__all__ = [
"AttachmentAdmin",
Expand All @@ -11,4 +15,8 @@
"IssueAdmin",
"FaqCategoryAdmin",
"FaqAdmin",
"TutorialAdmin",
"TutorialFaqAdmin",
"TutorialCategoryAdmin",
"TutorialTagAdmin",
]
54 changes: 54 additions & 0 deletions sage_ticket/admin/category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from django.contrib import admin
from django.utils.translation import gettext_lazy as _

from import_export.admin import ImportExportModelAdmin
from modeltranslation.admin import TabbedTranslationAdmin

from sage_ticket.admin.filters import TutorialsStatusFilter
from sage_ticket.models import TutorialCategory
from sage_ticket.resources import TutorialCategoryResource


@admin.register(TutorialCategory)
class TutorialCategoryAdmin(ImportExportModelAdmin, TabbedTranslationAdmin):
"""
Django admin customization for the TutorialCategory model.
This admin class customizes the display and search capabilities for TutorialCategories
in the Django admin interface. It provides an intuitive interface for managing blog
tutorial categories.
"""

resource_class = TutorialCategoryResource

# Display settings
admin_priority = 1
list_display = (
"title",
"slug",
"is_published",
"published_tutorials_count",
"modified_at",
)
list_filter = (TutorialsStatusFilter, "is_published")
search_fields = ("title",)
date_hierarchy = "created_at"
ordering = ("title",)
save_on_top = True

# Form layout customization
fieldsets = (
(None, {"fields": ("title", "slug", "is_published")}),
(_("Timestamps"), {"fields": ("created_at", "modified_at")}),
)
readonly_fields = ("created_at", "modified_at", "slug")

def get_queryset(self, request):
queryset = super().get_queryset(request)
queryset = queryset.join_tutorials()
return queryset

@admin.display(description=_("Published Tutorials"))
def published_tutorials_count(self, obj):
# Annotate the count of published tutorials directly when accessed
return obj.tutorials.filter(is_published=True).count()
6 changes: 3 additions & 3 deletions sage_ticket/admin/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
list_display = ("title", "user", "issue", "status", "is_unread", "created_at")
list_filter = ("status", "is_unread", "created_at")
list_display = ("title", "user", "issue", "status", "is_read", "created_at")
list_filter = ("status", "is_read", "created_at")
search_fields = ("title", "user__username", "issue__title")
readonly_fields = ("created_at", "modified_at")
ordering = ("-created_at",)
Expand All @@ -16,7 +16,7 @@ class CommentAdmin(admin.ModelAdmin):
(
None,
{
"fields": ("title", "user", "issue", "message", "status", "is_unread"),
"fields": ("title", "user", "issue", "message", "status", "is_read"),
"description": _(
"Fields related to the comment, including the title, user, associated issue, message content, status, and unread status."
),
Expand Down
1 change: 1 addition & 0 deletions sage_ticket/admin/filters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .category import TutorialsStatusFilter
20 changes: 20 additions & 0 deletions sage_ticket/admin/filters/category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.contrib import admin
from django.utils.translation import gettext_lazy as _


class TutorialsStatusFilter(admin.SimpleListFilter):
title = _("Tutorials Status")
parameter_name = "tutorials_status"

def lookups(self, request, model_admin):
return [
("no_tutorials", _("No Tutorials")),
("published_tutorials", _("Only With Published Tutorials")),
]

def queryset(self, request, queryset):
if self.value() == "no_tutorials":
return queryset.filter(tutorials__isnull=True)
elif self.value() == "published_tutorials":
return queryset.filter_published_tutorials().distinct()
return queryset
8 changes: 4 additions & 4 deletions sage_ticket/admin/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AttachmentInline(admin.TabularInline):
class CommentInline(admin.TabularInline):
model = Comment
extra = 1
fields = ("title", "user", "message", "is_unread")
fields = ("title", "user", "message", "is_read")
show_change_link = True


Expand All @@ -28,8 +28,8 @@ class DepartmentInline(admin.TabularInline):
@admin.register(Issue)
class IssueAdmin(admin.ModelAdmin):
inlines = [AttachmentInline, CommentInline]
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")
list_display = ("subject", "state", "department", "raised_by", "uid", "is_public", "is_read", "is_archive", "created_at")
list_filter = ("state", "is_public", "is_read", "is_archive", "created_at", "department")
search_fields = ("subject", "message", "raised_by__username", "department__title", "uid")
ordering = ("-created_at",)
readonly_fields = ("uid", "created_at", "modified_at")
Expand All @@ -47,7 +47,7 @@ class IssueAdmin(admin.ModelAdmin):
(
_("Status"),
{
"fields": ("is_public", "is_unread", "is_archive"),
"fields": ("is_public", "is_read", "is_archive"),
"description": _("Flags indicating whether the issue is public, unread, or archived."),
},
),
Expand Down
35 changes: 35 additions & 0 deletions sage_ticket/admin/tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from django.contrib import admin
from django.utils.translation import gettext_lazy as _

from import_export.admin import ImportExportModelAdmin
from modeltranslation.admin import TabbedTranslationAdmin

from sage_ticket.models import TutorialTag
from sage_ticket.resources import TutorialTagResource


@admin.register(TutorialTag)
class TutorialTagAdmin(ImportExportModelAdmin, TabbedTranslationAdmin):
"""
Django admin customization for the TutorialTag model.
This admin class customizes the display and search capabilities for TutorialTags
in the Django admin interface. It provides an easy-to-use interface for managing
tags associated with blog tutorials.
"""

resource_class = TutorialTagResource

admin_priority = 3
list_display = ("title", "slug", "is_published", "modified_at")
list_filter = ("created_at", "modified_at")
search_fields = ("title",)
date_hierarchy = "created_at"
save_on_top = True
ordering = ("title",)

fieldsets = (
(None, {"fields": ("title", "slug", "is_published")}),
(_("Timestamps"), {"fields": ("created_at", "modified_at")}),
)
readonly_fields = ("created_at", "modified_at", "slug")
148 changes: 148 additions & 0 deletions sage_ticket/admin/tutorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
from django.contrib import admin
from django.utils.translation import gettext_lazy as _

from sorl.thumbnail.admin import AdminImageMixin
from import_export.admin import ImportExportModelAdmin
from modeltranslation.admin import TabbedTranslationAdmin, TranslationTabularInline

from sage_ticket.models import Tutorial, TutorialFaq
from sage_ticket.resources import TutorialResource


class TutorialFaqInline(TranslationTabularInline):
model = TutorialFaq
extra = 1


@admin.register(Tutorial)
class TutorialAdmin(ImportExportModelAdmin, TabbedTranslationAdmin, AdminImageMixin):
"""
Django admin customization for the Tutorial model.
This admin class customizes the display, search, and filter capabilities for Tutorials
in the Django admin interface. It also provides a customized form layout for
editing and adding new Tutorials.
"""

resource_class = TutorialResource

admin_priority = 2
inlines = (TutorialFaqInline,)
# Display settings
list_display = (
"title",
"is_published",
"category",
"get_tags",
"get_summary",
"published_at",
"modified_at",
)
list_filter = ("is_published", "category", "published_at", "modified_at")
search_fields = (
"title",
"slug",
"description",
"summary",
"category__title",
"tags__title",
)
filter_horizontal = ("tags",)
save_on_top = True
autocomplete_fields = (
"author",
"category",
"suggested_tutorials",
"related_tutorials",
)
date_hierarchy = "published_at"
ordering = ("-published_at",)
readonly_fields = ("created_at", "modified_at", "slug")
fieldsets = (
(
"Basic Information",
{"fields": ("title", "slug", "category", "is_published")},
),
(
"Content Details",
{
"fields": (
"author",
"summary",
"description",
"picture",
"banner",
"alternate_text",
)
},
),
(
"SEO Metadata",
{
"fields": (
"keywords",
"meta_description",
"json_ld",
),
"classes": ("collapse",),
},
),
(
"Open Graph Metadata",
{
"fields": (
"og_title",
"og_type",
"og_image",
"og_description",
"og_url",
"og_site_name",
"og_locale",
"article_author",
),
"classes": ("collapse",),
},
),
(
_("Tags & Relationships"),
{
"fields": (
"tags",
"suggested_tutorials",
"related_tutorials",
),
"classes": ("collapse",),
"description": _(
"Enhance the tutorial's visibility by adding tags and "
"linking related tutorials."
),
},
),
(
"Timestamps",
{
"fields": (
"published_at",
"modified_at",
"created_at",
),
"classes": ("collapse",),
},
),
)

@staticmethod
@admin.display(description=_("Tags"))
def get_tags(obj):
return ", ".join([tag.title for tag in obj.tags.all()])

@staticmethod
@admin.display(description=_("Summary"))
def get_summary(obj):
return obj.summary if obj.summary else _("No Summary")

# Filter customization
def get_queryset(self, request):
queryset = super().get_queryset(request)
queryset = queryset.prefetch_related("tags")
return queryset
37 changes: 37 additions & 0 deletions sage_ticket/admin/tutorial_faq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
FAQ Administrators
"""

from django.contrib import admin

from import_export.admin import ImportExportModelAdmin
from modeltranslation.admin import TabbedTranslationAdmin

from sage_ticket.models import TutorialFaq
from sage_ticket.resources import TutorialFaqResource


@admin.register(TutorialFaq)
class TutorialFaqAdmin(ImportExportModelAdmin, TabbedTranslationAdmin):
"""
FAQ Admin
"""

resource_class = TutorialFaqResource

admin_priority = 5
list_display = ("question", "tutorial", "created_at", "modified_at")
list_filter = ("created_at", "modified_at")
search_fields = ("question", "answer", "tutorial__title")
list_select_related = ("tutorial",)
autocomplete_fields = ("tutorial",)
fieldsets = (
(None, {"fields": ("question", "answer", "tutorial")}),
(
"Timestamps",
{"fields": ("created_at", "modified_at"), "classes": ("collapse",)},
),
)
readonly_fields = ("created_at", "modified_at")
date_hierarchy = "created_at"
ordering = ("-created_at",)
1 change: 1 addition & 0 deletions sage_ticket/filters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .tutorial import TutorialFilter
Loading

0 comments on commit 403965b

Please sign in to comment.