Skip to content

Commit e670178

Browse files
committed
Merge branch 'main'
2 parents 37139a3 + 1564ffb commit e670178

File tree

94 files changed

+5720
-351
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+5720
-351
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ exclude =
1515
__pycache__,
1616
migrations,
1717
static,
18-
env, # your virtual environment directory
18+
venv, # your virtual environment directory
1919

2020
# Enable checking for complexity
2121
max-complexity = 10

.github/workflows/django.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Django CI
1+
name: Django Test
22

33
on:
44
push:
@@ -20,23 +20,21 @@ jobs:
2020

2121
steps:
2222
- name: Check out the repository
23-
uses: actions/checkout@v4 # This is an action, so it uses 'uses'
23+
uses: actions/checkout@v4
2424

2525
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v3 # This is an action, so it uses 'uses'
26+
uses: actions/setup-python@v3
2727
with:
2828
python-version: ${{ matrix.python-version }}
2929

3030
- name: Install OpenSSL
31-
run: sudo apt-get install -y openssl # This is a command, so it uses 'run'
31+
run: sudo apt-get install -y openssl
3232

3333
- name: Generate private and public keys
3434
run: |
35-
# Очистка старых файлов перед созданием новых
3635
rm -rf security
3736
mkdir -p security
3837
39-
# Генерация приватного и публичного ключа
4038
openssl genpkey -algorithm RSA -out security/private_key.pem -pkeyopt rsa_keygen_bits:2048
4139
openssl rsa -pubout -in security/private_key.pem -out security/public_key.pem
4240
@@ -53,17 +51,17 @@ jobs:
5351
5452
5553
- name: Check if .env has been updated
56-
run: cat .env # This is a command, so it uses 'run'
54+
run: cat .env
5755

5856
- name: Install Dependencies
5957
run: |
6058
python -m pip install --upgrade pip
61-
pip install -r requirements.txt # This is a command, so it uses 'run'
59+
pip install -r requirements.txt
6260
6361
- name: Run Tests
64-
run: python manage.py test # This is a command, so it uses 'run'
62+
run: python manage.py test
6563

6664
- name: Clean up keys (Optional)
6765
run: |
6866
rm -rf security
69-
echo "Keys removed after use." # This is a command, so it uses 'run'
67+
echo "Keys removed after use."

.github/workflows/lint.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Lint Code
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
- "master"
8+
pull_request:
9+
branches:
10+
- "main"
11+
- "master"
12+
13+
jobs:
14+
15+
build:
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
python-version: [3.8, 3.9]
20+
21+
steps:
22+
- name: Check out the repository
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Python ${{ matrix.python-version }}
26+
uses: actions/setup-python@v3
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
30+
- name: Install OpenSSL
31+
run: sudo apt-get install -y openssl
32+
33+
- name: Generate private and public keys
34+
run: |
35+
rm -rf security
36+
mkdir -p security
37+
38+
openssl genpkey -algorithm RSA -out security/private_key.pem -pkeyopt rsa_keygen_bits:2048
39+
openssl rsa -pubout -in security/private_key.pem -out security/public_key.pem
40+
41+
echo "Private key saved as security/private_key.pem"
42+
echo "Public key saved as security/public_key.pem"
43+
44+
- name: Create .env file
45+
run: |
46+
touch .env
47+
echo PRIVATE_KEY_PATH=$(pwd)/security/private_key.pem >> .env
48+
echo PUBLIC_KEY_PATH=$(pwd)/security/public_key.pem >> .env
49+
DJANGO_SETTINGS_MODULE=core.settings.development >> .env
50+
echo DATABASE_ENVIRON=sqlite3 >> .env
51+
52+
53+
- name: Check if .env has been updated
54+
run: cat .env
55+
56+
- name: Install Dependencies
57+
run: |
58+
pip install flake8
59+
python -m pip install --upgrade pip
60+
pip install -r requirements.txt
61+
62+
- name: Lint Code
63+
run: flake8 .
64+
65+
- name: Clean up keys (Optional)
66+
run: |
67+
rm -rf security
68+
echo "Keys removed after use."

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,5 @@ GitHub.sublime-settings
140140
# private_key.pem
141141
# public_key.pem
142142

143-
db.sqlite3
143+
db.sqlite3
144+
poetry.lock

apps/blog/admin.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from django.contrib import admin
22
from .models import Post, PostComment, PostLike, PostDislike, PostCommentLike
33

4+
from unfold.admin import ModelAdmin
5+
46

57
@admin.register(Post)
6-
class PostAdmin(admin.ModelAdmin):
8+
class PostAdmin(ModelAdmin):
79
list_display = ["title", "content", "author", "is_active"]
810
search_fields = ["title", "content"]
911
list_filter = ["author", "is_active"]
@@ -12,20 +14,20 @@ class PostAdmin(admin.ModelAdmin):
1214

1315

1416
@admin.register(PostComment)
15-
class PostCommentAdmin(admin.ModelAdmin):
17+
class PostCommentAdmin(ModelAdmin):
1618
pass
1719

1820

1921
@admin.register(PostLike)
20-
class PostLikeAdmin(admin.ModelAdmin):
22+
class PostLikeAdmin(ModelAdmin):
2123
pass
2224

2325

2426
@admin.register(PostDislike)
25-
class PostDislike(admin.ModelAdmin):
27+
class PostDislike(ModelAdmin):
2628
pass
2729

2830

2931
@admin.register(PostCommentLike)
30-
class PostCommentLikeAdmin(admin.ModelAdmin):
32+
class PostCommentLikeAdmin(ModelAdmin):
3133
pass
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from rest_framework import routers
2+
3+
from .blog import (
4+
PostViewSet,
5+
PostCommentViewSet,
6+
PostCommentLikeViewSet,
7+
PostLikeViewSet,
8+
PostDislikeViewSet,
9+
)
10+
11+
router = routers.DefaultRouter()
12+
router.register("post", PostViewSet, basename="post")
13+
router.register("post_comment", PostCommentViewSet, basename="post-comment")
14+
router.register(
15+
"post_comment_like", PostCommentLikeViewSet, basename="post-comment-like"
16+
)
17+
router.register("post_like", PostLikeViewSet, basename="post-like")
18+
router.register("post_dislike", PostDislikeViewSet, basename="post-dislike")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .views import * # noqa
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from rest_framework import serializers
2+
3+
from apps.blog.models import Post
4+
5+
6+
class PostSerializer(serializers.ModelSerializer):
7+
class Meta:
8+
model = Post
9+
fields = [
10+
"id",
11+
"title",
12+
"get_absolute_url",
13+
"status",
14+
"description",
15+
"publisher_at",
16+
"is_active",
17+
"author",
18+
"like_count",
19+
"dislike_count",
20+
"comment_count",
21+
"watching",
22+
"created_at",
23+
"updated_at",
24+
]

apps/blog/api_endpoints/blog/Post/tests.py

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from rest_framework import viewsets, permissions
2+
3+
from apps.blog.models import Post
4+
from .serializer import PostSerializer
5+
6+
7+
class PostViewSet(viewsets.ModelViewSet):
8+
queryset = Post.published.all().order_by("-created_at")
9+
serializer_class = PostSerializer
10+
11+
def get_permissions(self):
12+
if self.action in ["list", "retrieve"]:
13+
return [permissions.AllowAny()]
14+
return [permissions.IsAuthenticated()]
15+
16+
17+
__all__ = ("PostViewSet",)

0 commit comments

Comments
 (0)