Skip to content

Commit

Permalink
Following changes are made with this commit :
Browse files Browse the repository at this point in the history
Refactor : Merged Schedule mail and Sent mail in a single Model

Refactor : Email Column Validation in Bulk Upload

Add : More than one attachment for Mail
  • Loading branch information
ClawedCatalyst committed Jan 23, 2023
1 parent 7689741 commit 0c0f52b
Show file tree
Hide file tree
Showing 189 changed files with 315 additions and 36,317 deletions.
38 changes: 16 additions & 22 deletions authentication/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from django.core.mail import get_connection
from mailer.models import *
from django_celery_results.models import TaskResult
from django_celery_results.backends.cache import CacheBackend
import re
from django.conf import settings


from mailer.models import Group_Details
Expand All @@ -31,17 +32,21 @@ def send_otp(self,email):
return 'Done'

@shared_task(bind=True)
def send_custom_mass_mail(self,_from,_group,_subject,_company,_body,file,_template):
def send_custom_mass_mail(self,_from,_group,_subject,_company,_body,_template,mailID):


groups = Group_Details.objects.filter(group=_group)
appGmail = Gmail_APP_Model.objects.get(id=_from)
datatuple = [{'name':group.name,'email':group.email} for group in groups]
print(appGmail.email, appGmail.app_password)
file_attached = FileUploadForMail.objects.filter(mail=mailID)
print(file_attached)

html = ''


if _template is not None:
print(_template)
html = str(Template.objects.get(id=_template))

