# Path: api_v3/models/profile.py
# class Profile(AbstractUser):
#     class Meta:
#         db_table = 'accounts_profile'
# 
#     objects = ProfileManager()
# 
#     # Disable the `username` field
#     username = None
# 
#     profile_updated = models.DateTimeField(auto_now=True)
#     email = models.EmailField(max_length=254, unique=True, blank=False)
#     first_name = models.CharField(max_length=64)
#     last_name = models.CharField(max_length=64)
#     locale = models.CharField(blank=True, max_length=16)
#     phone_number = models.CharField(blank=True, max_length=255)
#     organization = models.CharField(blank=True, max_length=1024)
#     country = models.CharField(blank=True, max_length=32, choices=COUNTRIES)
#     bio = models.TextField(blank=True, null=True)
# 
#     # Django auth module settings
#     USERNAME_FIELD = 'email'
#     REQUIRED_FIELDS = []
# 
#     @property
#     def display_name(self):
#         if self.first_name or self.last_name:
#             return ' '.join((self.first_name, self.last_name)).strip()
#         return self.email
# 
#     def get_full_name(self):
#         return self.display_name
# 
# Path: api_v3/serializers/profile.py
# class ProfileSerializer(serializers.ModelSerializer):
# 
#     tickets_count = fields.SerializerMethodField()
# 
#     class Meta:
#         model = Profile
#         read_only_fields = (
#             'id',
#             'email',
#             'first_name',
#             'last_name',
#             'is_staff',
#             'is_superuser',
#             'locale'
#         )
#         fields = (
#             'id',
#             'email',
#             'first_name',
#             'last_name',
#             'is_staff',
#             'is_superuser',
#             'bio',
#             'locale',
#             'tickets_count'
#         )
# 
#     def get_tickets_count(self, obj):
#         if obj.is_superuser:
#             return Ticket.objects.count()
#         else:
#             return Ticket.filter_by_user(obj).count()
# 
#     def to_representation(self, obj):
#         request = self.context.get('request', None)
# 
#         data = super(ProfileSerializer, self).to_representation(obj)
# 
#         if request and request.user and (
#             request.user.is_staff or request.user.is_superuser
#         ):
#             return data
# 
#         # For regular users, make sure others email is not displayed
#         if request and request.user != obj:
#             data.pop('email')
# 
#         return data
# 
#     # Adds extra application related metas.
#     def get_root_meta(self, resource, many):
#         if not self.context.get('add_misc', None):
#             return {}
# 
#         return {
#             'member_centers': sorted(settings.MEMBER_CENTERS),
#             'expense_scopes': sorted(settings.EXPENSE_SCOPES)
#         }
# 
# Path: api_v3/views/support.py
# class JSONApiEndpoint(object):
#     """Generic mixin for our endpoints to enable JSON API format.
# 
#     See: https://github.com/django-json-api/django-rest-framework-json-api/blob/develop/example/views.py  # noqa
#     """
#     parser_classes = [
#         rest_framework_json_api.parsers.JSONParser,
#         rest_framework.parsers.FormParser,
#         rest_framework.parsers.MultiPartParser,
#     ]
#     renderer_classes = set([
#         rest_framework_json_api.renderers.JSONRenderer,
#         rest_framework.renderers.BrowsableAPIRenderer
#     ])
# 
#     if (not settings.DEBUG):
#         renderer_classes.remove(rest_framework.renderers.BrowsableAPIRenderer)
# 
#     authentication_classes = [
#         SessionAuthenticationSansCSRF,
#     ]
#     filter_backends = [
#         OrderingFilter,
#         DjangoFilterBackend
#     ]
#     pagination_class = Pagination
#     metadata_class = rest_framework_json_api.metadata.JSONAPIMetadata
#     filter_fields = ('id', )
# 
#     def extract_filter_params(self, request):
#         params = qs_parser.parse(request.META['QUERY_STRING'])
#         params = params.get('filter') or {}
# 
#         for k, v in list(params.items()):
#             if not v:
#                 params.pop(k)
# 
#         return params
# 
#     def action_name(self):
#         """Simple helper to generate the current action name."""
#         template = '{}:{}'
#         resource = self.queryset.model.__name__.lower()
#         return template.format(resource, self.action).replace('partial_', '')
# 
#     def handle_exception(self, exc):
#         context = self.get_exception_handler_context()
#         response = rest_framework_json_api.exceptions.exception_handler(
#             exc, context)
# 
#         if response is None:
#             self.raise_uncaught_exception(exc)
# 
#         if isinstance(exc, rest_framework.exceptions.ValidationError):
#             # For ember-data validation errors (isInvalid method on adapter)
#             response.status_code = HTTP_422_UNPROCESSABLE_ENTITY
# 
#         return response


from rest_framework import response, viewsets
from api_v3.models import Profile
from api_v3.serializers import ProfileSerializer
from .support import JSONApiEndpoint



class SessionEndpoint(JSONApiEndpoint, viewsets.GenericViewSet):
    serializer_class = ProfileSerializer

    def get_queryset(self):
        return Profile.objects.none()

    def list(self, request, *args, **kwargs):
        serializer = self.get_serializer(request.user)

