# Path: profile/models.py
# class Profile(models.Model):
#     user = models.OneToOneField(User, on_delete=models.CASCADE)
#     full_name = models.TextField()
#     notifications = models.ForeignKey('profile.Notifications', on_delete=models.CASCADE)
#     subscriptions = models.ManyToManyField('petitions.Petition', related_name='profile_subscriptions', blank=True)
#     petitions_created = models.ManyToManyField('petitions.Petition', related_name='profile_petitions_created', blank=True)
#     petitions_signed = models.ManyToManyField('petitions.Petition', related_name='profile_petitions_signed', blank=True)
#     display_name = models.CharField(max_length=3, blank=True)
#     # 0 - Does not have access, 1 - Has Access
#     has_access = models.PositiveSmallIntegerField(default=1)
# 
#     def __unicode__(self):
#         return self.user.username


from petitions.models import *
from profile.models import Profile
from django.conf import settings
from django.db.models import Q
from django.core.mail import EmailMessage
from django.template.loader import get_template
from django.template import Context
from huey.contrib.djhuey import db_task
import time
import logging
    email = generate_email(petition_id, 'approved', site_path)
    send_email(email, petition_id, 'Approved')


@db_task(retries=3, retry_delay=3)
def petition_rejected(petition_id, site_path):
    email = generate_email(petition_id, 'rejected', site_path)
    send_email(email, petition_id, 'Rejected')


@db_task(retries=3, retry_delay=3)
def petition_update(petition_id, site_path):
    petition = Petition.objects.get(pk=petition_id)

    # Gets all users that are subscribed or have signed the petition and if they want to receive email updates.
    users = Profile.objects.filter(Q(subscriptions=petition) | Q(petitions_signed=petition)).filter(
        notifications__update=True).distinct("id")

    # Construct array of email addresses
    recipients = [prof.user.email for prof in users]

    email = generate_email(petition_id, 'updated', site_path, EMAIL_ADDR, recipients)
    send_email(email, petition_id, 'Status Update')


@db_task(retries=3, retry_delay=3)
def petition_responded(petition_id, site_path):
    petition = Petition.objects.get(pk=petition_id)

    # Gets all users that are subscribed or have signed the petition and if they want to receive email updates.

# Path: profile/models.py
# class Profile(models.Model):
#     user = models.OneToOneField(User, on_delete=models.CASCADE)
#     full_name = models.TextField()
#     notifications = models.ForeignKey('profile.Notifications', on_delete=models.CASCADE)
#     subscriptions = models.ManyToManyField('petitions.Petition', related_name='profile_subscriptions', blank=True)
#     petitions_created = models.ManyToManyField('petitions.Petition', related_name='profile_petitions_created', blank=True)
#     petitions_signed = models.ManyToManyField('petitions.Petition', related_name='profile_petitions_signed', blank=True)
#     display_name = models.CharField(max_length=3, blank=True)
#     # 0 - Does not have access, 1 - Has Access
#     has_access = models.PositiveSmallIntegerField(default=1)
# 
#     def __unicode__(self):
#         return self.user.username


# Path: send_mail/tasks.py
from petitions.models import *
from profile.models import Profile
from django.conf import settings
from django.db.models import Q
from django.core.mail import EmailMessage
from django.template.loader import get_template
from django.template import Context
from huey.contrib.djhuey import db_task
import time
import logging

    email = generate_email(petition_id, 'approved', site_path)
    send_email(email, petition_id, 'Approved')


@db_task(retries=3, retry_delay=3)
def petition_rejected(petition_id, site_path):
    email = generate_email(petition_id, 'rejected', site_path)
    send_email(email, petition_id, 'Rejected')


@db_task(retries=3, retry_delay=3)
def petition_update(petition_id, site_path):
    petition = Petition.objects.get(pk=petition_id)

    # Gets all users that are subscribed or have signed the petition and if they want to receive email updates.
    users = Profile.objects.filter(Q(subscriptions=petition) | Q(petitions_signed=petition)).filter(
        notifications__update=True).distinct("id")

    # Construct array of email addresses
    recipients = [prof.user.email for prof in users]

    email = generate_email(petition_id, 'updated', site_path, EMAIL_ADDR, recipients)
    send_email(email, petition_id, 'Status Update')


@db_task(retries=3, retry_delay=3)
def petition_responded(petition_id, site_path):
    petition = Petition.objects.get(pk=petition_id)

    # Gets all users that are subscribed or have signed the petition and if they want to receive email updates.

    users = Profile.objects.filter(Q(subscriptions=petition) | Q(petitions_signed=petition)).filter(