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)
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
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()
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:
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('.')
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
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()
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())
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())
</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>