mirror of
https://github.com/RoboSats/robosats.git
synced 2025-09-05 06:24:15 +00:00
CodeReview
This commit is contained in:
@ -1,9 +1,7 @@
|
||||
# Generated by Django 5.0.6 on 2024-06-09 10:21
|
||||
# Generated by Django 5.0.6 on 2024-06-14 18:31
|
||||
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
import uuid
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
@ -11,7 +9,6 @@ class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api', '0046_alter_currency_currency'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
@ -19,12 +16,11 @@ class Migration(migrations.Migration):
|
||||
name='Notification',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('reference', models.UUIDField(default=uuid.uuid4, editable=False)),
|
||||
('created_at', models.DateTimeField(default=django.utils.timezone.now)),
|
||||
('title', models.CharField(default=None, max_length=120)),
|
||||
('description', models.CharField(blank=True, default=None, max_length=120)),
|
||||
('title', models.CharField(default=None, max_length=240)),
|
||||
('description', models.CharField(blank=True, default=None, max_length=240)),
|
||||
('order', models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='api.order')),
|
||||
('user', models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
('robot', models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='api.robot')),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
@ -2,8 +2,7 @@
|
||||
import uuid
|
||||
|
||||
from decouple import config
|
||||
from django.contrib.auth.models import User
|
||||
from api.models import Order
|
||||
from api.models import Order, Robot
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
||||
@ -23,15 +22,14 @@ else:
|
||||
|
||||
class Notification(models.Model):
|
||||
# notification info
|
||||
reference = models.UUIDField(default=custom_uuid, editable=False)
|
||||
created_at = models.DateTimeField(default=timezone.now)
|
||||
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, default=None)
|
||||
robot = models.ForeignKey(Robot, on_delete=models.CASCADE, default=None)
|
||||
order = models.ForeignKey(Order, on_delete=models.CASCADE, default=None)
|
||||
|
||||
# notification details
|
||||
title = models.CharField(max_length=120, null=False, default=None)
|
||||
description = models.CharField(max_length=120, default=None, blank=True)
|
||||
title = models.CharField(max_length=240, null=False, default=None)
|
||||
description = models.CharField(max_length=240, default=None, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.title} {self.description}"
|
||||
|
@ -39,12 +39,9 @@ class Notifications:
|
||||
|
||||
def save_message(self, order, robot, title, description):
|
||||
"""Save a message for a user"""
|
||||
notification = Notification()
|
||||
notification.title = title
|
||||
notification.description = description
|
||||
notification.user = robot
|
||||
notification.order = order
|
||||
notification.save()
|
||||
Notification.objects.create(
|
||||
title=title, description=description, robot=robot, order=order
|
||||
)
|
||||
|
||||
def send_telegram_message(self, chat_id, title, description):
|
||||
"""sends a message to a user with telegram notifications enabled"""
|
||||
|
@ -749,8 +749,8 @@ class NotificationsView(ListAPIView):
|
||||
|
||||
@extend_schema(**NotificationSchema.get)
|
||||
def get(self, request, format=None):
|
||||
user = request.user
|
||||
queryset = Notification.objects.filter(user=user)
|
||||
robot = request.user.robot
|
||||
queryset = Notification.objects.filter(robot=robot)
|
||||
created_at = request.GET.get("created_at")
|
||||
|
||||
if created_at:
|
||||
|
Reference in New Issue
Block a user