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

setting DAILY_SUBJECT_IMPORT_FILE changed into configuration option

parent 100880a0
No related branches found
No related tags found
1 merge request!271Resolve "clean configuration"
......@@ -10,7 +10,7 @@ from django.conf import settings
from django_cron import CronJobBase, Schedule
from web.models import ConfigurationItem
from web.models.constants import CRON_JOB_TIMEOUT, DEFAULT_FROM_EMAIL
from web.models.constants import CRON_JOB_TIMEOUT, DEFAULT_FROM_EMAIL, DAILY_SUBJECT_IMPORT_FILE
from web.smash_email import EmailSender
from .csv_tns_subject_import_reader import TnsCsvSubjectImportReader
from .csv_tns_visit_import_reader import TnsCsvVisitImportReader
......@@ -29,9 +29,9 @@ class SubjectImporterCronJob(CronJobBase):
email_title = "Subjects daily import"
email_recipients = ConfigurationItem.objects.get(type=DEFAULT_FROM_EMAIL).value
filename = getattr(settings, "DAILY_SUBJECT_IMPORT_FILE", None)
filename = ConfigurationItem.objects.get(type=DAILY_SUBJECT_IMPORT_FILE).value
if filename is None:
if filename is None or filename == '':
logger.info("Importing subjects skipped. File not defined ")
return "import file not defined"
logger.info("Importing subjects from file: " + filename)
......@@ -41,7 +41,7 @@ class SubjectImporterCronJob(CronJobBase):
email_recipients)
return "import file not found"
try:
importer = Importer(settings.DAILY_SUBJECT_IMPORT_FILE, TnsCsvSubjectImportReader())
importer = Importer(filename, TnsCsvSubjectImportReader())
importer.execute()
email_body = importer.get_summary()
EmailSender().send_email(email_title,
......
......@@ -2,7 +2,7 @@
from django.conf import settings
from django.db import migrations
from web.models.constants import DEFAULT_FROM_EMAIL
from web.models.constants import DEFAULT_FROM_EMAIL, DAILY_SUBJECT_IMPORT_FILE
def create_item(apps, item_type, value, name):
......@@ -21,10 +21,12 @@ def create_item(apps, item_type, value, name):
# noinspection PyUnusedLocal
def configuration_items(apps, schema_editor):
email_from = getattr(settings, "DEFAULT_FROM_EMAIL", '')
create_item(apps, DEFAULT_FROM_EMAIL, email_from,
"Default email address used in the from field when sending emails")
subject_import_file = getattr(settings, "DAILY_SUBJECT_IMPORT_FILE", '')
create_item(apps, DAILY_SUBJECT_IMPORT_FILE, subject_import_file, "File used to import subjects automatically")
class Migration(migrations.Migration):
dependencies = [
......
......@@ -57,6 +57,7 @@ KIT_DAILY_EMAIL_DAYS_PERIOD_TYPE = "KIT_DAILY_EMAIL_DAYS_PERIOD_TYPE"
KIT_DAILY_EMAIL_TIME_FORMAT_TYPE = "KIT_DAILY_EMAIL_TIME_FORMAT_TYPE"
VIRUS_EMAIL_HOUR_CONFIGURATION_TYPE = "VIRUS_EMAIL_HOUR_CONFIGURATION_TYPE"
DEFAULT_FROM_EMAIL = "DEFAULT_FROM_EMAIL"
DAILY_SUBJECT_IMPORT_FILE = "DAILY_SUBJECT_IMPORT_FILE"
RED_CAP_LANGUAGE_4_FIELD_TYPE = 'RED_CAP_LANGUAGE_4_FIELD_TYPE'
RED_CAP_LANGUAGE_3_FIELD_TYPE = 'RED_CAP_LANGUAGE_3_FIELD_TYPE'
......
......@@ -4,22 +4,20 @@ import logging
import tempfile
from shutil import copyfile
from django.conf import settings
from django.core import mail
from django.test import TestCase
from django_cron.models import CronJobLog
from web.importer import SubjectImporterCronJob
from web.models import ConfigurationItem
from web.models.constants import DAILY_SUBJECT_IMPORT_FILE
from web.tests.functions import get_resource_path
logger = logging.getLogger(__name__)
from django.core import mail
from django_cron.models import CronJobLog
class TestCronJobImporter(TestCase):
def tearDown(self):
setattr(settings, "DAILY_SUBJECT_IMPORT_FILE", None)
def test_import_without_configuration(self):
CronJobLog.objects.all().delete()
......@@ -35,7 +33,9 @@ class TestCronJobImporter(TestCase):
new_file, tmp = tempfile.mkstemp()
copyfile(filename, tmp)
setattr(settings, "DAILY_SUBJECT_IMPORT_FILE", tmp)
conf = ConfigurationItem.objects.get(type=DAILY_SUBJECT_IMPORT_FILE)
conf.value = tmp
conf.save()
CronJobLog.objects.all().delete()
job = SubjectImporterCronJob()
......
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