Skip to content

Commit b278141

Browse files
committed
end configure
1 parent 7d88b18 commit b278141

File tree

18 files changed

+197
-35
lines changed

18 files changed

+197
-35
lines changed

apps/blog/admin.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from unfold.admin import ModelAdmin
55

6+
67
@admin.register(Post)
78
class PostAdmin(ModelAdmin):
89
list_display = ["title", "content", "author", "is_active"]

apps/blog/filters.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ class PostFilter(django_filters.FilterSet):
1111

1212
class Meta:
1313
model = Post
14-
fields = ['title', 'description', 'content', 'created_at']
14+
fields = ["title", "description", "content", "created_at"]

apps/blog/utils.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
11
from django.db.models import QuerySet
22
from django.db.models import Q
33
from django.contrib.postgres.search import SearchQuery, SearchRank, SearchVector
4-
from django.core.paginator import Paginator, Page, EmptyPage, PageNotAnInteger, InvalidPage
4+
from django.core.paginator import (
5+
Paginator,
6+
Page,
7+
EmptyPage,
8+
PageNotAnInteger,
9+
InvalidPage,
10+
)
511
from django.conf import settings
612

713
from .models import PostLike, PostDislike, Post, PostComment
814

915

10-
def get_search_model_queryset(
11-
model_queryset: QuerySet, query: str = None
12-
) -> QuerySet:
16+
def get_search_model_queryset(model_queryset: QuerySet, query: str = None) -> QuerySet:
1317
if not query:
1418
return model_queryset
1519

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

