Skip to content

Commit

Permalink
chore: notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Topvennie committed May 23, 2024
1 parent cb634d3 commit 7cc58dc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/api/tasks/docker_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def task_docker_image_build(docker_image: DockerImage):
client.images.build(path=MEDIA_ROOT, dockerfile=docker_image.file.path,
tag=get_docker_image_tag(docker_image), rm=True, quiet=True, forcerm=True)
docker_image.state = StateEnum.READY
except (docker.errors.APIError, docker.errors.BuildError, TypeError):
except Exception:
docker_image.state = StateEnum.ERROR
notification_type = NotificationType.DOCKER_IMAGE_BUILD_ERROR
finally:
Expand Down
5 changes: 3 additions & 2 deletions backend/notifications/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.utils.translation import gettext as _

from authentication.models import User
from django.utils.translation import gettext as _
from notifications.models import Notification, NotificationTemplate
from rest_framework import serializers

Expand All @@ -20,6 +19,7 @@ class NotificationSerializer(serializers.ModelSerializer):

title = serializers.SerializerMethodField()
content = serializers.SerializerMethodField()
arguments = serializers.JSONField(write_only=True)

def get_content(self, notification: Notification) -> str:
"""Get the content from the template and arguments."""
Expand All @@ -39,4 +39,5 @@ class Meta:
"created_at",
"is_read",
"is_sent",
"arguments"
]
8 changes: 5 additions & 3 deletions backend/notifications/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from typing import Dict, List, Union

from authentication.models import User
from django.db.models.query import QuerySet
from django.dispatch import Signal, receiver
from django.urls import reverse
from notifications.logic import schedule_send_mails
from notifications.serializers import NotificationSerializer
from ypovoli.settings import TESTING

notification_create = Signal()

Expand All @@ -21,13 +21,15 @@ def notification_creation(
arguments: Dict[str, str],
**kwargs, # Required by django
) -> bool:
if TESTING:
return True

data: List[Dict[str, Union[str, int, Dict[str, str]]]] = []

for user in queryset:
if user:
data.append(
{
"template_id": type.value,
"user": reverse("user-detail", kwargs={"pk": user.id}),
"arguments": arguments,
}
Expand All @@ -38,7 +40,7 @@ def notification_creation(
if not serializer.is_valid(raise_exception=False):
return False

serializer.save()
serializer.save(template_id_id=type.value)

schedule_send_mails()

Expand Down
1 change: 1 addition & 0 deletions backend/ypovoli/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
MEDIA_ROOT = os.path.normpath(os.path.join("data"))

# TESTING
TESTING = environ.get("DJANGO_TESTING", "False").lower() in ["true", "1", "t"]
TESTING_BASE_LINK = "http://testserver"
TEST_ADMIN_DATA = {
"id": "0",
Expand Down
2 changes: 2 additions & 0 deletions test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ services:
context: $BACKEND_DIR
dockerfile: Dockerfile.dev
command: sh -c "./setup.sh && python manage.py runsslserver 0.0.0.0:8000"
environment:
- DJANGO_TESTING=true
volumes:
- $BACKEND_DIR:/code
depends_on:
Expand Down

0 comments on commit 7cc58dc

Please sign in to comment.