Skip to content

Commit

Permalink
end configure
Browse files Browse the repository at this point in the history
  • Loading branch information
RustamovAkrom committed Nov 21, 2024
1 parent 7d88b18 commit b278141
Show file tree
Hide file tree
Showing 18 changed files with 197 additions and 35 deletions.
1 change: 1 addition & 0 deletions apps/blog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from unfold.admin import ModelAdmin


@admin.register(Post)
class PostAdmin(ModelAdmin):
list_display = ["title", "content", "author", "is_active"]
Expand Down
2 changes: 1 addition & 1 deletion apps/blog/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class PostFilter(django_filters.FilterSet):

class Meta:
model = Post
fields = ['title', 'description', 'content', 'created_at']
fields = ["title", "description", "content", "created_at"]
26 changes: 17 additions & 9 deletions apps/blog/utils.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
from django.db.models import QuerySet
from django.db.models import Q
from django.contrib.postgres.search import SearchQuery, SearchRank, SearchVector
from django.core.paginator import Paginator, Page, EmptyPage, PageNotAnInteger, InvalidPage
from django.core.paginator import (
Paginator,
Page,
EmptyPage,
PageNotAnInteger,
InvalidPage,
)
from django.conf import settings

from .models import PostLike, PostDislike, Post, PostComment


def get_search_model_queryset(
model_queryset: QuerySet, query: str = None
) -> QuerySet:
def get_search_model_queryset(model_queryset: QuerySet, query: str = None) -> QuerySet:
if not query:
return model_queryset

search_vector = SearchVector("title", "description", "content")
search_query = SearchQuery(query)

if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.postgresql':
if settings.DATABASES["default"]["ENGINE"] == "django.db.backends.postgresql":
# PostgreSQL search
queryset = model_queryset.annotate(
search=search_vector,
rank=SearchRank(search_vector, search_query),
).filter(search=search_query).order_by('-rank')
queryset = (
model_queryset.annotate(
search=search_vector,
rank=SearchRank(search_vector, search_query),
)
.filter(search=search_query)
.order_by("-rank")
)
else:
# SQLite3 search
queryset = model_queryset.filter(
Expand Down
1 change: 1 addition & 0 deletions apps/shared/management/commands/createadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.core.management import BaseCommand

from dotenv import load_dotenv

load_dotenv()


Expand Down
7 changes: 4 additions & 3 deletions apps/users/admin.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin # noqa
from .models import User, UserProfile

from unfold.admin import ModelAdmin


@admin.register(User)
class UserAdmin(ModelAdmin):
list_display = ["username", "post_count"]
search_fields = ["first_name", "last_name", "username"]
search_fields = ["first_name", "last_name", "username", "email"]
list_display_links = ["username"]

def get_post_count(self):
Expand All @@ -16,4 +17,4 @@ def get_post_count(self):

@admin.register(UserProfile)
class UserProfileAdmin(ModelAdmin):
pass
list_display = ["user", "avatar", "bio"]
2 changes: 1 addition & 1 deletion apps/users/api_endpoints/users/User/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ def _create_user():
_create_user()

def test_api_user_update(self):
pass
pass
4 changes: 1 addition & 3 deletions apps/users/api_endpoints/users/UserProfile/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework.test import APITestCase
from rest_framework_simplejwt.tokens import RefreshToken
from apps.users.models import UserProfile, User
from apps.users.models import UserProfile, User # noqa


class UserProfileApiTestCase(APITestCase):
Expand All @@ -18,5 +18,3 @@ def setUp(self) -> None:
refresh = RefreshToken.for_user(self.user)
self.token = str(refresh.access_token)
return super().setUp()


7 changes: 4 additions & 3 deletions core/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
from django.core.asgi import get_asgi_application

from dotenv import load_dotenv

load_dotenv()

os.environ.setdefault(
"DJANGO_SETTINGS_MODULE",
os.getenv("DJANGO_SETTINGS_MODULE", "core.settings.development")
"DJANGO_SETTINGS_MODULE",
os.getenv("DJANGO_SETTINGS_MODULE", "core.settings.development"),
)

application = get_asgi_application()

app = application
app = application
6 changes: 4 additions & 2 deletions core/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from .apps import * # noqa
from .jwt import * # noqa
from .rest_framework import * # noqa
from .unfold_navigation import * # noqa
from .unfold import * # noqa
from .unfold_navigation import * # noqa
from .unfold import * # noqa

# from .cheditor5 import * # noqa
2 changes: 2 additions & 0 deletions core/config/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"unfold.contrib.simple_history",
# Translation
"modeltranslation",
#
"django_ckeditor_5",
# Translation pannel
"rosetta",
# DRF Swaggers
Expand Down
140 changes: 140 additions & 0 deletions core/config/cheditor5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
customColorPalette = [
{"color": "hsl(4, 90%, 58%)", "label": "Red"},
{"color": "hsl(340, 82%, 52%)", "label": "Pink"},
{"color": "hsl(291, 64%, 42%)", "label": "Purple"},
{"color": "hsl(262, 52%, 47%)", "label": "Deep Purple"},
{"color": "hsl(231, 48%, 48%)", "label": "Indigo"},
{"color": "hsl(207, 90%, 54%)", "label": "Blue"},
]

CKEDITOR_5_CONFIGS = {
"default": {
"toolbar": [
"heading",
"|",
"bold",
"italic",
"link",
"bulletedList",
"numberedList",
"blockQuote",
"imageUpload",
],
},
"extends": {
"blockToolbar": [
"paragraph",
"heading1",
"heading2",
"heading3",
"|",
"bulletedList",
"numberedList",
"|",
"blockQuote",
],
"toolbar": [
"heading",
"|",
"outdent",
"indent",
"|",
"bold",
"italic",
"link",
"underline",
"strikethrough",
"code",
"subscript",
"superscript",
"highlight",
"|",
"codeBlock",
"sourceEditing",
"insertImage",
"bulletedList",
"numberedList",
"todoList",
"|",
"blockQuote",
"imageUpload",
"|",
"fontSize",
"fontFamily",
"fontColor",
"fontBackgroundColor",
"mediaEmbed",
"removeFormat",
"insertTable",
],
"image": {
"toolbar": [
"imageTextAlternative",
"|",
"imageStyle:alignLeft",
"imageStyle:alignRight",
"imageStyle:alignCenter",
"imageStyle:side",
"|",
],
"styles": [
"full",
"side",
"alignLeft",
"alignRight",
"alignCenter",
],
},
"table": {
"contentToolbar": [
"tableColumn",
"tableRow",
"mergeTableCells",
"tableProperties",
"tableCellProperties",
],
"tableProperties": {
"borderColors": customColorPalette,
"backgroundColors": customColorPalette,
},
"tableCellProperties": {
"borderColors": customColorPalette,
"backgroundColors": customColorPalette,
},
},
"heading": {
"options": [
{
"model": "paragraph",
"title": "Paragraph",
"class": "ck-heading_paragraph",
},
{
"model": "heading1",
"view": "h1",
"title": "Heading 1",
"class": "ck-heading_heading1",
},
{
"model": "heading2",
"view": "h2",
"title": "Heading 2",
"class": "ck-heading_heading2",
},
{
"model": "heading3",
"view": "h3",
"title": "Heading 3",
"class": "ck-heading_heading3",
},
]
},
},
"list": {
"properties": {
"styles": "true",
"startIndex": "true",
"reversed": "true",
}
},
}
6 changes: 3 additions & 3 deletions core/config/unfold.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@
"SIDEBAR": {
"show_search": True,
"show_all_applications": True,
"navigation": navigation.PAGES
}
}
"navigation": navigation.PAGES,
},
}
12 changes: 7 additions & 5 deletions core/config/unfold_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
def user_has_group_or_permission(user, permission):
if user.is_superuser:
return True

