Skip to content

Commit

Permalink
Updated the logic to select primary committe and primary role
Browse files Browse the repository at this point in the history
  • Loading branch information
devilankur18 committed Sep 11, 2015
1 parent a55e336 commit 6751d09
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions cleansweep/committees/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from ..models import db, Place, place_parents, PlaceType, Member, Place
from collections import defaultdict
from flask import url_for
from ..app import app


class CommitteeType(db.Model):
"""Specification of a Committee.
Expand Down Expand Up @@ -346,15 +348,40 @@ def get_committee(type):
return type.committees.filter_by(place_id=self.id).first() or Committee(self, type)
return [get_committee(type) for type in committee_types]

# Current there is no way to identify primary committee
# So we are predecting it as follows
# For a place, at it level, if any slug is defined in app config, we try to get a valid committe from it.
# else get the first defined committee for that place.

def get_primary_committee(self):
"""Returns primary commitee for a place.
"""
committee_slug = app.config.get("%s_MASTER_COMMITTEE" % self.type.short_name.upper(), '')
c = self.get_committee(committee_slug)

# If stale committee or not found, get first committee
if not c or not c.committee_members:
all_committees = self.committees.all()

if len(all_committees) > 0:
c = all_committees[0]
else:
c = None

return c


def get_incharges(self):
"""Returns incharge at a given place.
"""
committee_slug = u'incharges'
incharges = []
c = self.get_committee(committee_slug)

if c and c.committee_members:
incharges = filter(lambda m: m.role.role == u'Incharges', c.committee_members)
com = self.get_primary_committee()

if com:
committee_role_slug = app.config.get("%s_MASTER_COMMITTEE_ROLE" % self.type.short_name.upper(), com.type.roles.pop().role)
incharges = [m for m in com.committee_members if m.role.role == committee_role_slug]

return incharges


Expand Down

0 comments on commit 6751d09

Please sign in to comment.