Skip to content

Commit c14f710

Browse files
Merge pull request #18 from RustamovAkrom/main
Main
2 parents fb30118 + 1ceccb5 commit c14f710

Some content is hidden

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

60 files changed

+852
-335
lines changed

.flake8

+1-1
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

+8-10
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

+68
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."

apps/blog/api_endpoints/__init__.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
from rest_framework import routers
22

33
from .blog import (
4-
PostViewSet,
5-
PostCommentViewSet,
4+
PostViewSet,
5+
PostCommentViewSet,
66
PostCommentLikeViewSet,
77
PostLikeViewSet,
8-
PostDislikeViewSet
8+
PostDislikeViewSet,
99
)
1010

1111
router = routers.DefaultRouter()
1212
router.register("post", PostViewSet, basename="post")
1313
router.register("post_comment", PostCommentViewSet, basename="post-comment")
14-
router.register("post_comment_like", PostCommentLikeViewSet, basename="post-comment-like")
14+
router.register(
15+
"post_comment_like", PostCommentLikeViewSet, basename="post-comment-like"
16+
)
1517
router.register("post_like", PostLikeViewSet, basename="post-like")
1618
router.register("post_dislike", PostDislikeViewSet, basename="post-dislike")
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .views import * # noqa
1+
from .views import * # noqa

apps/blog/api_endpoints/blog/Post/serializer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Meta:
88
model = Post
99
fields = [
1010
"id",
11-
"title",
11+
"title",
1212
"get_absolute_url",
1313
"status",
1414
"description",
@@ -21,4 +21,4 @@ class Meta:
2121
"watching",
2222
"created_at",
2323
"updated_at",
24-
]
24+
]

apps/blog/api_endpoints/blog/Post/views.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
class PostViewSet(viewsets.ModelViewSet):
88
queryset = Post.published.all().order_by("-created_at")
99
serializer_class = PostSerializer
10-
10+
1111
def get_permissions(self):
12-
if self.action in ['list', 'retrieve']:
12+
if self.action in ["list", "retrieve"]:
1313
return [permissions.AllowAny()]
1414
return [permissions.IsAuthenticated()]
15-
16-
__all__ = ("PostViewSet", )
15+
16+
17+
__all__ = ("PostViewSet",)
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .views import * # noqa
1+
from .views import * # noqa

apps/blog/api_endpoints/blog/PostComment/views.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ class PostCommentViewSet(viewsets.ModelViewSet):
99
serializer_class = PostCommentSerializer
1010

1111
def get_permissions(self):
12-
if self.action in ['list', 'retrieve']:
12+
if self.action in ["list", "retrieve"]:
1313
return [permissions.AllowAny()]
14-
return [permissions.IsAuthenticated()]
15-
16-
__all__ = ("PostCommentViewSet", )
14+
return [permissions.IsAuthenticated()]
15+
16+
17+
__all__ = ("PostCommentViewSet",)
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .views import * # noqa
1+
from .views import * # noqa

apps/blog/api_endpoints/blog/PostCommentLike/serializers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Meta:
1818
class PostCommentLikeSerializer(serializers.ModelSerializer):
1919
user = MiniPostCommentLikeUserSerializer(read_only=True)
2020
comment = MiniPostCommentLikePostCommentSerializer(read_only=True)
21-
21+
2222
class Meta:
2323
model = PostCommentLike
2424
fields = ["id", "user", "comment"]

apps/blog/api_endpoints/blog/PostCommentLike/views.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ class PostCommentLikeViewSet(viewsets.ModelViewSet):
99
serializer_class = PostCommentLikeSerializer
1010
permission_classes = [permissions.IsAuthenticated]
1111

12-
__all__ = ("PostCommentLikeViewSet", )
12+
13+
__all__ = ("PostCommentLikeViewSet",)
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .views import * # noqa
1+
from .views import * # noqa

apps/blog/api_endpoints/blog/PostDislike/views.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ def create(self, request, *args, **kwargs):
2121
existing_dislike = PostDislike.objects.filter(post=post, user=user)
2222
if existing_dislike.exists():
2323
existing_dislike.delete()
24-
return response.Response({"message": "Dislike removed"}, status=status.HTTP_200_OK)
25-
24+
return response.Response(
25+
{"message": "Dislike removed"}, status=status.HTTP_200_OK
26+
)
27+
2628
dislike = PostDislike.objects.create(post=post, user=user)
2729
serializer = self.get_serializer(dislike)
2830

2931
return response.Response(serializer.data, status=status.HTTP_201_CREATED)
30-
3132

32-
__all__ = ("PostDislikeViewSet", )
33+
34+
__all__ = ("PostDislikeViewSet",)
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .views import * # noqa
1+
from .views import * # noqa

apps/blog/api_endpoints/blog/PostLike/views.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class PostLikeViewSet(viewsets.ModelViewSet):
1010
queryset = PostLike.objects.all()
1111
serializer_class = PostLikeSerializer
1212
permission_classes = [permissions.IsAuthenticated]
13-
13+
1414
def create(self, request, *args, **kwargs):
1515
post_id = request.data.get("post")
1616
post = get_object_or_404(Post, id=post_id)
@@ -21,11 +21,14 @@ def create(self, request, *args, **kwargs):
2121
existing_like = PostLike.objects.filter(post=post, user=user)
2222
if existing_like.exists():
2323
existing_like.delete()
24-
return response.Response({"message": "Like removed"}, status=status.HTTP_200_OK)
25-
24+
return response.Response(
25+
{"message": "Like removed"}, status=status.HTTP_200_OK
26+
)
27+
2628
like = PostLike.objects.create(post=post, user=user)
2729
serializer = self.get_serializer(like)
2830

2931
return response.Response(serializer.data, status=status.HTTP_201_CREATED)
3032

31-
__all__ = ("PostLikeViewSet", )
33+
34+
__all__ = ("PostLikeViewSet",)
+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from .Post import * # noqa
2-
from .PostComment import * # noqa
3-
from .PostCommentLike import * # noqa
4-
from .PostDislike import * # noqa
5-
from .PostLike import * # noqa
1+
from .Post import * # noqa
2+
from .PostComment import * # noqa
3+
from .PostCommentLike import * # noqa
4+
from .PostDislike import * # noqa
5+
from .PostLike import * # noqa

apps/blog/choices.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class StatusChoice(TextChoices):
5-
DRAFT = 'df', 'Draft'
6-
PUBLISHED = 'pb', 'Published'
5+
DRAFT = "df", "Draft"
6+
PUBLISHED = "pb", "Published"

apps/blog/forms.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .models import Post
55

66

7-
default_attrs = lambda name, placeholder: { # noqa :E731
7+
default_attrs = lambda name, placeholder: { # noqa :E731
88
"name": name,
99
"placeholder": placeholder,
1010
"class": "form-control",
@@ -52,7 +52,7 @@ class Meta:
5252
class SettingsUserForm(forms.ModelForm):
5353
class Meta:
5454
model = User
55-
fields = ("first_name", "last_name", "username", "email")
55+
fields = ("first_name", "last_name", "email")
5656

5757
first_name = forms.CharField(
5858
widget=forms.TextInput(
@@ -66,11 +66,6 @@ class Meta:
6666
),
6767
required=False,
6868
)
69-
username = forms.CharField(
70-
widget=forms.TextInput(
71-
attrs=default_attrs("username", "Username..."),
72-
)
73-
)
7469
email = forms.EmailField(
7570
widget=forms.EmailInput(attrs=default_attrs("email", "Email..."))
7671
)

0 commit comments

Comments
 (0)