# Path: remo/profiles/api/serializers.py
# class PeopleKPISerializer(BaseKPISerializer):
#     """Serializer for people (Reps) data."""
#     inactive_week = serializers.IntegerField()
#     casual_week = serializers.IntegerField()
#     active_week = serializers.IntegerField()
#     core_week = serializers.IntegerField()
# 
# class UserProfileDetailedSerializer(serializers.HyperlinkedModelSerializer):
#     """Detailed serializer for the UserProfile model."""
#     first_name = serializers.ReadOnlyField(source='user.first_name')
#     last_name = serializers.ReadOnlyField(source='user.last_name')
#     mentor = UserSerializer()
#     groups = GroupSerializer(source='user.groups', many=True)
#     functional_areas = FunctionalAreaSerializer(many=True)
#     mobilising_skills = MobilisingSkillSerializer(many=True)
#     mobilising_interests = MobilisingInterestSerializer(many=True)
#     remo_url = serializers.SerializerMethodField()
#     date_joined_program = serializers.DateTimeField(format='%Y-%m-%d')
#     date_left_program = serializers.DateTimeField(format='%Y-%m-%d')
# 
#     class Meta:
#         model = UserProfile
#         # Todo add logic for mozillians_username
#         fields = ['first_name', 'last_name', 'display_name',
#                   'date_joined_program', 'date_left_program', 'city', 'region',
#                   'country', 'twitter_account', 'jabber_id', 'irc_name',
#                   'wiki_profile_url', 'irc_channels', 'linkedin_url',
#                   'facebook_url', 'diaspora_url', 'functional_areas', 'mobilising_skills',
#                   'mobilising_interests', 'bio', 'mentor', 'mozillians_profile_url',
#                   'timezone', 'groups', 'remo_url']
# 
#     def get_remo_url(self, obj):
#         """
#         Default method for fetching the profile url for the user
#         in ReMo portal.
#         """
#         return absolutify(obj.get_absolute_url())
# 
# class UserSerializer(serializers.HyperlinkedModelSerializer):
#     """Serializer for the django User model."""
#     display_name = serializers.ReadOnlyField(source='userprofile.display_name')
# 
#     class Meta:
#         model = User
#         fields = ['first_name', 'last_name', 'display_name', '_url']
# 
# Path: remo/base/utils.py
# def get_quarter(date=None):
#     """Return the quarter for this date and datetime of Q's start."""
#     if not date:
#         date = timezone.now()
# 
#     quarter = int(math.ceil(date.month / 3.0))
#     first_month_of_quarter = 1 + 3 * (quarter - 1)
#     quarter_start = datetime.datetime(date.year, first_month_of_quarter, 1)
# 
#     return (quarter, quarter_start)


from collections import namedtuple
from datetime import datetime, timedelta
from django.db.models import Count, Q
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404
from django.utils.timezone import now
from rest_framework.views import APIView
from rest_framework.response import Response
from remo.profiles.api.serializers import (PeopleKPISerializer,
                                           UserProfileDetailedSerializer,
                                           UserSerializer)
from remo.api.views import BaseReadOnlyModelViewset
from remo.base.utils import get_quarter
from remo.profiles.models import UserProfile
import django_filters
        name='userprofile__wiki_profile_url')
    irc_channels = django_filters.CharFilter(name='userprofile__irc_channels')
    linkedin = django_filters.CharFilter(name='userprofile__linkedin_url')
    facebook = django_filters.CharFilter(name='userprofile__facebook_url')
    diaspora = django_filters.CharFilter(name='userprofile__diaspora_url')

    class Meta:
        model = User
        fields = ('first_name', 'last_name')


class UserProfileViewSet(BaseReadOnlyModelViewset):
    """Returns a list of Reps profiles."""
    serializer_class = UserSerializer
    model = User
    queryset = User.objects.all()
    filter_class = UserProfileFilter

    def get_queryset(self):
        orderby = self.request.query_params.get('orderby', 'DESC')

        queryset = self.queryset.filter(
            groups__name='Rep', userprofile__registration_complete=True)

        if orderby == 'DESC':
            queryset = queryset.order_by('-date_joined')
        return queryset

    def retrieve(self, request, pk):
        user = get_object_or_404(self.get_queryset(), pk=pk)

