Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main #18

Merged
merged 10 commits into from
Nov 19, 2024
Merged

Main #18

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exclude =
__pycache__,
migrations,
static,
env, # your virtual environment directory
venv, # your virtual environment directory

# Enable checking for complexity
max-complexity = 10
Expand Down
18 changes: 8 additions & 10 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Django CI
name: Django Test

on:
push:
Expand All @@ -20,23 +20,21 @@ jobs:

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

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

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

- name: Generate private and public keys
run: |
# Очистка старых файлов перед созданием новых
rm -rf security
mkdir -p security

# Генерация приватного и публичного ключа
openssl genpkey -algorithm RSA -out security/private_key.pem -pkeyopt rsa_keygen_bits:2048
openssl rsa -pubout -in security/private_key.pem -out security/public_key.pem

Expand All @@ -53,17 +51,17 @@ jobs:


- name: Check if .env has been updated
run: cat .env # This is a command, so it uses 'run'
run: cat .env

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt # This is a command, so it uses 'run'
pip install -r requirements.txt

- name: Run Tests
run: python manage.py test # This is a command, so it uses 'run'
run: python manage.py test

- name: Clean up keys (Optional)
run: |
rm -rf security
echo "Keys removed after use." # This is a command, so it uses 'run'
echo "Keys removed after use."
68 changes: 68 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Lint Code

on:
push:
branches:
- "main"
- "master"
pull_request:
branches:
- "main"
- "master"

jobs:

build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9]

steps:
- name: Check out the repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install OpenSSL
run: sudo apt-get install -y openssl

- name: Generate private and public keys
run: |
rm -rf security
mkdir -p security

openssl genpkey -algorithm RSA -out security/private_key.pem -pkeyopt rsa_keygen_bits:2048
openssl rsa -pubout -in security/private_key.pem -out security/public_key.pem

echo "Private key saved as security/private_key.pem"
echo "Public key saved as security/public_key.pem"

- name: Create .env file
run: |
touch .env
echo PRIVATE_KEY_PATH=$(pwd)/security/private_key.pem >> .env
echo PUBLIC_KEY_PATH=$(pwd)/security/public_key.pem >> .env
DJANGO_SETTINGS_MODULE=core.settings.development >> .env
echo DATABASE_ENVIRON=sqlite3 >> .env


- name: Check if .env has been updated
run: cat .env

- name: Install Dependencies
run: |
pip install flake8
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Lint Code
run: flake8 .

- name: Clean up keys (Optional)
run: |
rm -rf security
echo "Keys removed after use."
10 changes: 6 additions & 4 deletions apps/blog/api_endpoints/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
from rest_framework import routers

from .blog import (
PostViewSet,
PostCommentViewSet,
PostViewSet,
PostCommentViewSet,
PostCommentLikeViewSet,
PostLikeViewSet,
PostDislikeViewSet
PostDislikeViewSet,
)

router = routers.DefaultRouter()
router.register("post", PostViewSet, basename="post")
router.register("post_comment", PostCommentViewSet, basename="post-comment")
router.register("post_comment_like", PostCommentLikeViewSet, basename="post-comment-like")
router.register(
"post_comment_like", PostCommentLikeViewSet, basename="post-comment-like"
)
router.register("post_like", PostLikeViewSet, basename="post-like")
router.register("post_dislike", PostDislikeViewSet, basename="post-dislike")
2 changes: 1 addition & 1 deletion apps/blog/api_endpoints/blog/Post/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .views import * # noqa
from .views import * # noqa
4 changes: 2 additions & 2 deletions apps/blog/api_endpoints/blog/Post/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Meta:
model = Post
fields = [
"id",
"title",
"title",
"get_absolute_url",
"status",
"description",
Expand All @@ -21,4 +21,4 @@ class Meta:
"watching",
"created_at",
"updated_at",
]
]
9 changes: 5 additions & 4 deletions apps/blog/api_endpoints/blog/Post/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
class PostViewSet(viewsets.ModelViewSet):
queryset = Post.published.all().order_by("-created_at")
serializer_class = PostSerializer

def get_permissions(self):
if self.action in ['list', 'retrieve']:
if self.action in ["list", "retrieve"]:
return [permissions.AllowAny()]
return [permissions.IsAuthenticated()]

__all__ = ("PostViewSet", )


__all__ = ("PostViewSet",)
2 changes: 1 addition & 1 deletion apps/blog/api_endpoints/blog/PostComment/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .views import * # noqa
from .views import * # noqa
9 changes: 5 additions & 4 deletions apps/blog/api_endpoints/blog/PostComment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ class PostCommentViewSet(viewsets.ModelViewSet):
serializer_class = PostCommentSerializer

