-
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.
feat(Tutorial): add Tutorial with all those dependecies
- Loading branch information
Showing
45 changed files
with
2,080 additions
and
37 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -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" | ||
|
@@ -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" | ||
|
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,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() |
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 @@ | ||
from .category import TutorialsStatusFilter |
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 @@ | ||
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 |
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,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") |
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,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 |
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 @@ | ||
""" | ||
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",) |
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 @@ | ||
from .tutorial import TutorialFilter |
Oops, something went wrong.