Exemple #1
0
def view_profile(request, display_name):
    """View user profile."""
    user = get_object_or_404(User,
                             userprofile__display_name__iexact=display_name)
    if not user.groups.filter(name='Rep').exists():
        raise Http404

    if (not user.userprofile.registration_complete and
            not request.user.has_perm('profiles.can_edit_profiles')):
            raise Http404

    usergroups = user.groups.filter(Q(name='Mentor') | Q(name='Council'))
    data = {'pageuser': user,
            'user_profile': user.userprofile,
            'added_by': user.userprofile.added_by,
            'mentor': user.userprofile.mentor,
            'usergroups': usergroups}

    today = timezone.now().date()

    # NGReports
    data['ng_reports'] = (user.ng_reports
                          .filter(report_date__lte=today)
                          .order_by('-report_date'))

    past_user_events = get_events_for_user(user, to_date=today)

    data['future_events'] = get_events_for_user(user, from_date=today)
    data['past_events'] = past_user_events.reverse()[:10]
    data['featured_rep'] = FeaturedRep.objects.filter(user=user)

    return render(request, 'profiles_view.html', data)
Exemple #2
0
def view_profile(request, display_name):
    """View user profile."""
    user = get_object_or_404(User,
                             userprofile__display_name__iexact=display_name)
    if not user.groups.filter(name='Rep').exists():
        raise Http404

    if (not user.userprofile.registration_complete
            and not request.user.has_perm('profiles.can_edit_profiles')):
        raise Http404

    usergroups = user.groups.filter(Q(name='Mentor') | Q(name='Council'))
    data = {
        'pageuser': user,
        'user_profile': user.userprofile,
        'added_by': user.userprofile.added_by,
        'mentor': user.userprofile.mentor,
        'usergroups': usergroups
    }

    today = datetime.utcnow().date()

    # Enable NGReports if waffle flag is active
    if waffle.flag_is_active(request, 'reports_ng_report'):
        data['ng_reports'] = (user.ng_reports.filter(
            report_date__lte=today).order_by('-report_date'))

    if ((request.user.is_authenticated()
         and user in request.user.mentees.all()) or user == request.user):
        reports = get_reports_for_year(
            user,
            start_year=2011,
            end_year=today.year,
            permission=REPORTS_PERMISSION_LEVEL['owner'])
    elif request.user.is_authenticated():
        reports = get_reports_for_year(
            user,
            start_year=2011,
            end_year=today.year,
            permission=REPORTS_PERMISSION_LEVEL['authenticated'])
    else:
        reports = get_reports_for_year(
            user,
            start_year=2011,
            end_year=today.year,
            permission=REPORTS_PERMISSION_LEVEL['anonymous'])
    data['monthly_reports'] = reports

    past_user_events = get_events_for_user(user, to_date=today)

    data['future_events'] = get_events_for_user(user, from_date=today)
    data['past_events'] = past_user_events.reverse()[:10]
    data['featured_rep'] = FeaturedRep.objects.filter(user=user)

    return render(request, 'profiles_view.html', data)
Exemple #3
0
def view_profile(request, display_name):
    """View user profile."""
    user = get_object_or_404(User,
                             userprofile__display_name__iexact=display_name)
    if not user.groups.filter(name='Rep').exists():
        raise Http404

    if (not user.userprofile.registration_complete and
            not request.user.has_perm('profiles.can_edit_profiles')):
            raise Http404

    usergroups = user.groups.filter(Q(name='Mentor') | Q(name='Council'))
    data = {'pageuser': user,
            'user_profile': user.userprofile,
            'added_by': user.userprofile.added_by,
            'mentor': user.userprofile.mentor,
            'usergroups': usergroups}

    today = datetime.utcnow().date()

    # Enable NGReports if waffle flag is active
    if waffle.flag_is_active(request, 'reports_ng_report'):
        data['ng_reports'] = (user.ng_reports
                              .filter(report_date__lte=today)
                              .order_by('-report_date'))

    if ((request.user.is_authenticated() and
         user in request.user.mentees.all()) or
            user == request.user):
        reports = get_reports_for_year(
            user, start_year=2011, end_year=today.year,
            permission=REPORTS_PERMISSION_LEVEL['owner'])
    elif request.user.is_authenticated():
        reports = get_reports_for_year(
            user, start_year=2011, end_year=today.year,
            permission=REPORTS_PERMISSION_LEVEL['authenticated'])
    else:
        reports = get_reports_for_year(
            user, start_year=2011, end_year=today.year,
            permission=REPORTS_PERMISSION_LEVEL['anonymous'])
    data['monthly_reports'] = reports

    past_user_events = get_events_for_user(user, to_date=today)

    data['future_events'] = get_events_for_user(user, from_date=today)
    data['past_events'] = past_user_events.reverse()[:10]
    data['featured_rep'] = FeaturedRep.objects.filter(user=user)

    return render(request, 'profiles_view.html', data)