# Path: api_v3/models/profile.py
# class Profile(AbstractUser):
#     class Meta:
#         db_table = 'accounts_profile'
# 
#     objects = ProfileManager()
# 
#     # Disable the `username` field
#     username = None
# 
#     profile_updated = models.DateTimeField(auto_now=True)
#     email = models.EmailField(max_length=254, unique=True, blank=False)
#     first_name = models.CharField(max_length=64)
#     last_name = models.CharField(max_length=64)
#     locale = models.CharField(blank=True, max_length=16)
#     phone_number = models.CharField(blank=True, max_length=255)
#     organization = models.CharField(blank=True, max_length=1024)
#     country = models.CharField(blank=True, max_length=32, choices=COUNTRIES)
#     bio = models.TextField(blank=True, null=True)
# 
#     # Django auth module settings
#     USERNAME_FIELD = 'email'
#     REQUIRED_FIELDS = []
# 
#     @property
#     def display_name(self):
#         if self.first_name or self.last_name:
#             return ' '.join((self.first_name, self.last_name)).strip()
#         return self.email
# 
#     def get_full_name(self):
#         return self.display_name
# 
# Path: api_v3/serializers/profile.py
# class ProfileSerializer(serializers.ModelSerializer):
# 
#     tickets_count = fields.SerializerMethodField()
# 
#     class Meta:
#         model = Profile
#         read_only_fields = (
#             'id',
#             'email',
#             'first_name',
#             'last_name',
#             'is_staff',
#             'is_superuser',
#             'locale'
#         )
#         fields = (
#             'id',
#             'email',
#             'first_name',
#             'last_name',
#             'is_staff',
#             'is_superuser',
#             'bio',
#             'locale',
#             'tickets_count'
#         )
# 
#     def get_tickets_count(self, obj):
#         if obj.is_superuser:
#             return Ticket.objects.count()
#         else:
#             return Ticket.filter_by_user(obj).count()
# 
#     def to_representation(self, obj):
#         request = self.context.get('request', None)
# 
#         data = super(ProfileSerializer, self).to_representation(obj)
# 
#         if request and request.user and (
#             request.user.is_staff or request.user.is_superuser
#         ):
#             return data
# 
#         # For regular users, make sure others email is not displayed
#         if request and request.user != obj:
#             data.pop('email')
# 
#         return data
# 
#     # Adds extra application related metas.
#     def get_root_meta(self, resource, many):
#         if not self.context.get('add_misc', None):
#             return {}
# 
#         return {
#             'member_centers': sorted(settings.MEMBER_CENTERS),
#             'expense_scopes': sorted(settings.EXPENSE_SCOPES)
#         }
# 
# Path: api_v3/views/support.py
# class JSONApiEndpoint(object):
#     """Generic mixin for our endpoints to enable JSON API format.
# 
#     See: https://github.com/django-json-api/django-rest-framework-json-api/blob/develop/example/views.py  # noqa
#     """
#     parser_classes = [
#         rest_framework_json_api.parsers.JSONParser,
#         rest_framework.parsers.FormParser,
#         rest_framework.parsers.MultiPartParser,
#     ]
#     renderer_classes = set([
#         rest_framework_json_api.renderers.JSONRenderer,
#         rest_framework.renderers.BrowsableAPIRenderer
#     ])
# 
#     if (not settings.DEBUG):
#         renderer_classes.remove(rest_framework.renderers.BrowsableAPIRenderer)
# 
#     authentication_classes = [
#         SessionAuthenticationSansCSRF,
#     ]
#     filter_backends = [
#         OrderingFilter,
#         DjangoFilterBackend
#     ]
#     pagination_class = Pagination
#     metadata_class = rest_framework_json_api.metadata.JSONAPIMetadata
#     filter_fields = ('id', )
# 
#     def extract_filter_params(self, request):
#         params = qs_parser.parse(request.META['QUERY_STRING'])
#         params = params.get('filter') or {}
# 
#         for k, v in list(params.items()):
#             if not v:
#                 params.pop(k)
# 
#         return params
# 
#     def action_name(self):
#         """Simple helper to generate the current action name."""
#         template = '{}:{}'
#         resource = self.queryset.model.__name__.lower()
#         return template.format(resource, self.action).replace('partial_', '')
# 
#     def handle_exception(self, exc):
#         context = self.get_exception_handler_context()
#         response = rest_framework_json_api.exceptions.exception_handler(
#             exc, context)
# 
#         if response is None:
#             self.raise_uncaught_exception(exc)
# 
#         if isinstance(exc, rest_framework.exceptions.ValidationError):
#             # For ember-data validation errors (isInvalid method on adapter)
#             response.status_code = HTTP_422_UNPROCESSABLE_ENTITY
# 
#         return response


# Path: api_v3/views/session.py
from rest_framework import response, viewsets
from api_v3.models import Profile
from api_v3.serializers import ProfileSerializer
from .support import JSONApiEndpoint




class SessionEndpoint(JSONApiEndpoint, viewsets.GenericViewSet):
    serializer_class = ProfileSerializer

    def get_queryset(self):
        return Profile.objects.none()

    def list(self, request, *args, **kwargs):
        serializer = self.get_serializer(request.user)

        return response.Response(serializer.data)