19-
if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.postgresql':
23+
if settings.DATABASES["default"]["ENGINE"] == "django.db.backends.postgresql":
2024
# PostgreSQL search
21-
queryset = model_queryset.annotate(
22-
search=search_vector,
23-
rank=SearchRank(search_vector, search_query),
24-
).filter(search=search_query).order_by('-rank')
25+
queryset = (
26+
model_queryset.annotate(
27+
search=search_vector,
28+
rank=SearchRank(search_vector, search_query),
29+
)
30+
.filter(search=search_query)
31+
.order_by("-rank")
32+
)
2533
else:
2634
# SQLite3 search
2735
queryset = model_queryset.filter(

apps/shared/management/commands/createadmin.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.core.management import BaseCommand
55

66
from dotenv import load_dotenv
7+
78
load_dotenv()
89

910

apps/users/admin.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from django.contrib import admin
2-
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
2+
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin # noqa
33
from .models import User, UserProfile
44

55
from unfold.admin import ModelAdmin
66

7+
78
@admin.register(User)
89
class UserAdmin(ModelAdmin):
910
list_display = ["username", "post_count"]
10-
search_fields = ["first_name", "last_name", "username"]
11+
search_fields = ["first_name", "last_name", "username", "email"]
1112
list_display_links = ["username"]
1213

1314
def get_post_count(self):
@@ -16,4 +17,4 @@ def get_post_count(self):
1617

1718
@admin.register(UserProfile)
1819
class UserProfileAdmin(ModelAdmin):
19-
pass
20+
list_display = ["user", "avatar", "bio"]

apps/users/api_endpoints/users/User/tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@ def _create_user():
104104
_create_user()
105105

106106
def test_api_user_update(self):
107-
pass
107+
pass

apps/users/api_endpoints/users/UserProfile/tests.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from rest_framework.test import APITestCase
22
from rest_framework_simplejwt.tokens import RefreshToken
3-
from apps.users.models import UserProfile, User
3+
from apps.users.models import UserProfile, User # noqa
44

55

66
class UserProfileApiTestCase(APITestCase):
@@ -18,5 +18,3 @@ def setUp(self) -> None:
1818
refresh = RefreshToken.for_user(self.user)
1919
self.token = str(refresh.access_token)
2020
return super().setUp()
21-
22-

core/asgi.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
from django.core.asgi import get_asgi_application
44

55
from dotenv import load_dotenv
6+
67
load_dotenv()
78

89
os.environ.setdefault(
9-
"DJANGO_SETTINGS_MODULE",
10-
os.getenv("DJANGO_SETTINGS_MODULE", "core.settings.development")
10+
"DJANGO_SETTINGS_MODULE",
11+
os.getenv("DJANGO_SETTINGS_MODULE", "core.settings.development"),
1112
)
1213

1314
application = get_asgi_application()
1415

15-
app = application
16+
app = application

core/config/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from .apps import * # noqa
22
from .jwt import * # noqa
33
from .rest_framework import * # noqa
4-
from .unfold_navigation import * # noqa
5-
from .unfold import * # noqa
4+
from .unfold_navigation import * # noqa
5+
from .unfold import * # noqa
6+
7+
# from .cheditor5 import * # noqa

core/config/apps.py

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"unfold.contrib.simple_history",
2727
# Translation
2828
"modeltranslation",
29+
#
30+
"django_ckeditor_5",
2931
# Translation pannel
3032
"rosetta",
3133
# DRF Swaggers

core/config/cheditor5.py

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
customColorPalette = [
2+
{"color": "hsl(4, 90%, 58%)", "label": "Red"},
3+
{"color": "hsl(340, 82%, 52%)", "label": "Pink"},
4+
{"color": "hsl(291, 64%, 42%)", "label": "Purple"},
5+
{"color": "hsl(262, 52%, 47%)", "label": "Deep Purple"},
6+
{"color": "hsl(231, 48%, 48%)", "label": "Indigo"},
7+
{"color": "hsl(207, 90%, 54%)", "label": "Blue"},
8+
]
9+
10+
CKEDITOR_5_CONFIGS = {
11+
"default": {
12+
"toolbar": [
13+
"heading",
14+
"|",
15+
"bold",
16+
"italic",
17+
"link",
18+
"bulletedList",
19+
"numberedList",
20+
"blockQuote",
21+
"imageUpload",
22+
],
23+
},
24+
"extends": {
25+
"blockToolbar": [
26+
"paragraph",
27+
"heading1",
28+
"heading2",
29+
"heading3",
30+
"|",
31+
"bulletedList",
32+
"numberedList",
33+
"|",
34+
"blockQuote",
35+
],
36+
"toolbar": [
37+
"heading",
38+
"|",
39+
"outdent",
40+
"indent",
41+
"|",
42+
"bold",
43+
"italic",
44+
"link",
45+
"underline",
46+
"strikethrough",
47+
"code",
48+
"subscript",
49+
"superscript",
50+
"highlight",
51+
"|",
52+
"codeBlock",
53+
"sourceEditing",
54+
"insertImage",
55+
"bulletedList",
56+
"numberedList",
57+
"todoList",
58+
"|",
59+
"blockQuote",
60+
"imageUpload",
61+
"|",
62+
"fontSize",
63+
"fontFamily",
64+
"fontColor",
65+
"fontBackgroundColor",
66+
"mediaEmbed",
67+
"removeFormat",
68+
"insertTable",
69+
],
70+
"image": {
71+
"toolbar": [
72+
"imageTextAlternative",
73+
"|",
74+
"imageStyle:alignLeft",
75+
"imageStyle:alignRight",
76+
"imageStyle:alignCenter",
77+
"imageStyle:side",
78+
"|",
79+
],
80+
"styles": [
81+
"full",
82+
"side",
83+
"alignLeft",
84+
"alignRight",
85+
"alignCenter",
86+
],
87+
},
88+
"table": {
89+
"contentToolbar": [
90+
"tableColumn",
91+
"tableRow",
92+
"mergeTableCells",
93+
"tableProperties",
94+
"tableCellProperties",
95+
],
96+
"tableProperties": {
97+
"borderColors": customColorPalette,
98+
"backgroundColors": customColorPalette,
99+
},
100+
"tableCellProperties": {
101+
"borderColors": customColorPalette,
102+
"backgroundColors": customColorPalette,
103+
},
104+
},
105+
"heading": {
106+
"options": [
107+
{
108+
"model": "paragraph",
109+
"title": "Paragraph",
110+
"class": "ck-heading_paragraph",
111+
},
112+
{
113+
"model": "heading1",
114+
"view": "h1",
115+
"title": "Heading 1",
116+
"class": "ck-heading_heading1",
117+
},
118+
{
119+
"model": "heading2",
120+
"view": "h2",
121+
"title": "Heading 2",
122+
"class": "ck-heading_heading2",
123+
},
124+
{
125+
"model": "heading3",
126+
"view": "h3",
127+
"title": "Heading 3",
128+
"class": "ck-heading_heading3",
129+
},
130+
]
131+
},
132+
},
133+
"list": {
134+
"properties": {
135+
"styles": "true",
136+
"startIndex": "true",
137+
"reversed": "true",
138+
}
139+
},
140+
}

core/config/unfold.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@
6262
"SIDEBAR": {
6363
"show_search": True,
6464
"show_all_applications": True,
65-
"navigation": navigation.PAGES
66-
}
67-
}
65+
"navigation": navigation.PAGES,
66+
},
67+
}

