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)
    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)
        reps_without_report = reps.exclude(reports__month__year=date.year,
                                           reports__month__month=date.month)

        data = {'year': date.year, 'month': number2month(date.month)}

        send_remo_mail(reps_without_report, self.SUBJECT,
                       self.EMAIL_TEMPLATE, data)
Ejemplo n.º 3
0
def dashboard(request):
    """Dashboard view."""
    user = request.user
    budget_requests = Bug.objects.filter(component='Budget Requests')
    budget_requests = budget_requests.exclude(status='RESOLVED')
    swag_requests = Bug.objects.filter(component='Swag Requests')
    swag_requests = swag_requests.exclude(status='RESOLVED')
    mentorship_requests = Bug.objects.filter(component='Mentorship')
    mentorship_requests = mentorship_requests.exclude(status='RESOLVED')
    cit_requests = Bug.objects.filter(component='Community IT Requests')
    cit_requests = cit_requests.exclude(status='RESOLVED')
    planning_requests = Bug.objects.filter(component='Planning')
    planning_requests = planning_requests.exclude(status='RESOLVED')

    today = date.today()
    previous_month = go_back_n_months(today)
    monthly_reports = get_reports_for_year(user, start_year=2011,
                                           end_year=today.year,
                                           private=False)

    my_q = (Q(cc=user) | Q(creator=user))
    my_q_assigned = (my_q | Q(assigned_to=user))
    my_mentees = User.objects.filter(userprofile__mentor=user)

    my_budget_requests = budget_requests.filter(my_q)
    my_swag_requests = swag_requests.filter(my_q)

    if user.groups.filter(name='Mentor').exists():
        mentees_budget_requests = budget_requests.filter(creator__in=my_mentees)
        mentees_swag_requests = swag_requests.filter(creator__in=my_mentees)
        my_mentorship_requests = mentorship_requests.filter(my_q)
        my_mentorship_requests = my_mentorship_requests.order_by('whiteboard')
        mentees_reports_list = (Report.objects.filter(mentor=user).
                                order_by('-created_on')[:20])
        mentees_reports_grid = Report.objects.filter(
            mentor=user, month__month=previous_month.month,
            month__year=previous_month.year).order_by('user__last_name',
                                                      'user__first_name')
    else:
        mentees_budget_requests = None
        mentees_swag_requests = None
        my_mentorship_requests = None
        mentees_reports_list = None
        mentees_reports_grid = None

    if user.groups.filter(Q(name='Admin') | Q(name='Council')).exists():
        all_budget_requests = budget_requests.all()[:20]
        all_swag_requests = swag_requests.all()[:20]
        my_cit_requests = cit_requests
        my_planning_requests = planning_requests
        all_reports = Report.objects.all().order_by('-created_on')[:20]
    else:
        all_budget_requests = None
        all_swag_requests = None
        my_cit_requests = None
        my_planning_requests = planning_requests.filter(my_q_assigned)
        all_reports = None

    if user.groups.filter(name='Admin').exists():
        reps = User.objects.filter(groups__name="Rep")
        reps_without_mentors = reps.filter(
            userprofile__registration_complete=True, userprofile__mentor=None)
        reps_without_profile = reps.filter(
            userprofile__registration_complete=False)
    else:
        reps_without_mentors = None
        reps_without_profile = None

    return render(request, 'dashboard.html',
                  {'my_budget_requests': my_budget_requests,
                   'mentees_budget_requests': mentees_budget_requests,
                   'all_budget_requests': all_budget_requests,
                   'my_swag_requests': my_swag_requests,
                   'mentees_swag_requests': mentees_swag_requests,
                   'all_swag_requests': all_swag_requests,
                   'my_cit_requests': my_cit_requests,
                   'my_mentorship_requests': my_mentorship_requests,
                   'my_planning_requests': my_planning_requests,
                   'reps_without_profile': reps_without_profile,
                   'reps_without_mentors': reps_without_mentors,
                   'monthly_reports': monthly_reports,
                   'mentees_reports_list': mentees_reports_list,
                   'mentees_reports_grid': mentees_reports_grid,
                   'all_reports': all_reports})