def get_permissions(self):
if self.action in ['list', 'retrieve']:
if self.action in ["list", "retrieve"]:
return [permissions.AllowAny()]
return [permissions.IsAuthenticated()]

__all__ = ("PostCommentViewSet", )
return [permissions.IsAuthenticated()]


__all__ = ("PostCommentViewSet",)
2 changes: 1 addition & 1 deletion apps/blog/api_endpoints/blog/PostCommentLike/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .views import * # noqa
from .views import * # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Meta:
class PostCommentLikeSerializer(serializers.ModelSerializer):
user = MiniPostCommentLikeUserSerializer(read_only=True)
comment = MiniPostCommentLikePostCommentSerializer(read_only=True)

class Meta:
model = PostCommentLike
fields = ["id", "user", "comment"]
3 changes: 2 additions & 1 deletion apps/blog/api_endpoints/blog/PostCommentLike/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ class PostCommentLikeViewSet(viewsets.ModelViewSet):
serializer_class = PostCommentLikeSerializer
permission_classes = [permissions.IsAuthenticated]

__all__ = ("PostCommentLikeViewSet", )

__all__ = ("PostCommentLikeViewSet",)
2 changes: 1 addition & 1 deletion apps/blog/api_endpoints/blog/PostDislike/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .views import * # noqa
from .views import * # noqa
10 changes: 6 additions & 4 deletions apps/blog/api_endpoints/blog/PostDislike/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ def create(self, request, *args, **kwargs):
existing_dislike = PostDislike.objects.filter(post=post, user=user)
if existing_dislike.exists():
existing_dislike.delete()
return response.Response({"message": "Dislike removed"}, status=status.HTTP_200_OK)

return response.Response(
{"message": "Dislike removed"}, status=status.HTTP_200_OK
)

dislike = PostDislike.objects.create(post=post, user=user)
serializer = self.get_serializer(dislike)

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


__all__ = ("PostDislikeViewSet", )

__all__ = ("PostDislikeViewSet",)
2 changes: 1 addition & 1 deletion apps/blog/api_endpoints/blog/PostLike/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .views import * # noqa
from .views import * # noqa
11 changes: 7 additions & 4 deletions apps/blog/api_endpoints/blog/PostLike/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PostLikeViewSet(viewsets.ModelViewSet):
queryset = PostLike.objects.all()
serializer_class = PostLikeSerializer
permission_classes = [permissions.IsAuthenticated]

def create(self, request, *args, **kwargs):
post_id = request.data.get("post")
post = get_object_or_404(Post, id=post_id)
Expand All @@ -21,11 +21,14 @@ def create(self, request, *args, **kwargs):
existing_like = PostLike.objects.filter(post=post, user=user)
if existing_like.exists():
existing_like.delete()
return response.Response({"message": "Like removed"}, status=status.HTTP_200_OK)

return response.Response(
{"message": "Like removed"}, status=status.HTTP_200_OK
)

like = PostLike.objects.create(post=post, user=user)
serializer = self.get_serializer(like)

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

__all__ = ("PostLikeViewSet", )

__all__ = ("PostLikeViewSet",)
10 changes: 5 additions & 5 deletions apps/blog/api_endpoints/blog/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .Post import * # noqa
from .PostComment import * # noqa
from .PostCommentLike import * # noqa
from .PostDislike import * # noqa
from .PostLike import * # noqa
from .Post import * # noqa
from .PostComment import * # noqa
from .PostCommentLike import * # noqa
from .PostDislike import * # noqa
from .PostLike import * # noqa
4 changes: 2 additions & 2 deletions apps/blog/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class StatusChoice(TextChoices):
DRAFT = 'df', 'Draft'
PUBLISHED = 'pb', 'Published'
DRAFT = "df", "Draft"
PUBLISHED = "pb", "Published"
9 changes: 2 additions & 7 deletions apps/blog/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .models import Post


default_attrs = lambda name, placeholder: { # noqa :E731
default_attrs = lambda name, placeholder: { # noqa :E731
"name": name,
"placeholder": placeholder,
"class": "form-control",
Expand Down Expand Up @@ -52,7 +52,7 @@ class Meta:
class SettingsUserForm(forms.ModelForm):
class Meta:
model = User
fields = ("first_name", "last_name", "username", "email")
fields = ("first_name", "last_name", "email")

first_name = forms.CharField(
widget=forms.TextInput(
Expand All @@ -66,11 +66,6 @@ class Meta:
),
required=False,
)
username = forms.CharField(
widget=forms.TextInput(
attrs=default_attrs("username", "Username..."),
)
)
email = forms.EmailField(
widget=forms.EmailInput(attrs=default_attrs("email", "Email..."))
)
Expand Down
Loading
Loading