[open-ils-commits] r910 - in servres/trunk/conifer: syrup syrup/views templates (gfawcett)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Jul 14 20:54:15 EDT 2010
Author: gfawcett
Date: 2010-07-14 20:54:14 -0400 (Wed, 14 Jul 2010)
New Revision: 910
Modified:
servres/trunk/conifer/syrup/models.py
servres/trunk/conifer/syrup/views/sites.py
servres/trunk/conifer/templates/edit_site.xhtml
Log:
partially-working site-creation
The permissions page is still messed up; and the creation UI is
awful. But it does generate a Site instance.
Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py 2010-07-15 00:54:04 UTC (rev 909)
+++ servres/trunk/conifer/syrup/models.py 2010-07-15 00:54:14 UTC (rev 910)
@@ -166,8 +166,8 @@
passkey = m.CharField(db_index=True, blank=True, null=True, max_length=256)
def __unicode__(self):
- cc = '%s' % (', '.join([c.code for c in self.courses]))
- tt = '(%s)' % (', '.join([t.code for t in self.terms]))
+ cc = '%s' % (', '.join([c.code for c in self.courses.all()]))
+ tt = '(%s)' % (', '.join([t.code for t in self.terms.all()]))
oo = '(%s)' % self.owner.last_name
return u'%s %s %s' % (cc, tt, oo)
@@ -265,9 +265,12 @@
registration."""
return user.is_authenticated() \
and self.access in ('ANON', 'LOGIN') \
- and not user.id == self.owner_id \
- and not self.members.filter(user=user).exists()
+ and not self.is_member(user)
+ def is_member(self, user):
+ assert user
+ return user.id == self.owner_id \
+ or self.members.filter(user=user).exists()
#------------------------------------------------------------
# User membership in sites
Modified: servres/trunk/conifer/syrup/views/sites.py
===================================================================
--- servres/trunk/conifer/syrup/views/sites.py 2010-07-15 00:54:04 UTC (rev 909)
+++ servres/trunk/conifer/syrup/views/sites.py 2010-07-15 00:54:14 UTC (rev 910)
@@ -67,7 +67,7 @@
site.generate_new_passkey()
site.save()
assert site.id
- user_in_site = models.Member.objects.filter(user=request.user,site=site)
+ user_in_site = site.is_member(request.user)
if not user_in_site: # for edits, might already be!
mbr = site.member_set.create(user=request.user, role='INSTR')
mbr.save()
@@ -122,9 +122,9 @@
instr = models.maybe_initialize_user(iname)
if instr:
try:
- return models.Member.objects.get(user=instr, site=site)
- except models.Member.DoesNotExist:
- return models.Member.objects.create(user=instr, site=site)
+ return models.Membership.objects.get(user=instr, site=site)
+ except models.Membership.DoesNotExist:
+ return models.Membership.objects.create(user=instr, site=site)
# add a new instructor
if iname:
@@ -144,12 +144,12 @@
for name in POST if name.startswith('instructor_remove_')]
for instr_id, newrole in to_change_role:
if not instr_id in to_remove:
- instr = models.Member.objects.get(pk=instr_id, site=site)
+ instr = models.Membership.objects.get(pk=instr_id, site=site)
instr.role = newrole
instr.save()
for instr_id in to_remove:
# todo, should warn if deleting yourself!
- instr = models.Member.objects.get(pk=instr_id, site=site)
+ instr = models.Membership.objects.get(pk=instr_id, site=site)
instr.delete()
# todo, should have some error-reporting.
return HttpResponseRedirect('.')
@@ -159,7 +159,7 @@
access = POST.get('access')
site.access = access
# drop all provided users. fixme, this could be optimized to do add/drops.
- models.Member.objects.filter(site=site, provided=True).delete()
+ models.Membership.objects.filter(site=site, provided=True).delete()
if site.access == u'STUDT':
initial_sections = site.sections()
# add the 'new section' if any
@@ -176,8 +176,8 @@
for name in student_names:
user = models.maybe_initialize_user(name)
if user:
- if not models.Member.objects.filter(site=site, user=user):
- mbr = models.Member.objects.create(
+ if not models.Membership.objects.filter(site=site, user=user):
+ mbr = models.Membership.objects.create(
site=site, user=user,
role='STUDT', provided=True)
mbr.save()
@@ -222,8 +222,8 @@
return g.render('site_invitation.xhtml', **locals())
# the passkey is good; add the user if not already a member.
- if not models.Member.objects.filter(user=request.user, site=crs):
- mbr = models.Member.objects.create(user=request.user, site=crs,
+ if not models.Membership.objects.filter(user=request.user, site=crs):
+ mbr = models.Membership.objects.create(user=request.user, site=crs,
role='STUDT')
mbr.save()
return HttpResponseRedirect(crs.site_url())
@@ -252,7 +252,7 @@
elif request.method != 'POST':
return g.render('site_join.xhtml', site=site)
else:
- mbr = models.Member.objects.create(user=request.user, site=site, role='STUDT')
+ mbr = models.Membership.objects.create(user=request.user, site=site, role='STUDT')
mbr.save()
return HttpResponseRedirect(site.site_url())
Modified: servres/trunk/conifer/templates/edit_site.xhtml
===================================================================
--- servres/trunk/conifer/templates/edit_site.xhtml 2010-07-15 00:54:04 UTC (rev 909)
+++ servres/trunk/conifer/templates/edit_site.xhtml 2010-07-15 00:54:14 UTC (rev 910)
@@ -30,10 +30,12 @@
</tr>
<h2>General description</h2>
<table class="metadata_table">
- ${field_row(form.code, example)}
- ${field_row(form.title)}
- ${field_row(form.term)}
- ${field_row(form.department)}
+ ${field_row(form.owner)}
+ ${field_row(form.terms)}
+ ${field_row(form.courses)}
+ ${field_row(form.service_desk)}
+
+ <!-- ${field_row(form.department)} -->
<!-- <tr><th>Department</th><td>${Markup(form.department)} ${errorlist(form.department)}</td></tr> -->
</table>
<p><input type="submit" value="Continue"/> ${go_back_link()}</p>
More information about the open-ils-commits
mailing list