Skip to content
Snippets Groups Projects
Commit 5e377687 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

document generation is allowed from voucher edit page

parent ee86c08d
No related branches found
No related tags found
2 merge requests!138list of vouchers with possibility to filter and sort,!137document generation for vouchers
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-06-04 10:21
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('web', '0111_auto_20180601_1318'),
]
operations = [
migrations.AlterField(
model_name='mailtemplate',
name='context',
field=models.CharField(choices=[(b'A', b'Appointment'), (b'S', b'Subject'), (b'V', b'Visit'), (b'C', b'Voucher')], max_length=1),
),
migrations.AlterField(
model_name='mailtemplate',
name='language',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='web.Language'),
),
]
......@@ -144,11 +144,16 @@ class MailTemplate(models.Model):
active_templates = []
disabled_templates = []
for template in templates:
if template.language.name in languages_names:
if template.language is None:
if len(languages) == 0:
active_templates.append(template)
else:
disabled_templates.append(template)
elif template.language.name in languages_names:
active_templates.append(template)
else:
disabled_templates.append(template)
active_templates.sort(key=lambda x: languages_names.index(x.language.name))
active_templates.sort(key=lambda x: languages_names.index(x.language.name) if x.language is not None else -1)
return active_templates, disabled_templates
def apply(self, instance, user, stream):
......
......@@ -90,6 +90,8 @@
</table>
</div>
{% include 'includes/mail_templates_box.html' with instance_id=voucher.id %}
{% endif %}
</div>
</div>
......
......@@ -115,6 +115,28 @@ class MailTemplateModelTests(TestCase):
voucher.issue_date.strftime(DATE_FORMAT_SHORT)
])
def test_get_mail_templates_for_context_without_language(self):
template_name_french = "test_without_language"
MailTemplate(name=template_name_french, language=None,
context=MAIL_TEMPLATE_CONTEXT_VOUCHER,
template_file="voucher_test.docx").save()
templates = MailTemplate.get_mail_templates_for_context([], context=MAIL_TEMPLATE_CONTEXT_VOUCHER)
self.assertEquals(1, len(templates[0]))
templates = MailTemplate.get_mail_templates_for_context([self.english_language],
context=MAIL_TEMPLATE_CONTEXT_VOUCHER)
self.assertEquals(0, len(templates[0]))
def test_get_mail_templates_for_context_without_language_2(self):
template_name_french = "test_without_language"
MailTemplate(name=template_name_french, language=self.english_language,
context=MAIL_TEMPLATE_CONTEXT_VOUCHER,
template_file="voucher_test.docx").save()
templates = MailTemplate.get_mail_templates_for_context([], context=MAIL_TEMPLATE_CONTEXT_VOUCHER)
self.assertEquals(0, len(templates[0]))
def test_apply_visit(self):
template_name_french = "test_fr"
visit = create_visit()
......
......@@ -49,6 +49,11 @@ class MailTemplatesCreateView(CreateView, WrappedView):
success_url = reverse_lazy('web.views.mail_templates')
success_message = "Template created"
def get_form(self, form_class=None):
form = super(MailTemplatesCreateView, self).get_form(form_class)
form.fields['language'].required = False
return form
class MailTemplatesDeleteView(DeleteView, WrappedView):
model = MailTemplate
......
......@@ -10,7 +10,7 @@ from django_cron import CronJobBase, Schedule
from web.views.notifications import get_today_midnight_date
from web.forms import VoucherForm
from web.models import Voucher, StudySubject
from web.models import Voucher, StudySubject, MailTemplate
from web.models.constants import GLOBAL_STUDY_ID, VOUCHER_STATUS_NEW, VOUCHER_STATUS_EXPIRED
from . import WrappedView
......@@ -67,6 +67,12 @@ class VoucherEditView(SuccessMessageMixin, UpdateView, WrappedView):
def get_study_subject_id(self):
return Voucher.objects.get(id=self.kwargs['pk']).study_subject.id
def get_context_data(self, *args, **kwargs):
context = super(VoucherEditView, self).get_context_data(*args, **kwargs)
context['mail_templates']= MailTemplate.get_voucher_mail_templates([])
print context
return context
class ExpireVouchersJob(CronJobBase):
RUN_EVERY_MINUTES = 120
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment