Skip to content

Commit

Permalink
Merge pull request #224 from Paulfuther/dev-v1.0.01
Browse files Browse the repository at this point in the history
Update to employee engagement report
  • Loading branch information
Paulfuther authored Jan 9, 2025
2 parents 2fb6a6f + 70570d9 commit a7aa366
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
17 changes: 17 additions & 0 deletions arl/arl/msg/migrations/0018_emailtemplate_include_in_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.10 on 2025-01-09 23:16

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("msg", "0017_emaillist"),
]

operations = [
migrations.AddField(
model_name="emailtemplate",
name="include_in_report",
field=models.BooleanField(default=False),
),
]
1 change: 1 addition & 0 deletions arl/arl/msg/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __str__(self):
class EmailTemplate(models.Model):
name = models.CharField(max_length=100, null=True)
sendgrid_id = models.TextField()
include_in_report = models.BooleanField(default=False)

def __str__(self):
return self.name
Expand Down
13 changes: 8 additions & 5 deletions arl/arl/msg/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
from celery.utils.log import get_task_logger
from django.conf import settings
from django.contrib.auth.models import Group
from django.core.cache import cache
from django.db import connection
from django.db.models import (Count, F, Func, IntegerField, OuterRef, Q,
Subquery)
from django.db.models import F, Func, IntegerField, OuterRef, Subquery
from django.utils import timezone

from arl.celery import app
from arl.msg.models import EmailEvent, Message, SmsLog
from arl.msg.models import EmailEvent, EmailTemplate, Message, SmsLog
from arl.user.models import CustomUser

from .helpers import (client, create_master_email, create_single_csv_email,
Expand Down Expand Up @@ -575,8 +573,13 @@ def generate_employee_email_report_task(employee_id):
employee = CustomUser.objects.get(pk=employee_id)
email = employee.email

# Fetch template IDs for templates marked as "include_in_report"
template_ids = EmailTemplate.objects.filter(
include_in_report=True).values_list('sendgrid_id', flat=True)
# print(template_ids)
# Search for all email events related to this email address
email_events = EmailEvent.objects.filter(email=email)
email_events = EmailEvent.objects.filter(email=email,
sg_template_id__in=template_ids)

# Summarize the events into a DataFrame
event_data = list(email_events.values('event', 'sg_template_name'))
Expand Down
6 changes: 6 additions & 0 deletions arl/arl/user/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
# fields = list(UserAdmin.fieldsets)


class EmailTemplateAdmin(admin.ModelAdmin):
list_display = ('name', 'sendgrid_id', 'include_in_report') # Display the checkbox
list_editable = ('include_in_report',) # Allow inline editing of the checkbox
search_fields = ('name',)


class ExternalRecipientAdmin(admin.ModelAdmin):
list_display = ('first_name', 'last_name', 'company', 'email', 'group')
search_fields = ('first_name', 'last_name', 'company', 'email',
Expand Down

0 comments on commit a7aa366

Please sign in to comment.