Skip to content

Commit

Permalink
Implemented
Browse files Browse the repository at this point in the history
- Showing incharges for every children place, right away in the list.
- All the comittees and their memebers with contact info shown right away in comittees page.
  • Loading branch information
devilankur18 committed Sep 3, 2015
1 parent a73caf4 commit 9f84324
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
12 changes: 12 additions & 0 deletions cleansweep/committees/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,18 @@ 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]

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)
return incharges


def get_committee(self, slug, _create=True):
"""Returns a committee with given slug.
Expand Down
16 changes: 8 additions & 8 deletions cleansweep/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ class Place(db.Model, Mixable):

# List of parents
# Required to list immediate children on the place page
_parents = db.relationship('Place',
secondary=place_parents,
_parents = db.relationship('Place',
secondary=place_parents,
primaryjoin=(id==place_parents.c.child_id),
secondaryjoin=(id==place_parents.c.parent_id),
backref=db.backref('places', lazy='dynamic', order_by='Place.key'),
Expand All @@ -134,7 +134,7 @@ def get_toplevel_places():
"""
return Place.query.filter_by(iparent_id=None).all()

@property
@property
def code(self):
return self.key.split("/")[-1]

Expand Down Expand Up @@ -245,7 +245,7 @@ def _get_places_query(self, type=None):
def add_place(self, place):
"""Addes a new place as direct child of this place.
This function takes care of setting parents for the
This function takes care of setting parents for the
new place.
"""
# The place is being added as an immediate child of this node.
Expand All @@ -272,7 +272,7 @@ def get_siblings(self):
return Place.query.filter_by(type=self.type).all()

def get_child_places_by_type(self):
"""Returns an iterator over type and child-places of that type
"""Returns an iterator over type and child-places of that type
for all the immediate child places.
"""
places = self.child_places.all()
Expand All @@ -297,7 +297,7 @@ def add_member(self, name, email, phone, voterid=None):
"""
member = Member(self, name, email, phone, voterid)
db.session.add(member)
return member
return member


def get_pending_members(self, status='pending', limit=100, offset=0):
Expand Down Expand Up @@ -326,7 +326,7 @@ def add_contacts(self, data):
contacts = [
Contact(self, name, email, phone, voterid)
for name, email, phone, voterid in data
if name and name.strip()
if name and name.strip()
and email not in dup_emails
and phone not in dup_phones]
db.session.add_all(contacts)
Expand Down Expand Up @@ -516,7 +516,7 @@ class Contact(db.Model):
id = db.Column(db.Integer, primary_key=True)
place_id = db.Column(db.Integer, db.ForeignKey("place.id"), nullable=False, index=True)
place = db.relationship('Place', foreign_keys=place_id)

name = db.Column(db.Text, nullable=False)
email = db.Column(db.Text, index=True)
phone = db.Column(db.Text, index=True)
Expand Down
15 changes: 15 additions & 0 deletions cleansweep/templates/admin/committees.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ <h2>Committees</h2>
<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 %}
Expand Down
22 changes: 21 additions & 1 deletion cleansweep/templates/widgets/PlaceList.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,27 @@
<h3>{{ subtype.name | pluralize }}</h3>
<ul class="list-group">
{% for p in places %}
<li class="list-group-item"><a href="{{ url_for('place', key=p.key) }}">{{ p.name }}</a></li>
<li class="list-group-item">
<a href="{{ url_for('place', key=p.key) }}">
{{ p.name }}
</a>

<div class="incharges pull-right">
{% set incharges = p.get_incharges() %}
{% if incharges %}
{% for i in incharges%}
{% set member = i.member %}
<a href="{{ url_for('volunteers.profile', id=member.id , hash=member.get_hash())}}" target="_blank">
{{member.name}}
</a>
{% endfor %}
{% else %}
<em>None</em>
{% endif %}
</div>


</li>
{% endfor %}
</ul>
{% endfor %}
Expand Down

0 comments on commit 9f84324

Please sign in to comment.