Exemple #4
0
def view_profile(request, display_name):
    """View user profile."""
    user = get_object_or_404(User,
                             userprofile__display_name__iexact=display_name)
    if not user.groups.filter(name='Rep').exists():
        raise Http404

    if (not user.userprofile.registration_complete
            and not request.user.has_perm('profiles.can_edit_profiles')):
        raise Http404

    usergroups = user.groups.filter(Q(name='Mentor') | Q(name='Council'))
    data = {
        'pageuser': user,
        'user_profile': user.userprofile,
        'added_by': user.userprofile.added_by,
        'mentor': user.userprofile.mentor,
        'usergroups': usergroups
    }

    if user.userprofile.is_unavailable:
        status = UserStatus.objects.filter(user=user).latest('created_on')
        data['user_status'] = status
        if user == request.user:
            today = timezone.now().date()
            date = (status.expected_date.strftime('%d %B %Y')
                    if status.expected_date > today else None)
            msg = render_to_string(
                'includes/view_profile_unavailable_msg.html', {
                    'date': date,
                    'display_name': user.userprofile.display_name
                })
            messages.info(request, mark_safe(msg))

    today = timezone.now().date()

    # NGReports
    data['ng_reports'] = (user.ng_reports.filter(
        report_date__lte=today).order_by('-report_date'))

    past_user_events = get_events_for_user(user, to_date=today)

    data['future_events'] = get_events_for_user(user, from_date=today)
    data['past_events'] = past_user_events.reverse()[:10]
    data['featured_rep'] = FeaturedRep.objects.filter(user=user)

    return render(request, 'profiles_view.html', data)
Exemple #5
0
def view_profile(request, display_name):
    """View user profile."""
    user = get_object_or_404(User, userprofile__display_name__iexact=display_name)
    if not user.groups.filter(name="Rep").exists():
        raise Http404

    if not user.userprofile.registration_complete and not request.user.has_perm("profiles.can_edit_profiles"):
        raise Http404

    usergroups = user.groups.filter(Q(name="Mentor") | Q(name="Council"))
    data = {
        "pageuser": user,
        "user_profile": user.userprofile,
        "added_by": user.userprofile.added_by,
        "mentor": user.userprofile.mentor,
        "usergroups": usergroups,
    }

    today = datetime.utcnow().date()

    # Enable NGReports if waffle flag is active
    if waffle.flag_is_active(request, "reports_ng_report"):
        data["ng_reports"] = user.ng_reports.filter(report_date__lte=today).order_by("-report_date")

    if (request.user.is_authenticated() and user in request.user.mentees.all()) or user == request.user:
        reports = get_reports_for_year(
            user, start_year=2011, end_year=today.year, permission=REPORTS_PERMISSION_LEVEL["owner"]
        )
    elif request.user.is_authenticated():
        reports = get_reports_for_year(
            user, start_year=2011, end_year=today.year, permission=REPORTS_PERMISSION_LEVEL["authenticated"]
        )
    else:
        reports = get_reports_for_year(
            user, start_year=2011, end_year=today.year, permission=REPORTS_PERMISSION_LEVEL["anonymous"]
        )
    data["monthly_reports"] = reports

    past_user_events = get_events_for_user(user, to_date=today)

    data["future_events"] = get_events_for_user(user, from_date=today)
    data["past_events"] = past_user_events.reverse()[:10]
    data["featured_rep"] = FeaturedRep.objects.filter(user=user)

    return render(request, "profiles_view.html", data)
Exemple #6
0
def view_profile(request, display_name):
    """View user profile."""
    user = get_object_or_404(User,
                             userprofile__display_name__iexact=display_name)
    if not user.groups.filter(name='Rep').exists():
        raise Http404

    if (not user.userprofile.registration_complete and
            not request.user.has_perm('profiles.can_edit_profiles')):
            raise Http404

    usergroups = user.groups.filter(Q(name='Mentor') | Q(name='Council'))
    data = {'pageuser': user,
            'user_profile': user.userprofile,
            'added_by': user.userprofile.added_by,
            'mentor': user.userprofile.mentor,
            'usergroups': usergroups}

    if user.userprofile.is_unavailable:
        status = UserStatus.objects.filter(user=user).latest('created_on')
        data['user_status'] = status
        if user == request.user:
            today = timezone.now().date()
            date = (status.expected_date.strftime('%d %B %Y')
                    if status.expected_date > today else None)
            msg = render_to_string(
                'includes/view_profile_unavailable_msg.html',
                {'date': date,
                 'display_name': user.userprofile.display_name})
            messages.info(request, mark_safe(msg))

    today = timezone.now().date()

    # NGReports
    data['ng_reports'] = (user.ng_reports
                          .filter(report_date__lte=today)
                          .order_by('-report_date'))

    past_user_events = get_events_for_user(user, to_date=today)

    data['future_events'] = get_events_for_user(user, from_date=today)
    data['past_events'] = past_user_events.reverse()[:10]
    data['featured_rep'] = FeaturedRep.objects.filter(user=user)

    return render(request, 'profiles_view.html', data)
