Skip to content

Commit

Permalink
Merge pull request #644 from FJNR-inc/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
RignonNoel authored Aug 31, 2020
2 parents 1c79822 + b98be80 commit 82a263e
Show file tree
Hide file tree
Showing 54 changed files with 2,428 additions and 2,291 deletions.
22 changes: 22 additions & 0 deletions blitz_api/cron_manager_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ def create_wait_queue_place_notification(self, wait_queue_place_id):

self.create_task(data)

def create_email_task(self, retreat, email, execution_date):
"""
:param retreat: The Retreat associate with this email
:param email: The AutomaticEmail we want to schedule
:return: None
"""
target_url = self.url_to_call + reverse(
'retreat:retreat-detail',
args=[retreat.id]
) + "/execute_automatic_email/?email=" + str(email.id)

description = "Automatic email #" + str(email.id) + \
" for retreat #" + str(retreat.id)
data = {
"execution_datetime": execution_date,
"url": target_url,
"description": description
}

self.create_task(data)

def create_remind_user(self, retreat_id, reminder_date):
remind_users_url = self.url_to_call + reverse(
'retreat:retreat-detail',
Expand Down
6 changes: 0 additions & 6 deletions blitz_api/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ class Meta:
notification_interval = timedelta(hours=24)
activity_language = factory.fuzzy.FuzzyChoice(Retreat.ACTIVITY_LANGUAGE)
price = factory.fuzzy.FuzzyDecimal(0, 9999, 2)
start_time = factory.Faker('date_time_between',
start_date="+10d", end_date="+30d",
tzinfo=tz.tzutc())
end_time = factory.Faker('date_time_between',
start_date="+31d", end_date="+600d",
tzinfo=tz.tzutc())
min_day_refund = factory.fuzzy.FuzzyInteger(0)
refund_rate = factory.fuzzy.FuzzyInteger(0)
min_day_exchange = factory.fuzzy.FuzzyInteger(0)
Expand Down
27 changes: 23 additions & 4 deletions blitz_api/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,26 @@ def send_mail(users, context, template):
Uses Anymail to send templated emails.
Returns a list of email addresses to which emails failed to be delivered.
"""
MAIL_SERVICE = settings.ANYMAIL
template = MAIL_SERVICE["TEMPLATES"].get(template)

return send_email_from_template_id(users, context, template)


def send_email_from_template_id(users, context, template):
"""
Uses Anymail to send templated emails.
Returns a list of email addresses to which emails failed to be delivered.
:param users: The list of users to notify
:param context: The context variables of the template
:param template: The template of the ESP
:return: A list of email addresses to which emails failed to be delivered
"""

if settings.LOCAL_SETTINGS['EMAIL_SERVICE'] is False:
raise MailServiceError(_(
"Email service is disabled."
))
MAIL_SERVICE = settings.ANYMAIL

failed_emails = list()
for user in users:
Expand All @@ -43,17 +58,21 @@ def send_mail(users, context, template):
)
message.from_email = None # required for SendinBlue templates
# use this SendinBlue template
message.template_id = MAIL_SERVICE["TEMPLATES"].get(template)
message.template_id = int(template)
message.merge_global_data = context
try:
# return number of successfully sent emails
response = message.send()
EmailLog.add(user.email, template, response)
EmailLog.add(
user.email,
"Template #" + str(template),
response
)
except Exception as err:
additional_data = {
'email': user.email,
'context': context,
'template': template
'template': "Template #" + str(template)
}
Log.error(
source='SENDING_BLUE_TEMPLATE',
Expand Down
22 changes: 22 additions & 0 deletions blitz_api/testing_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from rest_framework.test import APITestCase


class CustomAPITestCase(APITestCase):
ATTRIBUTES = []

def check_attributes(self, content, attrs=None):
if attrs is None:
attrs = self.ATTRIBUTES

missing_keys = list(set(attrs) - set(content.keys()))
extra_keys = list(set(content.keys()) - set(attrs))
self.assertEqual(
len(missing_keys),
0,
'You miss some attributes: ' + str(missing_keys)
)
self.assertEqual(
len(extra_keys),
0,
'You have some extra attributes: ' + str(extra_keys)
)
41 changes: 34 additions & 7 deletions retirement/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,32 @@
from django.utils.translation import ugettext_lazy as _
from import_export.admin import ExportActionModelAdmin
from modeltranslation.admin import TranslationAdmin
from safedelete.admin import SafeDeleteAdmin, highlight_deleted
from safedelete.admin import (
SafeDeleteAdmin,
highlight_deleted,
)
from simple_history.admin import SimpleHistoryAdmin

from blitz_api.admin import UserFilter
from store.admin import CouponFilter
from .models import (Picture, Reservation, Retreat, WaitQueue,
RetreatInvitation, WaitQueuePlace, WaitQueuePlaceReserved)
from .resources import (ReservationResource, RetreatResource,
WaitQueueResource)
from .models import (
Picture,
Reservation,
Retreat,
WaitQueue,
RetreatInvitation,
WaitQueuePlace,
WaitQueuePlaceReserved,
RetreatType,
AutomaticEmail,
AutomaticEmailLog,
RetreatDate,
)
from .resources import (
ReservationResource,
RetreatResource,
WaitQueueResource
)


class RetreatFilter(AutocompleteFilter):
Expand Down Expand Up @@ -74,8 +91,6 @@ class RetreatAdmin(SimpleHistoryAdmin,
list_filter = (
'name',
'seats',
'start_time',
'end_time',
'price',
) + SafeDeleteAdmin.list_filter

Expand Down Expand Up @@ -247,7 +262,19 @@ class Media:
pass


class RetreatDateAdmin(admin.ModelAdmin):
list_display = (
'retreat',
'start_time',
'end_time',
)


admin.site.register(Retreat, RetreatAdmin)
admin.site.register(RetreatType)
admin.site.register(RetreatDate, RetreatDateAdmin)
admin.site.register(AutomaticEmail)
admin.site.register(AutomaticEmailLog)
admin.site.register(Picture, PictureAdmin)
admin.site.register(Reservation, ReservationAdmin)
admin.site.register(WaitQueue, WaitQueueAdmin)
Expand Down
88 changes: 88 additions & 0 deletions retirement/migrations/0029_auto_20200720_1127.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Generated by Django 2.2.12 on 2020-07-20 15:27

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


class Migration(migrations.Migration):

dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('retirement', '0028_auto_20200601_1613'),
]

operations = [
migrations.CreateModel(
name='RetreatType',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=253, verbose_name='Name')),
(
'name_en',
models.CharField(
max_length=253,
null=True,
verbose_name='Name',
)
),
(
'name_fr',
models.CharField(
max_length=253,
null=True,
verbose_name='Name',
)
),
('minutes_before_display_link', models.IntegerField(verbose_name='Minute before displaying the link')),
],
options={
'verbose_name': 'Type of retreat',
'verbose_name_plural': 'Types of retreat',
},
),
migrations.AddField(
model_name='historicalretreat',
name='type_new',
field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='retirement.RetreatType'),
),
migrations.AddField(
model_name='retreat',
name='type_new',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='retirement.RetreatType'),
),
migrations.CreateModel(
name='HistoricalRetreatType',
fields=[
('id', models.IntegerField(auto_created=True, blank=True,
db_index=True, verbose_name='ID')),
(
'name', models.CharField(max_length=253, verbose_name='Name')),
('name_fr', models.CharField(max_length=253, null=True,
verbose_name='Name')),
('name_en', models.CharField(max_length=253, null=True,
verbose_name='Name')),
('minutes_before_display_link', models.IntegerField(
verbose_name='Minute before displaying the link')),
('history_id',
models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField()),
('history_change_reason',
models.CharField(max_length=100, null=True)),
('history_type', models.CharField(
choices=[('+', 'Created'), ('~', 'Changed'),
('-', 'Deleted')], max_length=1)),
('history_user', models.ForeignKey(null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name='+',
to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'historical Type of retreat',
'ordering': ('-history_date', '-history_id'),
'get_latest_by': 'history_date',
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
]
41 changes: 41 additions & 0 deletions retirement/migrations/0030_migration_of_retreat_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 2.2.12 on 2020-07-20 15:17

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


def migrate_type_of_retreat(apps, schema_editor):
Retreat = apps.get_model('retirement', 'Retreat')
RetreatType = apps.get_model('retirement', 'RetreatType')

physical, created = RetreatType.objects.get_or_create(
name_fr='Physique',
name_en='Physical',
minutes_before_display_link=0
)

virtual, created = RetreatType.objects.get_or_create(
name_fr='Virtuelle',
name_en='Virtual',
minutes_before_display_link=30
)

for retreat in Retreat.objects.all():
if retreat.type == 'V':
retreat.type_new = virtual
else:
retreat.type_new = physical

retreat.save()


class Migration(migrations.Migration):

dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('retirement', '0029_auto_20200720_1127'),
]

operations = [
migrations.RunPython(migrate_type_of_retreat),
]
21 changes: 21 additions & 0 deletions retirement/migrations/0031_auto_20200720_1135.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 2.2.12 on 2020-07-20 15:35

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('retirement', '0030_migration_of_retreat_type'),
]

operations = [
migrations.RemoveField(
model_name='historicalretreat',
name='type',
),
migrations.RemoveField(
model_name='retreat',
name='type',
),
]
24 changes: 24 additions & 0 deletions retirement/migrations/0032_auto_20200720_1159.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 2.2.12 on 2020-07-20 15:59

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


class Migration(migrations.Migration):

dependencies = [
('retirement', '0031_auto_20200720_1135'),
]

operations = [
migrations.RenameField(
model_name='historicalretreat',
old_name='type_new',
new_name='type',
),
migrations.RenameField(
model_name='retreat',
old_name='type_new',
new_name='type',
),
]
19 changes: 19 additions & 0 deletions retirement/migrations/0033_auto_20200720_1202.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.12 on 2020-07-20 16:02

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


class Migration(migrations.Migration):

dependencies = [
('retirement', '0032_auto_20200720_1159'),
]

operations = [
migrations.AlterField(
model_name='retreat',
name='type',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='retreats', to='retirement.RetreatType'),
),
]
14 changes: 14 additions & 0 deletions retirement/migrations/0034_auto_20200720_1339.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 2.2.12 on 2020-07-20 17:39

from django.conf import settings
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('retirement', '0033_auto_20200720_1202'),
]

operations = []
Loading

0 comments on commit 82a263e

Please sign in to comment.