-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from JahongirHakimjonov/dev
Dev
- Loading branch information
Showing
25 changed files
with
338 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 5.0.8 on 2024-12-18 07:19 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("mystories", "0002_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="notification", | ||
name="type", | ||
field=models.CharField( | ||
choices=[("SINGLE", "Single"), ("ALL", "All")], | ||
default="SINGLE", | ||
max_length=10, | ||
verbose_name="Type", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,34 @@ | ||
import io | ||
import logging | ||
|
||
from PIL import Image | ||
from django.core.files.base import ContentFile | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
|
||
from apps.mystories.models import Notification | ||
from apps.mystories.tasks import send_notification_task | ||
from apps.mystories.models import Notification, NotificationType | ||
from apps.mystories.tasks import send_notification_task, send_notification_to_all_task | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@receiver(post_save, sender=Notification) | ||
def send_notification(sender, instance, created, **kwargs): # noqa | ||
if created: | ||
if created and instance.type == NotificationType.SINGLE: | ||
send_notification_task.delay(instance.id) | ||
logger.info(f"Notification {instance.title} sent.") | ||
elif created and instance.type == NotificationType.ALL: | ||
send_notification_to_all_task.delay(instance.id) | ||
logger.info(f"Notification {instance.title} sent to all users.") | ||
elif created: | ||
if instance.banner: | ||
img = Image.open(instance.banner) | ||
if img.format != "WEBP": | ||
img_io = io.BytesIO() | ||
img.save(img_io, format="WEBP", quality=100) | ||
instance.banner.save( | ||
f"{instance.banner.name.split('.')[0]}.webp", | ||
ContentFile(img_io.getvalue()), | ||
save=False, | ||
) | ||
instance.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.