# Path: memopol/meps/models.py
# class OrganizationMEP(TimePeriod):
#     mep = models.ForeignKey(MEP)
#     organization = models.ForeignKey(Organization)
#     role = models.CharField(max_length=255)
# 
#     @reify
#     def instance(self):
#         return self.organization
# 
# class CommitteeRole(TimePeriod):
#     mep = models.ForeignKey(MEP)
#     committee = models.ForeignKey(Committee)
#     role = models.CharField(max_length=255)
# 
#     @reify
#     def instance(self):
#         return self.committee
# 
#     def __unicode__(self):
#         return u"%s : %s" % (self.committee.abbreviation, self.mep.full_name)
# 
# class DelegationRole(TimePeriod):
#     mep = models.ForeignKey(MEP)
#     delegation = models.ForeignKey(Delegation)
#     role = models.CharField(max_length=255)
# 
#     @reify
#     def instance(self):
#         return self.delegation
# 
#     def __unicode__(self):
#         return u"%s : %s" % (self.mep.full_name, self.delegation)


from django import template
from memopol.meps.models import OrganizationMEP, CommitteeRole, DelegationRole


register = template.Library()


@register.simple_tag
def current_organization_role(mep, organization):
    roles = OrganizationMEP.objects.filter(mep=mep, organization=organization)
    roles = sorted([role.role for role in roles if role.role != 'Member'])
    return roles and roles[0] or ''


@register.simple_tag
def current_committee_role(mep, committee):
    roles = CommitteeRole.objects.filter(mep=mep, committee=committee)
    roles = sorted([role.role for role in roles if role.role != 'Member'])

# Path: memopol/meps/models.py
# class OrganizationMEP(TimePeriod):
#     mep = models.ForeignKey(MEP)
#     organization = models.ForeignKey(Organization)
#     role = models.CharField(max_length=255)
# 
#     @reify
#     def instance(self):
#         return self.organization
# 
# class CommitteeRole(TimePeriod):
#     mep = models.ForeignKey(MEP)
#     committee = models.ForeignKey(Committee)
#     role = models.CharField(max_length=255)
# 
#     @reify
#     def instance(self):
#         return self.committee
# 
#     def __unicode__(self):
#         return u"%s : %s" % (self.committee.abbreviation, self.mep.full_name)
# 
# class DelegationRole(TimePeriod):
#     mep = models.ForeignKey(MEP)
#     delegation = models.ForeignKey(Delegation)
#     role = models.CharField(max_length=255)
# 
#     @reify
#     def instance(self):
#         return self.delegation
# 
#     def __unicode__(self):
#         return u"%s : %s" % (self.mep.full_name, self.delegation)


# Path: memopol/meps/templatetags/meps_role.py
from django import template
from memopol.meps.models import OrganizationMEP, CommitteeRole, DelegationRole



register = template.Library()


@register.simple_tag
def current_organization_role(mep, organization):
    roles = OrganizationMEP.objects.filter(mep=mep, organization=organization)
    roles = sorted([role.role for role in roles if role.role != 'Member'])
    return roles and roles[0] or ''


@register.simple_tag
def current_committee_role(mep, committee):
    roles = CommitteeRole.objects.filter(mep=mep, committee=committee)
    roles = sorted([role.role for role in roles if role.role != 'Member'])

    return roles and roles[0] or ''