partially-working site-creation
authorgfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Thu, 15 Jul 2010 00:54:14 +0000 (00:54 +0000)
committergfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Thu, 15 Jul 2010 00:54:14 +0000 (00:54 +0000)
The permissions page is still messed up; and the creation UI is
awful. But it does generate a Site instance.

git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@910 6d9bc8c9-1ec2-4278-b937-99fde70a366f

conifer/syrup/models.py
conifer/syrup/views/sites.py
conifer/templates/edit_site.xhtml

index 93ec273..2b30d17 100644 (file)
@@ -166,8 +166,8 @@ class Site(BaseModel):
     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 @@ class Site(BaseModel):
         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
index f95c96b..f8029ca 100644 (file)
@@ -67,7 +67,7 @@ def _add_or_edit_site(request, instance=None):
                 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 @@ def edit_site_permissions(request, site_id):
                 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 @@ def edit_site_permissions(request, site_id):
                              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 @@ def edit_site_permissions(request, site_id):
             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 @@ def edit_site_permissions(request, site_id):
                 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 @@ def site_invitation(request):
             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 @@ def site_join(request, site_id):
     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())
 
index e85e654..f6d9842 100644 (file)
@@ -30,10 +30,12 @@ else:
     </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>