group_names = user.groups.values_list("name", flat=True)
if not group_names:
return True

return user.groups.filter(permissions__codename=permission).exists()


Expand All @@ -33,17 +33,19 @@ def user_has_group_or_permission(user, permission):
"icon": "person_add",
"link": reverse_lazy("admin:auth_group_changelist"),
"permission": lambda request: user_has_group_or_permission(
request.user, "view_group",
request.user,
"view_group",
),
},
{
"title": _("Users"),
"icon": "person_add",
"link": reverse_lazy("admin:users_user_changelist"),
"permission": lambda request: user_has_group_or_permission(
request.user, "view_user",
request.user,
"view_user",
),
},
],
},
]
]
10 changes: 7 additions & 3 deletions core/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@

ALLOWED_HOSTS = str(os.getenv("ALLOWED_HOSTS")).split(",")

CSRF_TRUSTED_ORIGINS = str(os.getenv("CSRF_TRUSTED_ORIGINS")).split(",")

INSTALLED_APPS = THIRD_PARTY_APPS + DEFAULT_APPS + PROJECT_APPS # NOQA
INSTALLED_APPS = THIRD_PARTY_APPS + DEFAULT_APPS + PROJECT_APPS # noqa


MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.BrokenLinkEmailsMiddleware",
# "corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.locale.LocaleMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"apps.users.middleware.JWTAuthMiddleware", # My Jwt Auth Middleware
"apps.users.middleware.JWTAuthMiddleware", # My Jwt Auth Middleware
]

ROOT_URLCONF = "core.urls"
Expand Down Expand Up @@ -87,7 +91,7 @@

USE_TZ = True

gettext = lambda s: gettext_lazy(s)
gettext = lambda s: gettext_lazy(s) # noqa

LANGUAGES = (
("ru", gettext("Russia")),
Expand Down
2 changes: 1 addition & 1 deletion core/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.conf.urls import handler400, handler403, handler404, handler500 # noqa
from django.conf.urls.i18n import i18n_patterns # noqa: F401
from django.conf.urls.i18n import i18n_patterns # noqa: F401
from django.conf.urls.static import static
from django.conf import settings

Expand Down
1 change: 1 addition & 0 deletions core/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.core.wsgi import get_wsgi_application

from dotenv import load_dotenv

load_dotenv()

os.environ.setdefault(
Expand Down
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def main():

os.environ.setdefault(
"DJANGO_SETTINGS_MODULE",
os.getenv("DJANGO_SETTINGS_MODULE", "core.settings.development"),
Expand Down
Loading

0 comments on commit b278141

Please sign in to comment.