# Path: remo/profiles/api/serializers.py
# class PeopleKPISerializer(BaseKPISerializer):
#     """Serializer for people (Reps) data."""
#     inactive_week = serializers.IntegerField()
#     casual_week = serializers.IntegerField()
#     active_week = serializers.IntegerField()
#     core_week = serializers.IntegerField()
# 
# class UserProfileDetailedSerializer(serializers.HyperlinkedModelSerializer):
#     """Detailed serializer for the UserProfile model."""
#     first_name = serializers.ReadOnlyField(source='user.first_name')
#     last_name = serializers.ReadOnlyField(source='user.last_name')
#     mentor = UserSerializer()
#     groups = GroupSerializer(source='user.groups', many=True)
#     functional_areas = FunctionalAreaSerializer(many=True)
#     mobilising_skills = MobilisingSkillSerializer(many=True)
#     mobilising_interests = MobilisingInterestSerializer(many=True)
#     remo_url = serializers.SerializerMethodField()
#     date_joined_program = serializers.DateTimeField(format='%Y-%m-%d')
#     date_left_program = serializers.DateTimeField(format='%Y-%m-%d')
# 
#     class Meta:
#         model = UserProfile
#         # Todo add logic for mozillians_username
#         fields = ['first_name', 'last_name', 'display_name',
#                   'date_joined_program', 'date_left_program', 'city', 'region',
#                   'country', 'twitter_account', 'jabber_id', 'irc_name',
#                   'wiki_profile_url', 'irc_channels', 'linkedin_url',
#                   'facebook_url', 'diaspora_url', 'functional_areas', 'mobilising_skills',
#                   'mobilising_interests', 'bio', 'mentor', 'mozillians_profile_url',
#                   'timezone', 'groups', 'remo_url']
# 
#     def get_remo_url(self, obj):
#         """
#         Default method for fetching the profile url for the user
#         in ReMo portal.
#         """
#         return absolutify(obj.get_absolute_url())
# 
# class UserSerializer(serializers.HyperlinkedModelSerializer):
#     """Serializer for the django User model."""
#     display_name = serializers.ReadOnlyField(source='userprofile.display_name')
# 
#     class Meta:
#         model = User
#         fields = ['first_name', 'last_name', 'display_name', '_url']
# 
# Path: remo/base/utils.py
# def get_quarter(date=None):
#     """Return the quarter for this date and datetime of Q's start."""
#     if not date:
#         date = timezone.now()
# 
#     quarter = int(math.ceil(date.month / 3.0))
#     first_month_of_quarter = 1 + 3 * (quarter - 1)
#     quarter_start = datetime.datetime(date.year, first_month_of_quarter, 1)
# 
#     return (quarter, quarter_start)


# Path: remo/profiles/api/views.py
from collections import namedtuple
from datetime import datetime, timedelta
from django.db.models import Count, Q
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404
from django.utils.timezone import now
from rest_framework.views import APIView
from rest_framework.response import Response
from remo.profiles.api.serializers import (PeopleKPISerializer,
                                           UserProfileDetailedSerializer,
                                           UserSerializer)
from remo.api.views import BaseReadOnlyModelViewset
from remo.base.utils import get_quarter
from remo.profiles.models import UserProfile
import django_filters

        name='userprofile__wiki_profile_url')
    irc_channels = django_filters.CharFilter(name='userprofile__irc_channels')
    linkedin = django_filters.CharFilter(name='userprofile__linkedin_url')
    facebook = django_filters.CharFilter(name='userprofile__facebook_url')
    diaspora = django_filters.CharFilter(name='userprofile__diaspora_url')

    class Meta:
        model = User
        fields = ('first_name', 'last_name')


class UserProfileViewSet(BaseReadOnlyModelViewset):
    """Returns a list of Reps profiles."""
    serializer_class = UserSerializer
    model = User
    queryset = User.objects.all()
    filter_class = UserProfileFilter

    def get_queryset(self):
        orderby = self.request.query_params.get('orderby', 'DESC')

        queryset = self.queryset.filter(
            groups__name='Rep', userprofile__registration_complete=True)

        if orderby == 'DESC':
            queryset = queryset.order_by('-date_joined')
        return queryset

    def retrieve(self, request, pk):
        user = get_object_or_404(self.get_queryset(), pk=pk)

        serializer = UserProfileDetailedSerializer(