[open-ils-commits] r1186 - servres/trunk/conifer/syrup (gfawcett)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Jan 10 19:47:42 EST 2011
Author: gfawcett
Date: 2011-01-10 19:47:41 -0500 (Mon, 10 Jan 2011)
New Revision: 1186
Modified:
servres/trunk/conifer/syrup/models.py
Log:
fix membership problems.
Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py 2011-01-11 00:35:36 UTC (rev 1185)
+++ servres/trunk/conifer/syrup/models.py 2011-01-11 00:47:41 UTC (rev 1186)
@@ -44,7 +44,7 @@
def sites(self, role=None):
self.maybe_refresh_external_memberships()
- sites = Site.objects.filter(group__membership__user=self.id)
+ sites = Site.objects.filter(group__membership__user=self.id).distinct()
if role:
sites = sites.filter(group__membership__role=role)
return sites
@@ -384,11 +384,8 @@
return False
if (user.id == self.owner_id) or user.is_staff:
return True
- try:
- mbr = self.members().get(user=user)
- except Membership.DoesNotExist:
- return False
- return mbr.role in (u'INSTR', u'ASSIST')
+ memberships = self.members().filter(user=user)
+ return any(mbr.role in (u'INSTR', u'ASSIST') for mbr in memberships)
def is_joinable_by(self, user):
"""Return True if the user could feasibly register into this
@@ -411,12 +408,11 @@
return False
if level == 'LOGIN':
return True
- try:
- mbr = self.members().get(user=user)
- except:
+ memberships = self.members().filter(user=user)
+ if not memberships:
return False
if level == 'CLOSE':
- return mbr.role == u'INSTR'
+ return any(mbr.role == u'INSTR' for mbr in memberships)
elif level == u'MEMBR':
return True
else:
More information about the open-ils-commits
mailing list