コード例 #1
0
ファイル: utils.py プロジェクト: prameet-jain/remo
def get_mentee_reports_for_month(user, dateobj=None):
    """Return a dictionary with Mentee reports for month in dateobj.

    If dateobj==None return the reports of the previous month.

    """
    if not dateobj:
        one_month_before = go_back_n_months(date.today(), first_day=True)
    else:
        one_month_before = dateobj
    two_months_before = go_back_n_months(one_month_before, first_day=True)

    mentees = get_mentees(user)
    mentees_list = {'month': one_month_before.strftime("%B %Y"), 'reports': []}

    for mentee in mentees:
        month_first_report = get_month_first_report(mentee)
        current_report = get_object_or_none(Report, user=mentee,
                                            month=one_month_before)
        previous_report = get_object_or_none(Report, user=mentee,
                                             month=two_months_before)
        if not previous_report and two_months_before >= month_first_report:
            status = 'notfilled'
        elif current_report and current_report.empty:
            status = 'empty'
        else:
            status = ''

        mentees_list['reports'].append({'user': mentee, 'status': status,
                                        'report': current_report})

    return mentees_list
コード例 #2
0
ファイル: utils.py プロジェクト: craigcook/remo
def get_mentee_reports_for_month(user, dateobj=None):
    """Return a dictionary with Mentee reports for month in dateobj.

    If dateobj==None return the reports of the previous month.

    """
    if not dateobj:
        one_month_before = go_back_n_months(date.today(), first_day=True)
    else:
        one_month_before = dateobj
    two_months_before = go_back_n_months(one_month_before, first_day=True)

    mentees = get_mentees(user)
    mentees_list = {'month': one_month_before.strftime("%B %Y"), 'reports': []}

    for mentee in mentees:
        month_first_report = get_month_first_report(mentee)
        current_report = get_object_or_none(Report, user=mentee,
                                            month=one_month_before)
        previous_report = get_object_or_none(Report, user=mentee,
                                             month=two_months_before)
        if not previous_report and two_months_before >= month_first_report:
            status = 'notfilled'
        elif current_report and current_report.empty:
            status = 'empty'
        else:
            status = ''

        mentees_list['reports'].append({'user': mentee, 'status': status,
                                        'report': current_report})

    return mentees_list
コード例 #3
0
    def handle(self, *args, **options):
        """Prepares a list of reps to be notified and the required
        template variables.

        """
        date = go_back_n_months(datetime.today(), 1)
        rep_group = Group.objects.get(name='Rep')
        reps = (rep_group.user_set
                .exclude(userprofile__registration_complete=False)
                .exclude(reports__month__year=date.year,
                         reports__month__month=date.month))
        reps_without_report = reps.values_list('id', flat=True)

        month = number2month(date.month)
        subject = self.SUBJECT % month
        data = {'year': date.year, 'month': month}

        if options['dry_run']:
            email_reps = reps.values_list('email', flat=True)
            for recipient in email_reps:
                msg = 'Second notification sent to %s' % recipient
                print(msg)
        else:
            send_remo_mail(reps_without_report, subject,
                           self.EMAIL_TEMPLATE, data)
コード例 #4
0
ファイル: utils.py プロジェクト: bensternthal/remo
def get_mentee_reports_for_month(user, dateobj=None):
    """Return a dictionary with Mentee reports for month in dateobj.

    If dateobj==None return the reports of the previous month.

    """
    if not dateobj:
        dateobj = go_back_n_months(date.today(), first_day=True)

    mentees = get_mentees(user)
    mentees_list = {'month': dateobj.strftime("%B %Y"), 'reports': []}

    for mentee in mentees:
        report = get_object_or_none(Report, user=mentee, month=dateobj)
        if report is None:
            status = 'notfilled'
        elif report.overdue:
            status = 'overdue'
        else:
            status = ''

        mentees_list['reports'].append({'user': mentee, 'status': status,
                                        'report': report})

    return mentees_list
