Skip to content

Commit

Permalink
Merge pull request #20 from andela/ft-configure-periodic-reports-1507…
Browse files Browse the repository at this point in the history
…98566

#150798566 configure periodic reports
  • Loading branch information
Judith Achieng committed Sep 18, 2017
2 parents 2aebdbf + b6141cf commit 9e405ac
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 5 deletions.
2 changes: 2 additions & 0 deletions hc/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class EmailPasswordForm(forms.Form):

class ReportSettingsForm(forms.Form):
reports_allowed = forms.BooleanField(required=False)
reports_allowed_weekly = forms.BooleanField(required=False)
reports_allowed_daily = forms.BooleanField(required=False)


class SetPasswordForm(forms.Form):
Expand Down
25 changes: 25 additions & 0 deletions hc/accounts/migrations/0007_auto_20170914_0652.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2017-09-14 06:52
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0006_profile_current_team'),
]

operations = [
migrations.AddField(
model_name='profile',
name='reports_allowed_daily',
field=models.BooleanField(default=True),
),
migrations.AddField(
model_name='profile',
name='reports_allowed_weekly',
field=models.BooleanField(default=False),
),
]
15 changes: 14 additions & 1 deletion hc/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django.urls import reverse
from django.utils import timezone
from hc.lib import emails
import arrow


class Profile(models.Model):
Expand All @@ -20,6 +21,8 @@ class Profile(models.Model):
team_access_allowed = models.BooleanField(default=False)
next_report_date = models.DateTimeField(null=True, blank=True)
reports_allowed = models.BooleanField(default=True)
reports_allowed_weekly = models.BooleanField(default=False)
reports_allowed_daily = models.BooleanField(default=False)
ping_log_limit = models.IntegerField(default=100)
token = models.CharField(max_length=128, blank=True)
api_key = models.CharField(max_length=128, blank=True)
Expand Down Expand Up @@ -52,11 +55,21 @@ def send_set_password_link(self):
def set_api_key(self):
self.api_key = base64.urlsafe_b64encode(os.urandom(24))
self.save()

def determine_next_report(self):
if self.reports_allowed_daily:
return 1
elif self.reports_allowed_weekly:
return 7
else:
return 30

def send_report(self):
# reset next report date first:
now = timezone.now()
self.next_report_date = now + timedelta(days=30)
# self.next_report_date = now + timedelta(days=30)
arrow
self.next_report_date = now + timedelta(days=self.determine_next_report())
self.save()

token = signing.Signer().sign(uuid.uuid4())
Expand Down
4 changes: 4 additions & 0 deletions hc/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ def profile(request):
form = ReportSettingsForm(request.POST)
if form.is_valid():
profile.reports_allowed = form.cleaned_data["reports_allowed"]
profile.reports_allowed_weekly = form.cleaned_data["reports_allowed_weekly"]
profile.reports_allowed_daily = form.cleaned_data["reports_allowed_daily"]
profile.save()
messages.success(request, "Your settings have been updated!")
elif "invite_team_member" in request.POST:
Expand Down Expand Up @@ -254,6 +256,8 @@ def unsubscribe_reports(request, username):

user = User.objects.get(username=username)
user.profile.reports_allowed = False
user.profile.reports_allowed_weekly = False
user.profile.reports_allowed_daily = False
user.profile.save()

return render(request, "accounts/unsubscribed.html")
Expand Down
4 changes: 3 additions & 1 deletion hc/api/management/commands/sendalerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def handle_one(self, check):
check.status = check.get_status()
check.often = False
check.save()

if check.get_status == "down":
for i in range(1, 10):
errors = check.send_alert()
tmpl = "\nSending alert, status=%s, code=%s\n"
self.stdout.write(tmpl % (check.status, check.code))
errors = check.send_alert()
Expand Down
2 changes: 1 addition & 1 deletion hc/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
)
#COMPRESS_ENABLED = True
COMPRESS_OFFLINE = True

EMAIL_BACKEND = "sgbackend.SendGridBackend"
Expand All @@ -167,7 +168,6 @@

ALLOWED_HOSTS = ['*']


if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
from .local_settings import *
else:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ coveralls==1.2.0
pylint==1.7.2
python-http-client==3.0.0
wrapt==1.10.11

arrow
16 changes: 15 additions & 1 deletion templates/accounts/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,28 @@ <h1 class="settings-title">Settings</h1>
<div class="panel-body settings-block">
<form method="post">
{% csrf_token %}
<h2>Monthly Reports</h2>
<h2>Set Periodic Reports</h2>
<label>
<input
name="reports_allowed"
type="checkbox"
{% if profile.reports_allowed %} checked {% endif %}>
Each month send me a summary of my checks
</label>
<label>
<input
name="reports_allowed_weekly"
type="checkbox"
{% if profile.reports_allowed_weekly %} checked {% endif %}>
Each week send me a summary of my checks
</label>
<label>
<input
name="reports_allowed_daily"
type="checkbox"
{% if profile.reports_allowed_daily %} checked {% endif %}>
Each Day send me a summary of my checks
</label>
<button
name="update_reports_allowed"
type="submit"
Expand Down

0 comments on commit 9e405ac

Please sign in to comment.