# Path: remo/base/templatetags/helpers.py
# @library.filter
# def urlparams(url_, hash=None, **query):
#     """Add a fragment and/or query paramaters to a URL.
# 
#     New query params will be appended to exising parameters, except duplicate
#     names, which will be replaced.
#     """
#     url = urlparse.urlparse(url_)
#     fragment = hash if hash is not None else url.fragment
# 
#     # Use dict(parse_qsl) so we don't get lists of values.
#     q = url.query
#     query_dict = dict(urlparse.parse_qsl(smart_str(q))) if q else {}
#     query_dict.update((k, v) for k, v in query.items())
# 
#     query_string = _urlencode([(k, v) for k, v in query_dict.items()
#                                if v is not None])
#     new = urlparse.ParseResult(url.scheme, url.netloc, url.path, url.params,
#                                query_string, fragment)
#     return new.geturl()
# 
# Path: remo/voting/tasks.py
# def rotm_nomination_end_date():
#     return date(now().year, now().month, 10)


from django.conf import settings
from django.contrib import messages
from django.contrib.auth.decorators import user_passes_test
from django.contrib.auth.models import Group, User
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core.urlresolvers import reverse
from django.db.models import Q
from django.http import Http404
from django.shortcuts import get_object_or_404, redirect, render
from django.template.loader import render_to_string
from django.utils.timezone import now
from django.utils.encoding import iri_to_uri
from django.utils.safestring import mark_safe
from django.views.decorators.cache import cache_control, never_cache
from django_statsd.clients import statsd
from mozilla_django_oidc.auth import default_username_algo
from product_details import product_details
from remo.base.decorators import permission_check
from remo.base.templatetags.helpers import urlparams
from remo.events.utils import get_events_for_user
from remo.profiles.models import UserProfile, UserStatus
from remo.profiles.models import FunctionalArea, MobilisingInterest, MobilisingSkill
from remo.voting.tasks import rotm_nomination_end_date
import waffle
import forms
               .order_by('first_name', 'last_name')
               .exclude(groups__name='Alumni'))

    return render(request, 'profiles_mentors.jinja', {'mentors': mentors})


@cache_control(private=True, max_age=60 * 5)
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')
    )

# Path: remo/base/templatetags/helpers.py
# @library.filter
# def urlparams(url_, hash=None, **query):
#     """Add a fragment and/or query paramaters to a URL.
# 
#     New query params will be appended to exising parameters, except duplicate
#     names, which will be replaced.
#     """
#     url = urlparse.urlparse(url_)
#     fragment = hash if hash is not None else url.fragment
# 
#     # Use dict(parse_qsl) so we don't get lists of values.
#     q = url.query
#     query_dict = dict(urlparse.parse_qsl(smart_str(q))) if q else {}
#     query_dict.update((k, v) for k, v in query.items())
# 
#     query_string = _urlencode([(k, v) for k, v in query_dict.items()
#                                if v is not None])
#     new = urlparse.ParseResult(url.scheme, url.netloc, url.path, url.params,
#                                query_string, fragment)
#     return new.geturl()
# 
# Path: remo/voting/tasks.py
# def rotm_nomination_end_date():
#     return date(now().year, now().month, 10)


# Path: remo/profiles/views.py
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.decorators import user_passes_test
from django.contrib.auth.models import Group, User
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core.urlresolvers import reverse
from django.db.models import Q
from django.http import Http404
from django.shortcuts import get_object_or_404, redirect, render
from django.template.loader import render_to_string
from django.utils.timezone import now
from django.utils.encoding import iri_to_uri
from django.utils.safestring import mark_safe
from django.views.decorators.cache import cache_control, never_cache
from django_statsd.clients import statsd
from mozilla_django_oidc.auth import default_username_algo
from product_details import product_details
from remo.base.decorators import permission_check
from remo.base.templatetags.helpers import urlparams
from remo.events.utils import get_events_for_user
from remo.profiles.models import UserProfile, UserStatus
from remo.profiles.models import FunctionalArea, MobilisingInterest, MobilisingSkill
from remo.voting.tasks import rotm_nomination_end_date
import waffle
import forms

               .order_by('first_name', 'last_name')
               .exclude(groups__name='Alumni'))

    return render(request, 'profiles_mentors.jinja', {'mentors': mentors})


@cache_control(private=True, max_age=60 * 5)
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()