Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
[fix bug 973856] Update current streak counter every day.
Browse files Browse the repository at this point in the history
  • Loading branch information
akatsoulas committed Mar 4, 2014
1 parent 433aaf8 commit f522c7b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
17 changes: 17 additions & 0 deletions remo/reports/tasks.py
Expand Up @@ -8,6 +8,7 @@

from celery.task import periodic_task, task

from remo.base.utils import get_date
from remo.reports import ACTIVITY_EVENT_ATTEND, ACTIVITY_EVENT_CREATE


Expand Down Expand Up @@ -97,3 +98,19 @@ def send_ng_report_notification():
up.last_report_notification = today
send_mail(subject, message, settings.FROM_EMAIL, [rep.email])
up.save()


@task()

This comment has been minimized.

Copy link
@glogiotatidis

glogiotatidis Mar 7, 2014

Contributor

Is there a reason you don't set a periodic task here?

def zero_current_streak():
"""Zero current streak.
Zero current streak for users without a report in the last week.
"""

reps = User.objects.filter(
~Q(ng_reports__report_date__range=[get_date(-7), get_date()]),
groups__name='Rep')

for rep in reps:
rep.userprofile.current_streak_start = None
rep.userprofile.save()
19 changes: 18 additions & 1 deletion remo/reports/tests/test_tasks.py
@@ -1,16 +1,19 @@
from datetime import date, datetime, timedelta

from django.conf import settings
from django.contrib.auth.models import User

from mock import ANY as mockany, patch
from nose.tools import ok_

from remo.base.tests import RemoTestCase
from remo.base.utils import get_date
from remo.events.tests import EventFactory
from remo.profiles.tests import UserFactory
from remo.reports import ACTIVITY_EVENT_ATTEND
from remo.reports.models import Activity, NGReport
from remo.reports.tasks import send_ng_report_notification, send_report_digest
from remo.reports.tasks import (send_ng_report_notification,
send_report_digest, zero_current_streak)
from remo.reports.tests import NGReportFactory


Expand Down Expand Up @@ -108,3 +111,17 @@ def test_with_no_report_filled_and_one_notification(self):
with patch('remo.reports.tasks.send_mail') as send_mail_mock:
send_ng_report_notification()
ok_(not send_mail_mock.called)


class UpdateCurrentStreakCountersTest(RemoTestCase):
def test_base(self):
past_day = get_date(-8)
user = UserFactory.create(groups=['Rep'])
NGReportFactory.create(user=user, report_date=past_day)
user.userprofile.current_streak_start = past_day
user.userprofile.save()

zero_current_streak()
user = User.objects.get(pk=user.id)

ok_(not user.userprofile.current_streak_start)

0 comments on commit f522c7b

Please sign in to comment.