コード例 #5
0
    def handle(self, *args, **options):
        """Prepares a list of reps to be notified and the required
        template variables.

        """
        rep_group = Group.objects.get(name='Rep')
        reps = rep_group.user_set.exclude(
            userprofile__registration_complete=False)
        date = go_back_n_months(datetime.today(), 2)

        reps_without_report = reps.exclude(reports__month__year=date.year,
                                           reports__month__month=date.month)

        mentors = [rep.userprofile.mentor.id for rep in reps_without_report]

        month = number2month(date.month)
        subject = self.SUBJECT % month
        data = {'year': date.year, 'month': month,
                'reps_without_report': reps_without_report}

        if options['dry_run']:
            for mentor in mentors:
                msg = 'Email sent to mentor: %d' % mentor
                print(msg)
        else:
            send_remo_mail(mentors, subject, self.EMAIL_TEMPLATE, data)
コード例 #6
0
    def handle(self, *args, **options):
        """Prepares a list of reps to be notified and the required
        template variables.

        """
        date = go_back_n_months(datetime.today(), 2)
        rep_group = Group.objects.get(name='Rep')
        reps = (rep_group.user_set
                .exclude(userprofile__registration_complete=False)
                .exclude(reports__month__year=date.year,
                         reports__month__month=date.month))
        reps_without_report = reps.values_list('id', flat=True)

        month = number2month(date.month)
        subject = self.SUBJECT % month
        data = {'year': date.year, 'month': month}

        if options['dry_run']:
            email_reps = reps.values_list('email', flat=True)
            for recipient in email_reps:
                msg = 'Third notification sent to %s' % recipient
                print(msg)
        else:
            send_remo_mail(reps_without_report, subject,
                           self.EMAIL_TEMPLATE, data)
コード例 #7
0
ファイル: models.py プロジェクト: rbillings/remo
def report_set_overdue_pre_save(sender, instance, raw, **kwargs):
    """Set overdue on Report object creation."""
    today = datetime.date.today()
    previous_month = go_back_n_months(today, first_day=True)

    if not instance.id and not raw:
        if previous_month > instance.month or (previous_month == instance.month and today.day > OVERDUE_DAY):
            instance.overdue = True
コード例 #8
0
ファイル: models.py プロジェクト: giallu/remo
def report_set_overdue_pre_save(sender, instance, raw, **kwargs):
    """Set overdue on Report object creation."""
    today = datetime.date.today()
    previous_month = go_back_n_months(today, first_day=True)

    if not instance.id and not raw:
        if (previous_month > instance.month or
            (previous_month == instance.month and today.day > OVERDUE_DAY)):
            instance.overdue = True
コード例 #9
0
ファイル: test_models.py プロジェクト: AshishNamdev/remo
    def test_overdue_true_2(self, fake_requests_obj):
        """Test overdue report (second test)."""
        today = datetime.datetime.today()

        # act like it's OVERDUE_DAY + 1
        fake_date = datetime.datetime(year=today.year, month=today.month,
                                      day=OVERDUE_DAY+1)
        (fake_requests_obj.expects_call().returns(fake_date))

        month_year = go_back_n_months(today)
        report = Report.objects.create(user=self.user, month=month_year)
        eq_(report.overdue, True)
コード例 #10
0
    def handle(self, *args, **options):
        """Prepares a list of reps to be notified and the required
        template variables.

        """
        rep_group = Group.objects.get(name='Rep')
        reps = rep_group.user_set.exclude(
            userprofile__registration_complete=False)
        date = go_back_n_months(datetime.datetime.today(), 1)
        data = {'year': date.year, 'month': number2month(date.month)}

        send_remo_mail(reps, self.SUBJECT, self.EMAIL_TEMPLATE, data)
コード例 #11
0
ファイル: test_models.py プロジェクト: AshishNamdev/remo
    def test_overdue_false_2(self, fake_requests_obj):
        """Test not overdue report (first test)."""
        # marginal case
        today = datetime.datetime.today()

        # act like it's OVERDUE_DAY
        fake_date = datetime.datetime(year=today.year, month=today.month,
                                      day=OVERDUE_DAY)
        (fake_requests_obj.expects_call().returns(fake_date))

        month_year = go_back_n_months(today)
        report = Report.objects.create(user=self.user, month=month_year)
        eq_(report.overdue, False)
