Commit c172baa8 authored by Tom van Bussel's avatar Tom van Bussel
Browse files

Merge branch 'fix/move-vacancy-expiry-to-management-cmd' into 'master'

Move notification email of vacancies to a management command instead of using a…

See merge request !559
parents 7a51e8a0 817fe405
import datetime
from django.core.mail import EmailMessage
from django.utils import timezone
from partners.models import Vacancy
from thaliawebsite import settings
def send_vacancy_expiration_notifications(dry_run=False):
# Select vacencies that expire in roughly a month, wherefor
# a mail hasn't been sent yet to Mr/Mrs Extern
expired_vacancies = Vacancy.objects.filter(
expiration_mail_sent=False,
expiration_date__lt=timezone.now().date() + datetime.timedelta(days=30)
)
for exp_vacancy in expired_vacancies:
# Create Message
subject = ('[WEBSITE] Vacancy \'{}\' by {} will soon expire'
.format(exp_vacancy.title, exp_vacancy.get_company_name()))
text_message = ('Hello!\n\nA vacancy of {}, \'{}\' will '
'expire within the next 30 days. Maybe you '
'should contact them to negotiate a new deal. '
'\n\nKisses,\nThe website'
.format(exp_vacancy.title,
exp_vacancy.get_company_name()))
recipient = settings.PARTNER_EMAIL
if not dry_run:
# Send Mail
EmailMessage(
subject,
text_message,
to=[recipient]
).send()
# Save that mail has been sent into database
exp_vacancy.expiration_mail_sent = True
exp_vacancy.save()
from django.core.management.base import BaseCommand
from partners import emails
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument(
'--dry-run',
action='store_true',
dest='dry-run',
default=False,
help='Dry run instead of sending e-mail',
)
def handle(self, *args, **options):
emails.send_vacancy_expiration_notifications(
bool(options['dry-run']))
......@@ -8,5 +8,4 @@ urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^partners/(?P<slug>[-\w]+)$', views.partner, name='partner'),
url(r'^vacancies$', views.vacancies, name='vacancies'),
url(r'^vacancies/send-expiration-mails$', views.send_vacancy_expiration_mails, name='send-expiration-mails')
]
from random import random
import datetime
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render
from django.utils import timezone
from django.core.mail import EmailMessage
from partners.models import Partner, Vacancy, VacancyCategory
from thaliawebsite.settings import settings
def index(request):
......@@ -45,36 +40,3 @@ def vacancies(request):
}
return render(request, 'partners/vacancies.html', context)
def send_vacancy_expiration_mails():
# Select vacencies that expire in roughly a month, wherefor
# a mail hasn't been sent yet to Mr/Mrs Extern
expired_vacancies = Vacancy.objects.filter(
expiration_mail_sent=False,
expiration_date__lt=timezone.now().date() + datetime.timedelta(days=30)
)
for exp_vacancy in expired_vacancies:
# Create Message
subject = ("[THALIA][SPONSOR] Vacature '{}' van {} loopt af"
.format(exp_vacancy.title, exp_vacancy.get_company_name()))
text_message = ("Hallo Extern,\n\nde vacature van {}, '{}' loopt "
"over circa een maand af. Misschien wil "
"je ze contacteren om een nieuwe deal "
"te sluiten.\n\nGroetjes,\nDe Website"
.format(exp_vacancy.title,
exp_vacancy.get_company_name()))
recipient = settings.PARTNER_EMAIL
# Send Mail
EmailMessage(
subject,
text_message,
to=recipient
).send()
# Save that mail has been sent into database
exp_vacancy.expiration_mail_sent = True
exp_vacancy.save()
return HttpResponse(status=200)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment