# Path: lametro/models.py
# class LAMetroPerson(Person, SourcesMixin):
# 
#     class Meta:
#         proxy = True
# 
#     @property
#     def latest_council_membership(self):
#         filter_kwarg = {'organization__name': settings.OCD_CITY_COUNCIL_NAME,}
#         city_council_memberships = self.memberships.filter(**filter_kwarg)
# 
#         # Select posts denoting membership, i.e., exclude leadership
#         # posts, like 1st Chair.
#         # See: https://github.com/opencivicdata/python-opencivicdata/issues/129
#         #
#         # N.b., the CEO is not *technically* a member of the board, but their
#         # role is on the membership side of the membership/leadership dichotomy.
#         # See: https://github.com/datamade/la-metro-councilmatic/issues/351
#         primary_memberships = city_council_memberships.filter(Q(role='Chief Executive Officer') |
#                                                               Q(role='Board Member') |
#                                                               Q(role='Nonvoting Board Member'))
# 
#         if primary_memberships.exists():
#             return primary_memberships.order_by('-end_date').first()
#         return None
# 
#     @property
#     def current_district(self):
#         m = self.latest_council_membership
#         if m and m.post:
#             return m.post.label
#         return ''
# 
#     @property
#     def board_office(self):
#         office_roles = ('Chair', '1st Chair', 'Vice Chair', '1st Vice Chair', '2nd Chair', '2nd Vice Chair')
# 
#         try:
#             office_membership = self.memberships\
#                                     .filter(organization__name=settings.OCD_CITY_COUNCIL_NAME,
#                                             role__in=office_roles)\
#                                     .get(end_date_dt__gt=Now())
#         except Membership.DoesNotExist:
#             office_membership = None
# 
#         return office_membership
# 
#     @cached_property
#     def committee_sponsorships(self):
#         '''
#         This property returns a list of five bills, which have recent actions
#         from the organizations that the person has memberships in.
# 
#         Organizations do not include the Board of Directors.
#         '''
#         qs = LAMetroBill.objects\
#             .defer('extras')\
#             .filter(actions__organization__classification='committee',
#                     actions__organization__memberships__in=self.current_memberships)\
#             .order_by('-actions__date')\
#             .distinct()[:5]
# 
#         return qs
# 
#     @classmethod
#     def ceo(cls):
#         try:
#             ceo = Membership.objects\
#                 .get(post__role='Chief Executive Officer',
#                      end_date_dt__gt=Now())\
#                 .person
#         except Membership.DoesNotExist:
#             ceo = None
# 
#         return ceo
# 
#     @property
#     def headshot_url(self):
#         if self.slug in settings.MANUAL_HEADSHOTS:
#             image_url = 'images/' + settings.MANUAL_HEADSHOTS[self.slug]['image']
#         elif self.headshot:
#             image_url = self.headshot.url
#         else:
#             image_url = 'images/headshot_placeholder.png'
# 
#         return static(image_url)


from django.urls import reverse, reverse_lazy
from django.utils.feedgenerator import Rss201rev2Feed
from django.conf import settings
from councilmatic_core.feeds import PersonDetailFeed
from councilmatic_core.models import Person
from lametro.models import LAMetroPerson



class LAMetroPersonDetailFeed(PersonDetailFeed):
    """The PersonDetailFeed provides an RSS feed for a given committee member,
    returning the most recent 20 bills for which they are the primary sponsor;
    and for each bill, the list of sponsores and the action history.
    """

    model = LAMetroPerson

    def get_object(self, request, slug):

# Path: lametro/models.py
# class LAMetroPerson(Person, SourcesMixin):
# 
#     class Meta:
#         proxy = True
# 
#     @property
#     def latest_council_membership(self):
#         filter_kwarg = {'organization__name': settings.OCD_CITY_COUNCIL_NAME,}
#         city_council_memberships = self.memberships.filter(**filter_kwarg)
# 
#         # Select posts denoting membership, i.e., exclude leadership
#         # posts, like 1st Chair.
#         # See: https://github.com/opencivicdata/python-opencivicdata/issues/129
#         #
#         # N.b., the CEO is not *technically* a member of the board, but their
#         # role is on the membership side of the membership/leadership dichotomy.
#         # See: https://github.com/datamade/la-metro-councilmatic/issues/351
#         primary_memberships = city_council_memberships.filter(Q(role='Chief Executive Officer') |
#                                                               Q(role='Board Member') |
#                                                               Q(role='Nonvoting Board Member'))
# 
#         if primary_memberships.exists():
#             return primary_memberships.order_by('-end_date').first()
#         return None
# 
#     @property
#     def current_district(self):
#         m = self.latest_council_membership
#         if m and m.post:
#             return m.post.label
#         return ''
# 
#     @property
#     def board_office(self):
#         office_roles = ('Chair', '1st Chair', 'Vice Chair', '1st Vice Chair', '2nd Chair', '2nd Vice Chair')
# 
#         try:
#             office_membership = self.memberships\
#                                     .filter(organization__name=settings.OCD_CITY_COUNCIL_NAME,
#                                             role__in=office_roles)\
#                                     .get(end_date_dt__gt=Now())
#         except Membership.DoesNotExist:
#             office_membership = None
# 
#         return office_membership
# 
#     @cached_property
#     def committee_sponsorships(self):
#         '''
#         This property returns a list of five bills, which have recent actions
#         from the organizations that the person has memberships in.
# 
#         Organizations do not include the Board of Directors.
#         '''
#         qs = LAMetroBill.objects\
#             .defer('extras')\
#             .filter(actions__organization__classification='committee',
#                     actions__organization__memberships__in=self.current_memberships)\
#             .order_by('-actions__date')\
#             .distinct()[:5]
# 
#         return qs
# 
#     @classmethod
#     def ceo(cls):
#         try:
#             ceo = Membership.objects\
#                 .get(post__role='Chief Executive Officer',
#                      end_date_dt__gt=Now())\
#                 .person
#         except Membership.DoesNotExist:
#             ceo = None
# 
#         return ceo
# 
#     @property
#     def headshot_url(self):
#         if self.slug in settings.MANUAL_HEADSHOTS:
#             image_url = 'images/' + settings.MANUAL_HEADSHOTS[self.slug]['image']
#         elif self.headshot:
#             image_url = self.headshot.url
#         else:
#             image_url = 'images/headshot_placeholder.png'
# 
#         return static(image_url)


# Path: lametro/feeds.py
from django.urls import reverse, reverse_lazy
from django.utils.feedgenerator import Rss201rev2Feed
from django.conf import settings
from councilmatic_core.feeds import PersonDetailFeed
from councilmatic_core.models import Person
from lametro.models import LAMetroPerson




class LAMetroPersonDetailFeed(PersonDetailFeed):
    """The PersonDetailFeed provides an RSS feed for a given committee member,
    returning the most recent 20 bills for which they are the primary sponsor;
    and for each bill, the list of sponsores and the action history.
    """

    model = LAMetroPerson

    def get_object(self, request, slug):

        o = LAMetroPerson.objects.get(slug=slug)