diff --git a/backend/apps/authentication/serializers.py b/backend/apps/authentication/serializers.py index c8cad44..78882da 100644 --- a/backend/apps/authentication/serializers.py +++ b/backend/apps/authentication/serializers.py @@ -2,6 +2,7 @@ from django.contrib.auth.password_validation import validate_password as django_ from django.core.exceptions import ValidationError from rest_framework import serializers from apps.user.models import User +from apps.tasks import send_email class RegisterSerializer(serializers.ModelSerializer): @@ -33,5 +34,6 @@ class RegisterSerializer(serializers.ModelSerializer): validated_data["password"] ) - + send_email.delay(user.pk) + return user \ No newline at end of file diff --git a/backend/apps/authors/models.py b/backend/apps/authors/models.py index f4980e5..d0f263f 100644 --- a/backend/apps/authors/models.py +++ b/backend/apps/authors/models.py @@ -1,6 +1,6 @@ -from django.db import models -from apps.user.models import User +# from django.db import models +# from apps.user.models import User -class Author(models.Model): - user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="Authors") - name = models.CharField(max_length=255) \ No newline at end of file +# class Author(models.Model): +# user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="Authors") +# name = models.CharField(max_length=255) \ No newline at end of file diff --git a/backend/apps/authors/urls.py b/backend/apps/authors/urls.py index 70042c4..0203402 100644 --- a/backend/apps/authors/urls.py +++ b/backend/apps/authors/urls.py @@ -1,9 +1,9 @@ from rest_framework.routers import DefaultRouter -from apps.authors.views import AuthorsViewSet +# from apps.authors.views import AuthorsViewSet urlpatterns = [] -router = DefaultRouter() -router.register("", viewset=AuthorsViewSet) -urlpatterns += router.urls \ No newline at end of file +# router = DefaultRouter() +# router.register("", viewset=AuthorsViewSet) +# urlpatterns += router.urls \ No newline at end of file diff --git a/backend/apps/authors/views.py b/backend/apps/authors/views.py index ba890c7..7fff913 100644 --- a/backend/apps/authors/views.py +++ b/backend/apps/authors/views.py @@ -1,20 +1,20 @@ -from rest_framework import viewsets +# from rest_framework import viewsets -from apps.authors.models import Author -from apps.authors.serializers import AuthorSerializer -from rest_framework import viewsets -from rest_framework.permissions import IsAuthenticated -from rest_framework_simplejwt.authentication import JWTAuthentication +# from apps.authors.models import Author +# from apps.authors.serializers import AuthorSerializer +# from rest_framework import viewsets +# from rest_framework.permissions import IsAuthenticated +# from rest_framework_simplejwt.authentication import JWTAuthentication -class AuthorsViewSet(viewsets.ModelViewSet): - queryset = Author.objects.select_related("shelf") - serializer_class = AuthorSerializer +# class AuthorsViewSet(viewsets.ModelViewSet): +# queryset = Author.objects.select_related("shelf") +# serializer_class = AuthorSerializer - authentication_classes = [JWTAuthentication] - permission_classes = [IsAuthenticated] +# authentication_classes = [JWTAuthentication] +# permission_classes = [IsAuthenticated] - def get_queryset(self): - return self.queryset.filter( - shelf__user_id=self.request.user.pk - ) +# def get_queryset(self): +# return self.queryset.filter( +# shelf__user_id=self.request.user.pk +# ) diff --git a/backend/apps/books/models.py b/backend/apps/books/models.py index 19bac53..025efd0 100644 --- a/backend/apps/books/models.py +++ b/backend/apps/books/models.py @@ -1,11 +1,11 @@ from django.db import models from apps.shelves.models import Shelf -from apps.authors.models import Author +# from apps.authors.models import Author from apps.user.models import User class Book(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="Authors") - authors = models.ManyToManyField(Author, related_name="books") + # authors = models.ManyToManyField(Author, related_name="books") name = models.CharField(max_length=255) isbn = models.CharField(max_length=13) \ No newline at end of file diff --git a/backend/apps/tasks.py b/backend/apps/tasks.py new file mode 100644 index 0000000..ea45376 --- /dev/null +++ b/backend/apps/tasks.py @@ -0,0 +1,11 @@ +from celery import shared_task + + +@shared_task +def send_email(user_pk): + print(user_pk) + + # if sended + # zmienna info itp, jesli sie straci + + return None \ No newline at end of file diff --git a/backend/config/__init__.py b/backend/config/__init__.py index e69de29..612eebb 100644 --- a/backend/config/__init__.py +++ b/backend/config/__init__.py @@ -0,0 +1,3 @@ +from config.celery import app as celery_app + +__all__ = ('celery_app',) \ No newline at end of file diff --git a/backend/config/celery.py b/backend/config/celery.py new file mode 100644 index 0000000..6f88b04 --- /dev/null +++ b/backend/config/celery.py @@ -0,0 +1,11 @@ +import os + +from celery import Celery + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.django.dev') + +app = Celery('library') + +app.config_from_object('django.conf:settings', namespace='CELERY') + +app.autodiscover_tasks() \ No newline at end of file diff --git a/backend/config/django/base.py b/backend/config/django/base.py index 8267c17..dc548ad 100644 --- a/backend/config/django/base.py +++ b/backend/config/django/base.py @@ -131,3 +131,5 @@ USE_TZ = True # https://docs.djangoproject.com/en/6.0/howto/static-files/ STATIC_URL = "static/" + +from config.settings.celery import * \ No newline at end of file diff --git a/backend/config/settings/__init__.py b/backend/config/settings/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/config/settings/celery.py b/backend/config/settings/celery.py new file mode 100644 index 0000000..94e7bf5 --- /dev/null +++ b/backend/config/settings/celery.py @@ -0,0 +1,3 @@ +from config.env import env + +CELERY_BROKER_URL = env("CELERY_BROKER_URL") \ No newline at end of file