Skip to content

Commit 73d9d31

Browse files
Add link to nofitications and schedule daily
1 parent cc15bd3 commit 73d9d31

File tree

6 files changed

+103
-63
lines changed

6 files changed

+103
-63
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import logging
2+
from datetime import timedelta
3+
4+
from django.contrib.auth.models import User
5+
from django.core.management.base import BaseCommand
6+
from django.utils.timezone import now
7+
8+
from website.models import Notification
9+
10+
logger = logging.getLogger(__name__)
11+
12+
13+
class Command(BaseCommand):
14+
help = "Send reminder notifications to users who haven't checked in the last 24 hours."
15+
16+
def handle(self, *args, **options):
17+
cutoff_date = now().date() - timedelta(days=1)
18+
19+
users_without_checkin = User.objects.exclude(dailystatusreport__date__gte=cutoff_date)
20+
21+
# Create the reminder notifications for these users
22+
for user in users_without_checkin:
23+
Notification.objects.create(
24+
user=user,
25+
message="Don't forget to complete your daily check-in!",
26+
notification_type="reminder",
27+
link="/add-sizzle-checkin",
28+
)
29+
30+
count = users_without_checkin.count()
31+
logger.info(f"Sent reminder notifications to {count} users.")

website/management/commands/run_daily.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import logging
22

3+
from django.core import management
34
from django.core.management.base import BaseCommand
4-
5-
# from django.core import management
65
from django.utils import timezone
76

87
logger = logging.getLogger(__name__)
@@ -16,6 +15,7 @@ def handle(self, *args, **options):
1615
logger.info(f"Starting daily scheduled tasks at {timezone.now()}")
1716

1817
# Add commands to be executed daily
18+
management.call_command("checkin_reminder_notification")
1919
# management.call_command('daily_command1')
2020
# management.call_command('daily_command2')
2121
except Exception as e:

website/migrations/0181_notification.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 5.1.4 on 2025-01-12 14:26
1+
# Generated by Django 5.1.4 on 2025-01-19 14:46
22

