Skip to content

Commit

Permalink
Merge 4cb401e into ec2ae19
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed Sep 22, 2017
2 parents ec2ae19 + 4cb401e commit 7dad288
Show file tree
Hide file tree
Showing 17 changed files with 2,108 additions and 171 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
static/*
elcid/opal.sqlite*
elcid/local_settings.py
etc/gunicorn.conf
.coverage
htmlcov
libpeerconnection.log
Expand Down
14 changes: 14 additions & 0 deletions elcid/management/commands/error_emailer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
A management command that takes in a string and sends it as an error.
"""
import logging
from django.core.management.base import BaseCommand


class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('error', type=str)

def handle(self, error, *args, **options):
logger = logging.getLogger('error_emailer')
logger.error(error)
2 changes: 1 addition & 1 deletion elcid/management/commands/randomise_admission_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import random

from django.core.management.base import BaseCommand
from django.conf import settings

from opal.models import Episode


class Command(BaseCommand):

def handle(self, *args, **options):
Expand Down
39 changes: 39 additions & 0 deletions elcid/management/commands/status_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

"""
"""
import datetime
import json
import logging

from django.core.management.base import BaseCommand
from opal.core import subrecords
from opal import models


class Command(BaseCommand):

def count_created_last_week(self, model):
last_week = datetime.datetime.now() - datetime.timedelta(7)
return model.objects.filter(created__gte=last_week).count()

def handle(self, *args, **options):
# we want to catch the output, so lets not output info level logging
root_logger = logging.getLogger('')
root_logger.setLevel(logging.ERROR)
result = dict(
all_time=dict(
Episode=models.Episode.objects.count()
),
last_week=dict(
Episode=self.count_created_last_week(models.Episode)
)
)

for subrecord in subrecords.subrecords():
count_all_time = subrecord.objects.count()
count_last_week = self.count_created_last_week(subrecord)

result["all_time"][subrecord.get_display_name()] = count_all_time
result["last_week"][subrecord.get_display_name()] = count_last_week
self.stdout.write(json.dumps(result, indent=4))
18 changes: 17 additions & 1 deletion elcid/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,19 @@
'filters': ['require_debug_false'],
'class': 'opal.core.log.ConfidentialEmailer'
},
'standard_error_emailer': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler',
'include_html': True
}
},
'loggers': {
'django.request': {
'handlers': ['console', 'mail_admins'],
'level': 'ERROR',
'propagate': True,
},
'django.request': {
'handlers': ['console', 'mail_admins'],
'level': 'ERROR',
Expand All @@ -227,7 +238,12 @@
'handlers': ['console'],
'level': 'INFO',
'propagate': True,
}
},
'error_emailer': {
'handlers': ['standard_error_emailer'],
'level': 'ERROR',
'propagate': True,
},
}
}

Expand Down
19 changes: 19 additions & 0 deletions elcid/test/test_error_emailer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from opal.core.test import OpalTestCase
from elcid.management.commands import error_emailer
import mock


class ErrorEmailerTestCase(OpalTestCase):

@mock.patch('elcid.management.commands.error_emailer.logging')
def test_error_emailer(self, logging):
command = error_emailer.Command()
command.handle("Some error")
logging.getLogger.assert_called_once_with("error_emailer")
logging.getLogger().error.assert_called_once_with("Some error")

def test_add_arguments(self):
command = error_emailer.Command()
parser = mock.MagicMock()
command.add_arguments(parser)
parser.add_argument.assert_called_once_with("error", type=str)
Loading

0 comments on commit 7dad288

Please sign in to comment.