# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from tastypie import fields
from tastypie.resources import ModelResource
from tastypie.authorization import Authorization
from core.models.request import Request
from api.resources.user_resource import UserResource
from datetime import datetime
import pytz

DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'

'''
'''
class RequestResource(ModelResource):
    user = fields.ToOneField(UserResource, 'user', full=True, null=True)

    class Meta:
        queryset = Request.objects.all()
        authorization = Authorization()
        always_return_data = True,
        collection_name = 'requests'
    
    '''
    '''
    def dehydrate_status(self, bundle):
        return [
            bundle.obj.status,
            bundle.obj.get_status_display()
        ]

    '''
    '''
    def dehydrate_create_at(self, bundle):
        dt = bundle.obj.create_at
        dt.replace(tzinfo=pytz.UTC)
        return dt.strftime(DATETIME_FORMAT)