Exemple #7
0
def view_profile(request, display_name):
    """View user profile."""
    user = get_object_or_404(User,
                             userprofile__display_name__iexact=display_name)
    usergroups = user.groups.filter(Q(name='Mentor')|Q(name='Council'))

    if (not user.userprofile.registration_complete and
        not request.user.has_perm('profiles.can_edit_profiles')):
            raise Http404

    data = {'pageuser': user,
            'user_profile': user.userprofile,
            'added_by': user.userprofile.added_by,
            'mentor': user.userprofile.mentor,
            'usergroups': usergroups}

    if user.groups.filter(name='Rep').exists():
        today = date.today()
        if (request.user.groups.filter(name='Admin').exists() or
            (request.user.is_authenticated() and
             user in request.user.mentees.all()) or
            user == request.user):
            reports = get_reports_for_year(
                user, start_year=2011, end_year=today.year,
                permission=REPORTS_PERMISSION_LEVEL['owner'])
        elif request.user.is_authenticated():
            reports = get_reports_for_year(
                user, start_year=2011, end_year=today.year,
                permission=REPORTS_PERMISSION_LEVEL['authenticated'])
        else:
            reports = get_reports_for_year(
                user, start_year=2011, end_year=today.year,
                permission=REPORTS_PERMISSION_LEVEL['anonymous'])

        data['monthly_reports'] = reports

    today = date.today()
    data['future_events'] = get_events_for_user(user, from_date=today)
    data['past_events'] = get_events_for_user(user, to_date=today)[:10]

    return render(request, 'profiles_view.html', data)
Exemple #8
0
def view_profile(request, display_name):
    """View user profile."""
    user = get_object_or_404(User,
                             userprofile__display_name__iexact=display_name)
    usergroups = user.groups.filter(Q(name='Mentor')|Q(name='Council'))

    if (not user.userprofile.registration_complete and
        not request.user.has_perm('profiles.can_edit_profiles')):
            raise Http404

    data = {'pageuser': user,
            'user_profile': user.userprofile,
            'added_by': user.userprofile.added_by,
            'mentor': user.userprofile.mentor,
            'usergroups': usergroups}

    if user.groups.filter(name='Rep').exists():
        today = date.today()
        if (request.user.groups.filter(name='Admin').exists() or
            (request.user.is_authenticated() and
             user in request.user.mentees.all()) or
            user == request.user):
            reports = get_reports_for_year(
                user, start_year=2011, end_year=today.year,
                permission=REPORTS_PERMISSION_LEVEL['owner'])
        elif request.user.is_authenticated():
            reports = get_reports_for_year(
                user, start_year=2011, end_year=today.year,
                permission=REPORTS_PERMISSION_LEVEL['authenticated'])
        else:
            reports = get_reports_for_year(
                user, start_year=2011, end_year=today.year,
                permission=REPORTS_PERMISSION_LEVEL['anonymous'])

        data['monthly_reports'] = reports

    today = date.today()
    data['future_events'] = get_events_for_user(user, from_date=today)
    data['past_events'] = get_events_for_user(user, to_date=today)[:10]

    return render(request, 'profiles_view.html', data)