コード例 #12
0
ファイル: test_models.py プロジェクト: hardfire/remo
    def test_overdue_true_2(self, fake_requests_obj):
        """Test overdue report (second test)."""
        today = datetime.datetime.today()

        # act like it's OVERDUE_DAY + 1
        fake_date = datetime.datetime(year=today.year,
                                      month=today.month,
                                      day=OVERDUE_DAY + 1)
        (fake_requests_obj.expects_call().returns(fake_date))

        month_year = go_back_n_months(today)
        report = Report.objects.create(user=self.user, month=month_year)
        eq_(report.overdue, True)
コード例 #13
0
    def handle(self, *args, **options):
        """Prepares a list of reps to be notified and the required
        template variables.

        """
        rep_group = Group.objects.get(name='Rep')
        reps = rep_group.user_set.exclude(
            userprofile__registration_complete=False)
        date = go_back_n_months(datetime.datetime.today(), 1)
        month = number2month(date.month)
        subject = self.SUBJECT % month
        data = {'year': date.year, 'month': month}

        send_remo_mail(reps, subject, self.EMAIL_TEMPLATE, data)
コード例 #14
0
ファイル: test_models.py プロジェクト: hardfire/remo
    def test_overdue_false_2(self, fake_requests_obj):
        """Test not overdue report (first test)."""
        # marginal case
        today = datetime.datetime.today()

        # act like it's OVERDUE_DAY
        fake_date = datetime.datetime(year=today.year,
                                      month=today.month,
                                      day=OVERDUE_DAY)
        (fake_requests_obj.expects_call().returns(fake_date))

        month_year = go_back_n_months(today)
        report = Report.objects.create(user=self.user, month=month_year)
        eq_(report.overdue, False)
コード例 #15
0
ファイル: cron.py プロジェクト: yumsuresht/remo
def new_reps_reminder():
    """Send email to reps-mentors listing new subscribers the past month."""

    prev = go_back_n_months(now().date())
    prev_date = prev.strftime('%B %Y')

    reps = UserProfile.objects
    reps_num = reps.count()
    new_reps = reps.filter(date_joined_program__month=prev.month)
    email_template = 'emails/new_reps_monthly_reminder.txt'
    subject = '[Info] New Reps for %s' % prev_date
    recipient = settings.REPS_MENTORS_LIST
    data = {'reps': new_reps, 'date': prev_date, 'reps_num': reps_num}

    send_generic_mail.delay([recipient], subject, email_template, data)
コード例 #16
0
ファイル: views.py プロジェクト: shollmann/remo
def current_report(request, edit=False):
    display_name = request.user.userprofile.display_name
    previous_month = utils.go_back_n_months(datetime.date.today(),
                                            first_day=True)
    month_name = utils.number2month(previous_month.month)
    report = utils.get_object_or_none(
        Report, user__userprofile__display_name=display_name,
        month=previous_month)

    view = 'reports_view_report'
    if edit or not report:
        view = 'reports_edit_report'

    redirect_url = reverse(view, kwargs={'display_name': display_name,
                                         'year': previous_month.year,
                                         'month': month_name})
    return redirect(redirect_url)
コード例 #17
0
ファイル: views.py プロジェクト: craigcook/remo
def current_report(request, edit=False):
    display_name = request.user.userprofile.display_name
    previous_month = utils.go_back_n_months(datetime.date.today(),
                                            first_day=True)
    month_name = utils.number2month(previous_month.month)
    report = utils.get_object_or_none(
        Report, user__userprofile__display_name=display_name,
        month=previous_month)

    view = 'reports_view_report'
    if edit or not report:
        view = 'reports_edit_report'

    redirect_url = reverse(view, kwargs={'display_name': display_name,
                                         'year': previous_month.year,
                                         'month': month_name})
    return redirect(redirect_url)
