-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #92 Display comittee member information as per requirement #103
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -346,6 +348,43 @@ 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. | ||
""" | ||
incharges = [] | ||
|
||
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 | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only troubling part. The committee slug will be different for different levels. The Role for Incharge could be different as well. I think it is better to take it from a config setting or the first available committee. Lets have a function to get the committee name and role. That'll return first available committee and first role from that, unless a config setting is specified. Lets use Also, In python it is idiomatic to use list comprehensions instead of map/filter. The usual practice is:
|
||
def get_committee(self, slug, _create=True): | ||
"""Returns a committee with given slug. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{% extends "admin/index.html" %} | ||
|
||
{% block subnav %} | ||
{{ subnav(place, tab="committees") }} | ||
{% endblock %} | ||
|
||
{% block page_content %} | ||
<h2>Committees</h2> | ||
{% set committees = place.get_committees() %} | ||
{% if committees %} | ||
<ul class="list-group committees"> | ||
{% for c in place.get_committees() %} | ||
<li class="list-group-item"><a href="{{ url_for('committees.view_committee', key=place.key, slug=c.type.slug) }}">{{c.type.name}}</a></li> | ||
|
||
<div class="committee-members"> | ||
{% for role, members in c.get_members() %} | ||
{% if members %} | ||
<div class="committee-role"> | ||
<h4>{{role.role}}</h4> | ||
{% for m in members %} | ||
{{widget("VolunteerCard", volunteer=m)}} | ||
{% endfor %} | ||
</div> | ||
{% endif %} | ||
{% endfor %} | ||
</div> | ||
|
||
|
||
{% endfor %} | ||
</ul> | ||
{% else %} | ||
<em>No committes are available at {{place.type.name}} level.</em> | ||
{% endif %} | ||
{% endblock %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
com.types.roles.pop()
looks a bit scary.com.types.roles[0]
is safer I think.Don't worry, I'll take care of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anandology I think I tried that, but its was throwing some errors, as it was not an array some custom form for list.