connections = get_connection(
Expand All @@ -61,25 +66,24 @@ def send_custom_mass_mail(self,_from,_group,_subject,_company,_body,file,_templa
for recipient in datatuple:
msg = EmailMultiAlternatives(_subject, _body,by, [recipient["email"]] , connection=connections)
if _template is not None:
formatedhtml = html
if re.findall('{name}',html):
print(re.findall('{name}',html))
html = html.format(name=recipient["name"])
msg.attach_alternative(html, "text/html")

if file != 'None':
msg.attach_file(file)

formatedhtml = html.format(name=recipient["name"])
msg.attach_alternative(formatedhtml, "text/html")

if file_attached.count() > 0:
for file in file_attached:
print(file.file.name)
msg.attach_file(settings.MEDIA_ROOT + (f'/{file.file.name}'))
messages.append(msg)

return connections.send_messages(messages)


@shared_task(bind=True)
def status_update(self):
pending_task_id = SentMail.objects.filter(status='PENDING')

scheduling_task_id = SchedulingMail.objects.filter(status='PENDING')
print(pending_task_id)

for i in pending_task_id:
try :
celery_id = TaskResult.objects.get(task_id=i.celeryID)
Expand All @@ -89,16 +93,6 @@ def status_update(self):

except:
i.status = 'PENDING'

for i in scheduling_task_id:
try :
celery_id = TaskResult.objects.get(task_id=i.celeryID)
i.status = celery_id.status
print(celery_id.status)
i.save()

except:
i.status = 'PENDING'

return 'Done'

Expand Down
1 change: 1 addition & 0 deletions authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Password_Change_View(generics.GenericAPIView, mixins.UpdateModelMixin):
serializer_class = ChangePasswordSerializer

def get_object(self):

email = self.request.data.get('email')
user = New_User_Resgistration.objects.get(email=email)
return user
Expand Down
2 changes: 2 additions & 0 deletions bulkmailer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
Expand Down
4 changes: 4 additions & 0 deletions bulkmailer/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
"""
from django.contrib import admin
from django.urls import path, include
from bulkmailer import settings
from django.conf.urls.static import static

urlpatterns = [
path("admin/", admin.site.urls),
path("auth/", include('authentication.urls')),
path("dashboard/", include('mailer.urls'))
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Binary file modified dump.rdb
Binary file not shown.
2 changes: 1 addition & 1 deletion mailer/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
admin.site.register(models.Groups)
admin.site.register(models.Template)
admin.site.register(models.SentMail)
admin.site.register(models.SchedulingMail)
admin.site.register(models.FileUploadForMail)

@admin.register(models.Group_Details)
class PersonAdmin(ImportExportModelAdmin):
Expand Down
73 changes: 2 additions & 71 deletions mailer/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.1.4 on 2023-01-21 17:39
# Generated by Django 4.1.4 on 2023-01-22 15:53

from django.conf import settings
from django.db import migrations, models
Expand Down Expand Up @@ -29,75 +29,6 @@ class Migration(migrations.Migration):
("template", models.TextField()),
],
),
migrations.CreateModel(
name="SentMail",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("_from", models.CharField(max_length=200)),
("_group", models.CharField(max_length=200)),
("_company", models.CharField(blank=True, max_length=200, null=True)),
("_body", models.CharField(blank=True, max_length=200, null=True)),
("_subject", models.CharField(max_length=200)),
("_template", models.CharField(blank=True, max_length=200, null=True)),
("_file", models.FileField(blank=True, null=True, upload_to="media")),
("_image", models.ImageField(blank=True, null=True, upload_to="media")),
("time", models.DateTimeField(auto_now=True)),
("celeryID", models.CharField(blank=True, max_length=200, null=True)),
("status", models.CharField(default="Pending", max_length=200)),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
],
),
migrations.CreateModel(
name="SchedulingMail",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("_from", models.CharField(max_length=200)),
("_group", models.CharField(max_length=200)),
("_company", models.CharField(blank=True, max_length=200, null=True)),
("_body", models.CharField(blank=True, max_length=200, null=True)),
("_subject", models.CharField(max_length=200)),
("_template", models.CharField(blank=True, max_length=200, null=True)),
("_file", models.FileField(blank=True, null=True, upload_to="media")),
("_image", models.ImageField(blank=True, null=True, upload_to="media")),
("_year", models.IntegerField()),
("_month", models.IntegerField()),
("_date", models.IntegerField()),
("_hour", models.IntegerField()),
("_minute", models.IntegerField()),
("time", models.DateTimeField(auto_now=True)),
("celeryID", models.CharField(blank=True, max_length=200, null=True)),
("status", models.CharField(default="PENDING", max_length=200)),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
],
),
migrations.CreateModel(
name="Groups",
fields=[
Expand Down Expand Up @@ -132,7 +63,7 @@ class Migration(migrations.Migration):
verbose_name="ID",
),
),
("email", models.CharField(max_length=200, unique=True)),
("email", models.CharField(max_length=200)),
("name", models.CharField(max_length=200, null=True)),
(
"gender",
Expand Down
85 changes: 85 additions & 0 deletions mailer/migrations/0002_sentmail_schedulingmail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Generated by Django 4.1.4 on 2023-01-22 15:54

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("mailer", "0001_initial"),
]

operations = [
migrations.CreateModel(
name="SentMail",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("_from", models.CharField(max_length=200)),
("_group", models.CharField(max_length=200)),
("_company", models.CharField(blank=True, max_length=200, null=True)),
("_body", models.CharField(blank=True, max_length=200, null=True)),
("_subject", models.CharField(max_length=200)),
("_template", models.CharField(blank=True, max_length=200, null=True)),
("_file", models.FileField(blank=True, null=True, upload_to="media")),
("_image", models.ImageField(blank=True, null=True, upload_to="media")),
("time", models.DateTimeField(auto_now=True)),
("celeryID", models.CharField(blank=True, max_length=200, null=True)),
("status", models.CharField(default="PENDING", max_length=200)),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
],
),
migrations.CreateModel(
name="SchedulingMail",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("_from", models.CharField(max_length=200)),
("_group", models.CharField(max_length=200)),
("_company", models.CharField(blank=True, max_length=200, null=True)),
("_body", models.CharField(blank=True, max_length=200, null=True)),
("_subject", models.CharField(max_length=200)),
("_template", models.CharField(blank=True, max_length=200, null=True)),
("_file", models.FileField(blank=True, null=True, upload_to="media")),
("_image", models.ImageField(blank=True, null=True, upload_to="media")),
("_year", models.IntegerField()),
("_month", models.IntegerField()),
("_date", models.IntegerField()),
("_hour", models.IntegerField()),
("_minute", models.IntegerField()),
("time", models.DateTimeField(auto_now=True)),
("celeryID", models.CharField(blank=True, max_length=200, null=True)),
("status", models.CharField(default="PENDING", max_length=200)),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Generated by Django 4.1.4 on 2023-01-23 10:40

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("mailer", "0002_sentmail_schedulingmail"),
]

operations = [
migrations.AddField(
model_name="sentmail",
name="_date",
field=models.IntegerField(blank=True, null=True),
),
migrations.AddField(
model_name="sentmail",
name="_hour",
field=models.IntegerField(blank=True, null=True),
),
migrations.AddField(
model_name="sentmail",
name="_minute",
field=models.IntegerField(blank=True, null=True),
),
migrations.AddField(
model_name="sentmail",
name="_month",
field=models.IntegerField(blank=True, null=True),
),
migrations.AddField(
model_name="sentmail",
name="_year",
field=models.IntegerField(blank=True, null=True),
),
migrations.AddField(
model_name="sentmail",
name="scheduleMail",
field=models.BooleanField(default=False),
),
migrations.DeleteModel(
name="SchedulingMail",
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.1.4 on 2023-01-23 11:46

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("mailer", "0003_sentmail__date_sentmail__hour_sentmail__minute_and_more"),
]

operations = [
migrations.AlterField(
model_name="sentmail",
name="_from",
field=models.CharField(blank=True, max_length=200, null=True),
),
migrations.AlterField(
model_name="sentmail",
name="_group",
field=models.CharField(blank=True, max_length=200, null=True),
),
migrations.AlterField(
model_name="sentmail",
name="_subject",
field=models.CharField(blank=True, max_length=200, null=True),
),
]
Loading

0 comments on commit 0c0f52b

Please sign in to comment.