Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add send users active tasks email #935

Merged
merged 6 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/backend/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"task": "send_completed_tasks_mail",
"schedule": crontab(minute=0, hour="*/6"), # execute 4 times in a day
},
"Send_mail_to_users_active": {
"task": "send_active_tasks_mail",
"schedule": crontab(minute=0, hour=10),
},
"Send_mail_to_managers_new": {
"task": "send_new_tasks_mail",
"schedule": crontab(minute=0, hour=1), # execute everyday at 1 am
Expand Down
65 changes: 65 additions & 0 deletions backend/user_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,71 @@ def get_completed_tasks():
else:
html_table_df_tasks = ""

def get_active_tasks():
users = User.objects.filter(id=64)

for member in list(users):
tasks_managed = []
tasks = (
Task.objects
.filter(status__in=["INPROGRESS", "SELECTED_SOURCE"])
.filter(is_active=True)
.filter(user=member)
)
for task in tasks:
type = "voiceover" if task.task_type.find("VOICEOVER") else "translate" if task.task_type.find("TRANSLATION") else "transcript"
tasks_managed.append(
{
"Project Name": task.video.project_id.title,
"Project Id": task.video.project_id.id,
"Task ID": task.id,
"Task Type": task.get_task_type_label,
"Task Link": "https://chitralekha.ai4bharat.org/#/task/"+str(task.id)+"/"+type
}
)
if len(tasks_managed) > 0:
df = pd.DataFrame.from_records(tasks_managed)
blankIndex = [""] * len(df)
df.index = blankIndex
html_table_df_tasks = build_table(
df,
"orange_light",
font_size="medium",
text_align="left",
width="auto",
index=False,
)
message = (
"Hope you are doing great "
+ str(member.first_name + " " + member.last_name)
+ ",\n Following tasks are active now."
)

email_to_send = (
"<p>"
+ message
+ "</p><br><h1><b>Active Tasks Reports</b></h1>"
+ html_table_df_tasks
)
logging.info("Sending Mail to %s", member.email)

compiled_msg = send_email_template_with_attachment(
subject=f"{app_name} - Active Tasks Report",
username=[member.email],
message=email_to_send,
)
msg = EmailMultiAlternatives(
f"{app_name} - Active Tasks Report",
compiled_msg,
settings.DEFAULT_FROM_EMAIL,
[member.email],
)
email_content = compiled_msg
msg.attach_alternative(email_content, "text/html")
msg.send()
else:
html_table_df_tasks = ""


def get_new_tasks():
logging.info("Calculate Reports...")
Expand Down
3 changes: 3 additions & 0 deletions backend/users/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
def send_completed_tasks_mail():
get_completed_tasks()

@shared_task(name="send_active_tasks_mail")
def send_active_tasks_mail():
get_active_tasks()

@shared_task(name="send_new_tasks_mail")
def send_new_tasks_mail():
Expand Down
Loading