Example #1
0
def dashboard_mozillians(request, user):
    args = {}
    user_profile = user.userprofile
    interestform = forms.TrackFunctionalAreasForm(request.POST or None, instance=user_profile)
    reps_email_form = forms.EmailRepsForm(request.POST or None)
    if interestform.is_valid():
        interestform.save()
        messages.success(request, 'Interests successfully saved')
        return redirect('dashboard')
    if reps_email_form.is_valid():
        functional_area = reps_email_form.cleaned_data['functional_area']
        reps = User.objects.filter(groups__name='Rep').filter(
            userprofile__functional_areas=functional_area)
        reps_email_form.send_email(request, reps)
        return redirect('dashboard')

    # Get the reps who match the specified interests
    interests = user.userprofile.tracked_functional_areas.all()
    tracked_interests = {}
    reps_past_events = {}
    reps_current_events = {}
    reps_ng_reports = {}
    today = now().date()
    unavailable_rep_exists = {}

    for interest in interests:
        # Get the Reps with the specified interest
        reps = User.objects.filter(groups__name='Rep').filter(
            userprofile__functional_areas=interest)
        tracked_interests[interest.name] = {
            'id': interest.id,
            'reps': reps
        }

        # Get the reports of the Reps with the specified interest
        ng_reports = NGReport.objects.filter(report_date__lte=today,
                                             functional_areas=interest,
                                             user__in=reps)
        reps_ng_reports[interest.name] = ng_reports.order_by('-report_date')[:20]

        # Get the events with the specified category
        events = Event.objects.filter(categories=interest)
        reps_past_events[interest.name] = events.filter(start__lt=now())[:50]
        reps_current_events[interest.name] = events.filter(start__gte=now())

        # Check if there is an unavailable Rep for the specific interest
        unavailable_val = (UserStatus.objects.filter(is_unavailable=True)
                                             .filter(user__in=reps).exists())
        unavailable_rep_exists[interest.name] = unavailable_val

    args['unavailable_rep_exists'] = unavailable_rep_exists
    args['reps_ng_reports'] = reps_ng_reports
    args['interestform'] = interestform
    args['reps_past_events'] = reps_past_events
    args['reps_current_events'] = reps_current_events
    args['tracked_interests'] = tracked_interests
    args['reps_email_form'] = reps_email_form
    statsd.incr('dashboard.dashboard_mozillians')
    return render(request, 'dashboard_mozillians.jinja', args)
Example #2
0
def dashboard_mozillians(request, user):
    args = {}
    user_profile = user.userprofile
    interestform = forms.TrackFunctionalAreasForm(request.POST or None,
                                                  instance=user_profile)
    reps_email_form = forms.EmailRepsForm(request.POST or None)
    if interestform.is_valid():
        interestform.save()
        messages.success(request, 'Interests successfully saved')
        return redirect('dashboard')
    if reps_email_form.is_valid():
        functional_area = reps_email_form.cleaned_data['functional_area']
        reps = (User.objects.filter(groups__name='Rep').filter(
            userprofile__functional_areas=functional_area))
        reps_email_form.send_email(request, reps)
        return redirect('dashboard')

    # Get the reps who match the specified interests
    interests = user.userprofile.tracked_functional_areas.all()
    tracked_interests = {}
    reps_reports = {}
    reps_past_events = {}
    reps_current_events = {}
    now = datetime.now()
    reps_ng_reports = {}
    today = datetime.utcnow().date()

    for interest in interests:
        # Get the Reps with the specified interest
        reps = User.objects.filter(groups__name='Rep').filter(
            userprofile__functional_areas=interest)
        tracked_interests[interest.name] = {'id': interest.id, 'reps': reps}

        # Continuous reporting section
        ng_reports = NGReport.objects.filter(report_date__lte=today,
                                             functional_areas=interest,
                                             user__in=reps)
        reps_ng_reports[interest.name] = (
            ng_reports.order_by('-report_date')[:10])

        # Get the reports of the Reps with the specified interest
        reps_reports[interest.name] = Report.objects.filter(
            user__in=reps).order_by('created_on')[:20]
        # Get the events with the specified category
        events = Event.objects.filter(categories=interest)
        reps_past_events[interest.name] = events.filter(start__lt=now)[:50]
        reps_current_events[interest.name] = events.filter(start__gte=now)

    if waffle.flag_is_active(request, 'reports_ng_report'):
        args['reps_ng_reports'] = reps_ng_reports

    args['interestform'] = interestform
    args['reps_reports'] = reps_reports
    args['reps_past_events'] = reps_past_events
    args['reps_current_events'] = reps_current_events
    args['tracked_interests'] = tracked_interests
    args['reps_email_form'] = reps_email_form
    return render(request, 'dashboard_mozillians.html', args)