コード例 #18
0
    def handle(self, *args, **options):
        """Prepares a list of reps to be notified and the required
        template variables.

        """
        rep_group = Group.objects.get(name='Rep')
        reps = (rep_group.user_set
                .exclude(userprofile__registration_complete=False)
                .values_list('id', flat=True))
        date = go_back_n_months(datetime.datetime.today(), 1)
        reps_without_report = reps.exclude(reports__month__year=date.year,
                                           reports__month__month=date.month)

        month = number2month(date.month)
        subject = self.SUBJECT % month
        data = {'year': date.year, 'month': month}

        send_remo_mail(reps_without_report, subject, self.EMAIL_TEMPLATE, data)
コード例 #19
0
    def handle(self, *args, **options):
        """Prepares a list of reps to be notified and the required
        template variables.

        """
        rep_group = Group.objects.get(name="Rep")
        reps = rep_group.user_set.exclude(userprofile__registration_complete=False)
        date = go_back_n_months(datetime.datetime.today(), 2)

        reps_without_report = reps.exclude(reports__month__year=date.year, reports__month__month=date.month)

        mentors = [rep.userprofile.mentor.id for rep in reps_without_report]

        month = number2month(date.month)
        subject = self.SUBJECT % month
        data = {"year": date.year, "month": month, "reps_without_report": reps_without_report}

        send_remo_mail(mentors, subject, self.EMAIL_TEMPLATE, data)
コード例 #20
0
ファイル: test_views.py プロジェクト: hoosteeno/remo
    def test_view_current_report_page(self):
        """Test view report page."""
        # If anonymous, return an error.
        c = Client()
        response = c.get(reverse('reports_view_current_report'), follow=True)
        self.assertTemplateUsed(response, 'main.html')
        for m in response.context['messages']:
            pass
        eq_(m.tags, u'warning')

        # Login.
        c.login(username='******', password='******')

        # If report does not exist, render edit page.
        response = c.get(reverse('reports_view_current_report'), follow=True)
        self.assertTemplateUsed(response, 'edit_report.html')

        # If report exists, render report.
        ReportFactory.create(user=self.user, empty=True, mentor=self.mentor,
                             month=go_back_n_months(datetime.date.today()))
        response = c.get(reverse('reports_view_current_report'), follow=True)
        self.assertTemplateUsed(response, 'view_report.html')
コード例 #21
0
    def handle(self, *args, **options):
        """Prepares a list of reps to be notified and the required
        template variables.

        """
        rep_group = Group.objects.get(name="Rep")
        reps = rep_group.user_set.exclude(userprofile__registration_complete=False)
        id_reps = reps.values_list("id", flat=True)

        date = go_back_n_months(datetime.datetime.today(), 1)
        month = number2month(date.month)

        subject = self.SUBJECT % month
        data = {"year": date.year, "month": month}

        if options["dry_run"]:
            email_reps = reps.values_list("email", flat=True)
            for recipient in email_reps:
                msg = "First notification sent to %s" % recipient
                print(msg)
        else:
            send_remo_mail(id_reps, subject, self.EMAIL_TEMPLATE, data)
コード例 #22
0
ファイル: test_views.py プロジェクト: shollmann/remo
    def test_view_current_report_page(self):
        """Test view report page."""
        # If anonymous, return an error.
        c = Client()
        response = c.get(reverse('reports_view_current_report'), follow=True)
        self.assertTemplateUsed(response, 'main.html')
        for m in response.context['messages']:
            pass
        eq_(m.tags, u'warning')

        # Login.
        c.login(username='******', password='******')

        # If report does not exist, render edit page.
        response = c.get(reverse('reports_view_current_report'), follow=True)
        self.assertTemplateUsed(response, 'edit_report.html')

        # If report exists, render report.
        Report.objects.create(user=self.user,
                              empty=True,
                              month=go_back_n_months(datetime.date.today()))
        response = c.get(reverse('reports_view_current_report'), follow=True)
        self.assertTemplateUsed(response, 'view_report.html')