Exemple #9
0
def view_profile(request, display_name):
    """View user profile."""
    user = get_object_or_404(User,
                             userprofile__display_name__iexact=display_name)
    user_is_alumni = user.groups.filter(name='Alumni').exists()
    if not user.groups.filter(Q(name='Rep') | Q(name='Alumni')).exists():
        raise Http404

    if (not user.userprofile.registration_complete
            and not request.user.has_perm('profiles.can_edit_profiles')):
        raise Http404

    nominee_form = forms.RotmNomineeForm(request.POST or None,
                                         instance=user.userprofile)

    usergroups = user.groups.filter(
        Q(name='Mentor') | Q(name='Council') | Q(name='Peers')
        | Q(name='Resources') | Q(name='Onboarding'))
    is_nomination_period = now().date() < rotm_nomination_end_date()
    data = {
        'pageuser': user,
        'user_profile': user.userprofile,
        'added_by': user.userprofile.added_by,
        'mentor': user.userprofile.mentor,
        'usergroups': usergroups,
        'user_nominated': user.userprofile.is_rotm_nominee,
        'is_nomination_period': is_nomination_period,
        'user_is_alumni': user_is_alumni
    }

    if UserStatus.objects.filter(user=user, is_unavailable=True).exists():
        status = UserStatus.objects.filter(user=user).latest('created_on')
        data['user_status'] = status
        if user == request.user:
            today = now().date()
            date = (status.expected_date.strftime('%d %B %Y')
                    if status.expected_date > today else None)
            msg = render_to_string(
                'includes/view_profile_unavailable_msg.jinja', {
                    'date': date,
                    'display_name': user.userprofile.display_name
                })
            messages.info(request, mark_safe(msg))

    if nominee_form.is_valid():
        if ((is_nomination_period
             or waffle.switch_is_active('enable_rotm_tasks'))
                and request.user.groups.filter(name='Mentor').exists()
                and request.user != user):
            nominee_form.save(nominated_by=request.user)
            return redirect('profiles_view_profile', display_name=display_name)

        messages.warning(request, ('Only mentors can nominate a mentee.'))

    if user_is_alumni:
        msg = render_to_string('includes/alumni_msg.jinja')
        messages.info(request, mark_safe(msg))

    today = now().date()

    # NGReports
    data['ng_reports'] = (user.ng_reports.filter(
        report_date__lte=today).order_by('-report_date'))

    past_user_events = get_events_for_user(user, to_date=today)

    data['future_events'] = get_events_for_user(user, from_date=today)
    data['past_events'] = past_user_events.reverse()[:10]
    data['featured_rep'] = user.featuredrep_users.all()
    data['request_user'] = request.user
    data['nominee_form'] = nominee_form

    return render(request, 'profiles_view.jinja', data)
Exemple #10
0
def view_profile(request, display_name):
    """View user profile."""
    user = get_object_or_404(User,
                             userprofile__display_name__iexact=display_name)
    user_is_alumni = user.groups.filter(name='Alumni').exists()
    if not user.groups.filter(Q(name='Rep') | Q(name='Alumni')).exists():
        raise Http404

    if (not user.userprofile.registration_complete and
            not request.user.has_perm('profiles.can_edit_profiles')):
            raise Http404

    nominee_form = forms.RotmNomineeForm(request.POST or None,
                                         instance=user.userprofile)

    usergroups = user.groups.filter(
        Q(name='Mentor') |
        Q(name='Council') |
        Q(name='Peers') |
        Q(name='Resources') |
        Q(name='Onboarding') |
        Q(name='Newsletter')
    )
    is_nomination_period = now().date() < rotm_nomination_end_date()
    data = {'pageuser': user,
            'user_profile': user.userprofile,
            'added_by': user.userprofile.added_by,
            'mentor': user.userprofile.mentor,
            'usergroups': usergroups,
            'user_nominated': user.userprofile.is_rotm_nominee,
            'is_nomination_period': is_nomination_period,
            'user_is_alumni': user_is_alumni}

    if UserStatus.objects.filter(user=user, is_unavailable=True).exists():
        status = UserStatus.objects.filter(user=user).latest('created_on')
        data['user_status'] = status
        if user == request.user:
            today = now().date()
            date = (status.expected_date.strftime('%d %B %Y')
                    if status.expected_date > today else None)
            msg = render_to_string(
                'includes/view_profile_unavailable_msg.jinja',
                {'date': date,
                 'display_name': user.userprofile.display_name})
            messages.info(request, mark_safe(msg))

    if nominee_form.is_valid():
        if ((is_nomination_period or waffle.switch_is_active('enable_rotm_tasks')) and
                request.user.groups.filter(name='Mentor').exists() and request.user != user):
            nominee_form.save(nominated_by=request.user)
            return redirect('profiles_view_profile', display_name=display_name)

        messages.warning(request, ('Only mentors can nominate a mentee.'))

    if user_is_alumni:
        msg = render_to_string('includes/alumni_msg.jinja')
        messages.info(request, mark_safe(msg))

    today = now().date()

    # NGReports
    data['ng_reports'] = (user.ng_reports
                          .filter(report_date__lte=today)
                          .order_by('-report_date'))

    past_user_events = get_events_for_user(user, to_date=today)

    data['future_events'] = get_events_for_user(user, from_date=today)
    data['past_events'] = past_user_events.reverse()[:10]
    data['featured_rep'] = user.featuredrep_users.all()
    data['request_user'] = request.user
    data['nominee_form'] = nominee_form

    return render(request, 'profiles_view.jinja', data)