-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from MohmdFo/main
feat(sage_blog): Add is_active field to Category and Tag models and enhance admin and repository feature
- Loading branch information
Showing
21 changed files
with
642 additions
and
169 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
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 .post import PostsStatusFilter |
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 PostsStatusFilter(admin.SimpleListFilter): | ||
title = _("Posts Status") | ||
parameter_name = "posts_status" | ||
|
||
def lookups(self, request, model_admin): | ||
return [ | ||
("no_posts", _("No Posts")), | ||
("inactive_posts", _("Only Inactive Posts")), | ||
] | ||
|
||
def queryset(self, request, queryset): | ||
if self.value() == "no_posts": | ||
return queryset.filter(posts__isnull=True) | ||
elif self.value() == "inactive_posts": | ||
return queryset.filter_active_posts().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
Empty file.
Empty file.
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,90 @@ | ||
import logging | ||
import timeit | ||
from typing import TextIO | ||
|
||
from colorama import init | ||
from django.core.management.base import BaseCommand | ||
from django.utils.text import slugify | ||
|
||
from sage_blog.repository.generator import DataGeneratorLayer | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
init(autoreset=True) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Load a list of example data into the database" | ||
|
||
def handle(self, *args, **kwargs): | ||
|
||
logger.info("Generate Data for Blog") | ||
DGL = DataGeneratorLayer() | ||
|
||
self.show_warning_msg("create categories") | ||
start = timeit.default_timer() | ||
DGL.create_post_categories(11) | ||
stop = timeit.default_timer() | ||
self.show_success_msg("create categories finished in: " + str(stop - start)) | ||
|
||
self.show_warning_msg("create tags") | ||
start = timeit.default_timer() | ||
DGL.create_tags( | ||
total=25, | ||
) | ||
stop = timeit.default_timer() | ||
self.show_success_msg("create tags finished in: " + str(stop - start)) | ||
|
||
self.show_warning_msg("create posts") | ||
start = timeit.default_timer() | ||
DGL.create_posts( | ||
total=50, | ||
) | ||
stop = timeit.default_timer() | ||
self.show_success_msg("create posts finished in: " + str(stop - start)) | ||
|
||
self.show_warning_msg("create FAQ") | ||
start = timeit.default_timer() | ||
DGL.create_faqs( | ||
total=50, | ||
) | ||
stop = timeit.default_timer() | ||
self.show_success_msg("create FAQ finished in: " + str(stop - start)) | ||
|
||
logger.info("Data Generation Finished") | ||
|
||
def show_success_msg(self, msg: str) -> TextIO: | ||
""" | ||
Display a success message on the console. | ||
Args: | ||
- msg (str): The success message. | ||
Returns: | ||
TextIO: The output stream. | ||
""" | ||
self.stdout.write(self.style.SUCCESS(msg)) | ||
|
||
def show_warning_msg(self, msg: str) -> TextIO: | ||
""" | ||
Display a warning message on the console. | ||
Args: | ||
- msg (str): The warning message. | ||
Returns: | ||
TextIO: The output stream. | ||
""" | ||
self.stdout.write(self.style.WARNING(msg)) | ||
|
||
def show_error_msg(self, msg: str) -> TextIO: | ||
""" | ||
Display an error message on the console. | ||
Args: | ||
- msg (str): The error message. | ||
Returns: | ||
TextIO: The output stream. | ||
""" | ||
self.stdout.write(self.style.ERROR(msg)) |
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
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 .data_generator import DataGeneratorLayer |
Oops, something went wrong.