# Path: pyston/serializer.py
# class Serializable:
# 
#     def serialize(self, serialization_format, **kwargs):
#         raise NotImplementedError
# 
# class SerializableObj(Serializable, metaclass=SerializableObjMetaClass):
# 
#     resource_typemapper = {}
# 
#     def _get_value(self, field, serialization_format, request, **kwargs):
#         val = getattr(self, field)
#         return get_serializer(
#             val, request=request, resource_typemapper=self.resource_typemapper
#         ).serialize(val, serialization_format, **kwargs)
# 
#     def serialize(self, serialization_format, request=None, requested_fieldset=None, **kwargs):
#         return {
#             field_name: self._get_value(
#                 field_name,
#                 serialization_format,
#                 request,
#                 requested_fieldset=requested_fieldset.get(field_name).subfieldset if requested_fieldset else None,
#                 **kwargs
#             )
#             for field_name in self.get_fields()
#             if not requested_fieldset or field_name in requested_fieldset
#         }
# 
#     def get_fields(self):
#         return self.RestMeta.fields
# 
# Path: example/dj/apps/app/models.py
# class User(models.Model):
# 
#     created_at = models.DateTimeField(verbose_name=_('created at'), null=False, blank=False, auto_now_add=True)
#     email = models.EmailField(verbose_name=_('email'), null=False, blank=False, unique=True,
#                               filter=OnlyContainsStringFieldFilter)
#     contract = models.FileField(_('file'), null=True, blank=True, upload_to='documents/')
#     is_superuser = models.BooleanField(_('is superuser'), default=True)
#     first_name = models.CharField(_('first name'), null=True, blank=True, max_length=100)
#     last_name = models.CharField(_('last name'), null=True, blank=True, max_length=100)
#     manual_created_date = models.DateTimeField(verbose_name=_('manual created date'), null=True, blank=True)
# 
#     @filter_class(WatchedIssuesCountMethodFilter)
#     @sorter_class(WatchedIssuesCountSorter)
#     def watched_issues_count(self):
#         return self.watched_issues.count()
# 
#     def __str__(self):
#         return 'user: %s' % self.email
# 
#     class RestMeta:
#         fields = ('created_at', 'email', 'contract', 'solving_issue', 'first_name', 'last_name', 'is_superuser',
#                   'manual_created_date', 'watched_issues_count')
#         detailed_fields = ('created_at', '_obj_name', 'email', 'contract', 'solving_issue', 'first_name', 'last_name',
#                            'watched_issues__name', 'watched_issues__id', 'manual_created_date')
#         general_fields = ('email', 'first_name', 'last_name', 'watched_issues__name', 'watched_issues__id',
#                           'manual_created_date', 'watched_issues_count')
#         direct_serialization_fields = ('created_at', 'email', 'contract', 'solving_issue', 'first_name', 'last_name',
#                                        'manual_created_date')
#         order_fields = ('email', 'solving_issue', 'watched_issues_count')
#         extra_order_fields = ('created_at',)
#         filter_fields = ('email', 'first_name', 'last_name', 'is_superuser', 'created_issues', 'watched_issues_count')
#         extra_filter_fields = ('created_at',)


from pyston.serializer import Serializable, SerializableObj
from .models import User



class CountIssuesPerUserTable(Serializable):

    def serialize(self, serialization_format, **kwargs):
        return [
            {
                'email': user.email,
                'created_issues_count': user.created_issues.count(),
            }
            for user in User.objects.all()
        ]


class CountWatchersPerIssue(SerializableObj):

    def __init__(self, issue):

# Path: pyston/serializer.py
# class Serializable:
# 
#     def serialize(self, serialization_format, **kwargs):
#         raise NotImplementedError
# 
# class SerializableObj(Serializable, metaclass=SerializableObjMetaClass):
# 
#     resource_typemapper = {}
# 
#     def _get_value(self, field, serialization_format, request, **kwargs):
#         val = getattr(self, field)
#         return get_serializer(
#             val, request=request, resource_typemapper=self.resource_typemapper
#         ).serialize(val, serialization_format, **kwargs)
# 
#     def serialize(self, serialization_format, request=None, requested_fieldset=None, **kwargs):
#         return {
#             field_name: self._get_value(
#                 field_name,
#                 serialization_format,
#                 request,
#                 requested_fieldset=requested_fieldset.get(field_name).subfieldset if requested_fieldset else None,
#                 **kwargs
#             )
#             for field_name in self.get_fields()
#             if not requested_fieldset or field_name in requested_fieldset
#         }
# 
#     def get_fields(self):
#         return self.RestMeta.fields
# 
# Path: example/dj/apps/app/models.py
# class User(models.Model):
# 
#     created_at = models.DateTimeField(verbose_name=_('created at'), null=False, blank=False, auto_now_add=True)
#     email = models.EmailField(verbose_name=_('email'), null=False, blank=False, unique=True,
#                               filter=OnlyContainsStringFieldFilter)
#     contract = models.FileField(_('file'), null=True, blank=True, upload_to='documents/')
#     is_superuser = models.BooleanField(_('is superuser'), default=True)
#     first_name = models.CharField(_('first name'), null=True, blank=True, max_length=100)
#     last_name = models.CharField(_('last name'), null=True, blank=True, max_length=100)
#     manual_created_date = models.DateTimeField(verbose_name=_('manual created date'), null=True, blank=True)
# 
#     @filter_class(WatchedIssuesCountMethodFilter)
#     @sorter_class(WatchedIssuesCountSorter)
#     def watched_issues_count(self):
#         return self.watched_issues.count()
# 
#     def __str__(self):
#         return 'user: %s' % self.email
# 
#     class RestMeta:
#         fields = ('created_at', 'email', 'contract', 'solving_issue', 'first_name', 'last_name', 'is_superuser',
#                   'manual_created_date', 'watched_issues_count')
#         detailed_fields = ('created_at', '_obj_name', 'email', 'contract', 'solving_issue', 'first_name', 'last_name',
#                            'watched_issues__name', 'watched_issues__id', 'manual_created_date')
#         general_fields = ('email', 'first_name', 'last_name', 'watched_issues__name', 'watched_issues__id',
#                           'manual_created_date', 'watched_issues_count')
#         direct_serialization_fields = ('created_at', 'email', 'contract', 'solving_issue', 'first_name', 'last_name',
#                                        'manual_created_date')
#         order_fields = ('email', 'solving_issue', 'watched_issues_count')
#         extra_order_fields = ('created_at',)
#         filter_fields = ('email', 'first_name', 'last_name', 'is_superuser', 'created_issues', 'watched_issues_count')
#         extra_filter_fields = ('created_at',)


# Path: example/dj/apps/app/serializable.py
from pyston.serializer import Serializable, SerializableObj
from .models import User




class CountIssuesPerUserTable(Serializable):

    def serialize(self, serialization_format, **kwargs):
        return [
            {
                'email': user.email,
                'created_issues_count': user.created_issues.count(),
            }
            for user in User.objects.all()
        ]


class CountWatchersPerIssue(SerializableObj):

    def __init__(self, issue):

        super(SerializableObj, self).__init__()