Example #3
0
def dashboard(request):
    """Dashboard view."""
    user = request.user
    args = {}

    # Mozillians block
    if user.groups.filter(name='Mozillians').exists():
        user_profile = user.userprofile
        interestform = forms.TrackFunctionalAreasForm(request.POST or None,
                                                      instance=user_profile)
        reps_email_form = forms.EmailRepsForm(request.POST or None)
        if interestform.is_valid():
            interestform.save()
            messages.success(request, 'Interests successfully saved')
            return redirect('dashboard')
        if reps_email_form.is_valid():
            functional_area = reps_email_form.cleaned_data['functional_area']
            reps = (User.objects.filter(groups__name='Rep').filter(
                userprofile__functional_areas=functional_area))
            reps_email_form.send_email(request, reps)
            return redirect('dashboard')

        # Get the reps who match the specified interests
        interests = user.userprofile.tracked_functional_areas.all()
        tracked_interests = {}
        reps_reports = {}
        reps_past_events = {}
        reps_current_events = {}
        now = datetime.now()
        for interest in interests:
            # Get the Reps with the specified interest
            reps = User.objects.filter(groups__name='Rep').filter(
                userprofile__functional_areas=interest)
            tracked_interests[interest.name] = {
                'id': interest.id,
                'reps': reps
            }
            # Get the reports of the Reps with the specified interest
            reps_reports[interest.name] = Report.objects.filter(
                user__in=reps).order_by('created_on')[:20]
            # Get the events with the specified category
            events = Event.objects.filter(categories=interest)
            reps_past_events[interest.name] = events.filter(start__lt=now)[:50]
            reps_current_events[interest.name] = events.filter(start__gte=now)
        args['interestform'] = interestform
        args['reps_reports'] = reps_reports
        args['reps_past_events'] = reps_past_events
        args['reps_current_events'] = reps_current_events
        args['tracked_interests'] = tracked_interests
        args['reps_email_form'] = reps_email_form
        return render(request, 'dashboard_mozillians.html', args)

    # Reps block
    q_closed = Q(status='RESOLVED') | Q(status='VERIFIED')
    budget_requests = (Bug.objects.filter(
        component='Budget Requests').exclude(q_closed))
    swag_requests = (Bug.objects.filter(
        component='Swag Requests').exclude(q_closed))
    mentorship_requests = (Bug.objects.filter(
        component='Mentorship').exclude(q_closed))
    cit_requests = (Bug.objects.filter(
        component='Community IT Requests').exclude(q_closed))
    planning_requests = (Bug.objects.filter(
        component='Planning').exclude(q_closed))

    today = date.today()
    if user.groups.filter(name='Rep').exists():
        args['monthly_reports'] = get_reports_for_year(
            user,
            start_year=2011,
            end_year=today.year,
            permission=REPORTS_PERMISSION_LEVEL['owner'])

    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,
                                     userprofile__registration_complete=True)

    args['my_budget_requests'] = budget_requests.filter(my_q).distinct()
    args['my_swag_requests'] = swag_requests.filter(my_q).distinct()

    if user.groups.filter(name='Mentor').exists():
        args['mentees_budget_requests'] = (budget_requests.filter(
            creator__in=my_mentees).distinct())
        args['mentees_swag_requests'] = (swag_requests.filter(
            creator__in=my_mentees).distinct())
        my_mentorship_requests = mentorship_requests.filter(my_q_assigned)
        my_mentorship_requests = my_mentorship_requests.order_by('whiteboard')
        args['my_mentorship_requests'] = my_mentorship_requests.distinct()
        args['mentees_reports_list'] = (Report.objects.filter(
            mentor=user).order_by('-created_on').distinct()[:20])
        args['mentees_reports_grid'] = get_mentee_reports_for_month(user)
        args['mentees_emails'] = (my_mentees.values_list(
            'first_name', 'last_name', 'email') or None)
        args['email_mentees_form'] = forms.EmailUsersForm(my_mentees)

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

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

    return render(request, 'dashboard_reps.html', args)