33
import django.db.models.deletion
44
from django.conf import settings
@@ -31,6 +31,7 @@ class Migration(migrations.Migration):
3131
"notification_type",
3232
models.CharField(default="general", max_length=50),
3333
),
34+
("link", models.CharField(blank=True, max_length=200, null=True)),
3435
(
3536
"user",
3637
models.ForeignKey(

website/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,7 @@ class Notification(models.Model):
13441344
created_at = models.DateTimeField(auto_now_add=True)
13451345
is_read = models.BooleanField(default=False)
13461346
notification_type = models.CharField(max_length=50, default="general")
1347+
link = models.CharField(max_length=200, blank=True, null=True)
13471348

13481349
def __str__(self):
13491350
return f"Notification for {self.user.username} - {self.notification_type}"

website/templates/includes/header.html

Lines changed: 66 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ <h3 class="text-xl font-extrabold">Chat with BLT Bot</h3>
404404
notifications.forEach(notification => {
405405
const listItem = document.createElement('li');
406406
listItem.className = `p-4 hover:bg-gray-100 relative ${notification.is_read ? '' : 'bg-blue-50'}`;
407+
console.log("Printing notif link")
408+
console.log(notification.link)
407409

408410
notif_icon_src = ""
409411
if (notification.notification_type == 'reward'){
@@ -416,20 +418,24 @@ <h3 class="text-xl font-extrabold">Chat with BLT Bot</h3>
416418

417419

418420
const content = `
419-
<div class="flex items-center space-x-4 w-full notification-item" data-notification-id="${notification.id}">
420-
<img src="${notif_icon_src}" class="h-12 w-12 object-cover" alt="Notification Icon">
421-
<div class="flex-1">
422-
<div class="flex justify-between items-start">
423-
<p class="text-xl font-medium text-gray-900 mb-1">${notification.message}</p>
424-
${!notification.is_read ? '<div class="flex items-center justify-center w-2 h-2 bg-red-500 rounded-full" style="min-width: 7px; min-height: 7px;"></div>' : ''}
425-
</div>
426-
<div class="flex items-center space-x-2 mt-1">
427-
<span class="text-sm text-gray-600">${new Date(notification.created_at).toLocaleString()}</span>
428-
${!notification.is_read ? '<span class="text-sm font-medium text-blue-600">New</span>' : ''}
429-
</div>
421+
<div class="flex items-center space-x-4 w-full notification-item" data-notification-id="${notification.id}" style="cursor: ${notification.link ? 'pointer' : 'default'};">
422+
${notification.link
423+
? `<a href="${notification.link}" class="flex items-center space-x-4 w-full" target="_blank" rel="noopener noreferrer">`
424+
: ''}
425+
<img src="${notif_icon_src}" class="h-12 w-12 object-cover" alt="Notification Icon">
426+
<div class="flex-1">
427+
<div class="flex justify-between items-start">
428+
<p class="text-xl font-medium text-gray-900 mb-1">${notification.message}</p>
429+
${!notification.is_read ? '<div class="flex items-center justify-center w-2 h-2 bg-red-500 rounded-full" style="min-width: 7px; min-height: 7px;"></div>' : ''}
430+
</div>
431+
<div class="flex items-center space-x-2 mt-1">
432+
<span class="text-sm text-gray-600">${new Date(notification.created_at).toLocaleString()}</span>
433+
${!notification.is_read ? '<span class="text-sm font-medium text-blue-600">New</span>' : ''}
434+
</div>
435+
</div>
436+
${notification.link ? '</a>' : ''}
430437
</div>
431-
</div>
432-
`;
438+
`;
433439
listItem.innerHTML = content;
434440
notificationList.appendChild(listItem);
435441
});
@@ -475,56 +481,56 @@ <h3 class="text-xl font-extrabold">Chat with BLT Bot</h3>
475481
</script>
476482
<!--Script for Dropdown button-->
477483
<script>
478-
const organizationsBtn = document.getElementById("organizations-btn");
479-
const organizationsDropdown = document.getElementById("organizations-dropdown");
480-
481-
if (organizationsBtn && organizationsDropdown) {
482-
organizationsBtn.addEventListener("click", function (e) {
483-
e.preventDefault();
484-
e.stopPropagation();
485-
486-
const isHidden = organizationsDropdown.classList.toggle('hidden');
487-
488-
if (!isHidden) {
489-
const btnRect = organizationsBtn.getBoundingClientRect();
490-
Object.assign(organizationsDropdown.style, {
491-
position: 'fixed',
492-
top: `${btnRect.bottom}px`,
493-
left: `${btnRect.left}px`,
494-
minWidth: `${btnRect.width}px`,
495-
display: 'block',
496-
});
497-
} else {
498-
organizationsDropdown.style.display = 'none';
499-
}
500-
});
484+
document.addEventListener("DOMContentLoaded", function () {
501485

502-
// Close dropdown when clicking outside
503-
document.addEventListener("click", function (e) {
504-
if (!organizationsBtn.contains(e.target) && !organizationsDropdown.contains(e.target)) {
505-
organizationsDropdown.classList.add('hidden');
506-
organizationsDropdown.style.display = 'none';
507-
}
508-
});
509-
} else {
510-
console.error('Required elements not found!');
511-
}
486+
const organizationsBtn = document.getElementById("organizations-btn");
487+
const organizationsDropdown = document.getElementById("organizations-dropdown");
512488

513-
// Fix: Remove extra closing parenthesis here
514-
document.querySelectorAll('.filter-option').forEach(option => {
515-
option.addEventListener('click', function(e) {
516-
e.preventDefault();
517-
const iconElement = this.querySelector('i');
518-
const textContent = this.textContent.trim();
519-
520-
const selectedIcon = document.getElementById('selected-icon');
521-
const selectedFilter = document.getElementById('selected-filter');
489+
if (organizationsBtn && organizationsDropdown) {
490+
organizationsBtn.addEventListener("click", function (e) {
491+
e.preventDefault();
492+
e.stopPropagation();
493+
494+
const isHidden = organizationsDropdown.classList.toggle('hidden');
495+
496+
if (!isHidden) {
497+
const btnRect = organizationsBtn.getBoundingClientRect();
498+
Object.assign(organizationsDropdown.style, {
499+
position: 'fixed',
500+
top: `${btnRect.bottom}px`,
501+
left: `${btnRect.left}px`,
502+
minWidth: `${btnRect.width}px`,
503+
display: 'block',
504+
});
505+
} else{
506+
organizationsDropdown.style.display = 'none';
507+
}
508+
});
509+
// Close dropdown when clicking outside
510+
document.addEventListener("click", function (e) {
511+
if (!organizationsBtn.contains(e.target) && !organizationsDropdown.contains(e.target)) {
512+
organizationsDropdown.classList.add('hidden');
513+
organizationsDropdown.style.display = 'none';
514+
}
515+
});
516+
} else {
517+
console.error('Required elements not found!');
518+
}
519+
document.querySelectorAll('.filter-option').forEach(option => {
520+
option.addEventListener('click', function(e) {
521+
e.preventDefault();
522+
const iconElement = this.querySelector('i');
523+
const textContent = this.textContent.trim();
524+
525+
const selectedIcon = document.getElementById('selected-icon');
526+
const selectedFilter = document.getElementById('selected-filter');
522527

523-
selectedIcon.className = iconElement.className + ' mr-2';
524-
selectedFilter.textContent = textContent;
525-
526-
organizationsDropdown.classList.add('hidden');
527-
organizationsDropdown.style.display = 'none';
528+
selectedIcon.className = iconElement.className + ' mr-2';
529+
selectedFilter.textContent = textContent;
530+
531+
organizationsDropdown.classList.add('hidden');
532+
organizationsDropdown.style.display = 'none';
533+
});
528534
});
529535
});
530536
</script>

website/views/user.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ def fetch_notifications(request):
802802
"created_at": notification.created_at,
803803
"is_read": notification.is_read,
804804
"notification_type": notification.notification_type,
805+
"link": notification.link,
805806
}
806807
for notification in notifications
807808
]

0 commit comments

Comments
 (0)