core/config/unfold_navigation.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
def user_has_group_or_permission(user, permission):
66
if user.is_superuser:
77
return True
8-
8+
99
group_names = user.groups.values_list("name", flat=True)
1010
if not group_names:
1111
return True
12-
12+
1313
return user.groups.filter(permissions__codename=permission).exists()
1414

1515

@@ -33,17 +33,19 @@ def user_has_group_or_permission(user, permission):
3333
"icon": "person_add",
3434
"link": reverse_lazy("admin:auth_group_changelist"),
3535
"permission": lambda request: user_has_group_or_permission(
36-
request.user, "view_group",
36+
request.user,
37+
"view_group",
3738
),
3839
},
3940
{
4041
"title": _("Users"),
4142
"icon": "person_add",
4243
"link": reverse_lazy("admin:users_user_changelist"),
4344
"permission": lambda request: user_has_group_or_permission(
44-
request.user, "view_user",
45+
request.user,
46+
"view_user",
4547
),
4648
},
4749
],
4850
},
49-
]
51+
]

core/settings/base.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,23 @@
1818

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

21+
CSRF_TRUSTED_ORIGINS = str(os.getenv("CSRF_TRUSTED_ORIGINS")).split(",")
2122

22-
INSTALLED_APPS = THIRD_PARTY_APPS + DEFAULT_APPS + PROJECT_APPS # NOQA
23+
INSTALLED_APPS = THIRD_PARTY_APPS + DEFAULT_APPS + PROJECT_APPS # noqa
2324

2425

2526
MIDDLEWARE = [
2627
"django.middleware.security.SecurityMiddleware",
2728
"django.contrib.sessions.middleware.SessionMiddleware",
29+
"django.middleware.common.BrokenLinkEmailsMiddleware",
30+
# "corsheaders.middleware.CorsMiddleware",
2831
"django.middleware.common.CommonMiddleware",
32+
"django.middleware.locale.LocaleMiddleware",
2933
"django.middleware.csrf.CsrfViewMiddleware",
3034
"django.contrib.auth.middleware.AuthenticationMiddleware",
3135
"django.contrib.messages.middleware.MessageMiddleware",
3236
"django.middleware.clickjacking.XFrameOptionsMiddleware",
33-
"apps.users.middleware.JWTAuthMiddleware", # My Jwt Auth Middleware
37+
"apps.users.middleware.JWTAuthMiddleware", # My Jwt Auth Middleware
3438
]
3539

3640
ROOT_URLCONF = "core.urls"
@@ -87,7 +91,7 @@
8791

8892
USE_TZ = True
8993

90-
gettext = lambda s: gettext_lazy(s)
94+
gettext = lambda s: gettext_lazy(s) # noqa
9195

9296
LANGUAGES = (
9397
("ru", gettext("Russia")),

core/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.conf.urls import handler400, handler403, handler404, handler500 # noqa
2-
from django.conf.urls.i18n import i18n_patterns # noqa: F401
2+
from django.conf.urls.i18n import i18n_patterns # noqa: F401
33
from django.conf.urls.static import static
44
from django.conf import settings
55

core/wsgi.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.core.wsgi import get_wsgi_application
44

55
from dotenv import load_dotenv
6+
67
load_dotenv()
78

89
os.environ.setdefault(

manage.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
def main():
10-
10+
1111
os.environ.setdefault(
1212
"DJANGO_SETTINGS_MODULE",
1313
os.getenv("DJANGO_SETTINGS_MODULE", "core.settings.development"),

0 commit comments

Comments
 (0)