[open-ils-commits] r930 - in servres/trunk/conifer: . integration/linktool integration/linktool/templates plumbing syrup syrup/views templates (gfawcett)
svn at svn.open-ils.org
svn at svn.open-ils.org
Sun Jul 18 21:35:57 EDT 2010
Author: gfawcett
Date: 2010-07-18 21:35:55 -0400 (Sun, 18 Jul 2010)
New Revision: 930
Added:
servres/trunk/conifer/integration/linktool/templates/
servres/trunk/conifer/integration/linktool/templates/index.xhtml
Modified:
servres/trunk/conifer/integration/linktool/app.py
servres/trunk/conifer/plumbing/genshi_support.py
servres/trunk/conifer/syrup/models.py
servres/trunk/conifer/syrup/views/general.py
servres/trunk/conifer/syrup/views/items.py
servres/trunk/conifer/syrup/views/search.py
servres/trunk/conifer/syrup/views/sites.py
servres/trunk/conifer/templates/edit_site.xhtml
servres/trunk/conifer/templates/edit_site_permissions.xhtml
servres/trunk/conifer/templates/my_sites.xhtml
servres/trunk/conifer/templates/site_detail.xhtml
servres/trunk/conifer/urls.py
Log:
reorg of site editing code; starting on smarter sakai-linktool integration
Modified: servres/trunk/conifer/integration/linktool/app.py
===================================================================
--- servres/trunk/conifer/integration/linktool/app.py 2010-07-16 19:56:52 UTC (rev 929)
+++ servres/trunk/conifer/integration/linktool/app.py 2010-07-19 01:35:55 UTC (rev 930)
@@ -1,14 +1,25 @@
-from django.contrib.auth import authenticate, login
-from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden
+from conifer.syrup.views._common import *
+from django.contrib.auth import authenticate, login
+from conifer.syrup import models
+from conifer.syrup.views import genshi_namespace
+from conifer.plumbing.genshi_support import TemplateSet
+g = TemplateSet([HERE('integration/linktool/templates'),
+ HERE('templates')],
+ genshi_namespace)
-def linktool_welcome(request):
+
+def linktool_welcome(request, command=u''):
+ #return g.render('index.xhtml')
user = authenticate(request=request)
if user is None:
return HttpResponseForbidden('You are not allowed here.')
else:
login(request, user)
- request.session['clew-site'] = request.GET['site']
+ extsite = request.session['clew-site'] = request.GET['site']
+ extrole = request.session['clew-role'] = request.GET['role']
+
+
return HttpResponse("""<html><head/><body onload="top.location='%s';">"""
"""Redirecting to the library reserves system...</body></html>""" % (
- request.META['SCRIPT_NAME']))
+ request.META['SCRIPT_NAME'] or '/'))
Added: servres/trunk/conifer/integration/linktool/templates/index.xhtml
===================================================================
--- servres/trunk/conifer/integration/linktool/templates/index.xhtml (rev 0)
+++ servres/trunk/conifer/integration/linktool/templates/index.xhtml 2010-07-19 01:35:55 UTC (rev 930)
@@ -0,0 +1,11 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:py="http://genshi.edgewall.org/">
+<xi:include href="master.xhtml"/>
+<head>
+ <title>testing</title>
+</head>
+<body>
+<h1>testing</h1>
+</body>
+</html>
Modified: servres/trunk/conifer/plumbing/genshi_support.py
===================================================================
--- servres/trunk/conifer/plumbing/genshi_support.py 2010-07-16 19:56:52 UTC (rev 929)
+++ servres/trunk/conifer/plumbing/genshi_support.py 2010-07-19 01:35:55 UTC (rev 930)
@@ -33,12 +33,19 @@
def __init__(self, basedir, namespace_module=None):
self.basedir = basedir
- self.dirs = [self.basedir]
+ if isinstance(basedir, list):
+ self.dirs = basedir
+ else:
+ self.dirs = [self.basedir]
self.loader = TemplateLoader(self.dirs,
auto_reload=True,
callback=self.template_loaded)
- self.namespace_module = namespace_module
+ if hasattr(namespace_module, '__dict__'):
+ self.namespace_module = namespace_module.__dict__
+ else:
+ self.namespace_module = namespace_module
+
def file(self, name):
fn = os.path.join(self.basedir, name)
assert os.path.dirname(fn) == self.basedir
@@ -62,7 +69,7 @@
if not 'errors' in ns:
ns['errors'] = None
if self.namespace_module is not None:
- ns.update(self.namespace_module.__dict__)
+ ns.update(self.namespace_module)
def render(self, tname, **kwargs):
request = get_request()
Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py 2010-07-16 19:56:52 UTC (rev 929)
+++ servres/trunk/conifer/syrup/models.py 2010-07-19 01:35:55 UTC (rev 930)
@@ -160,7 +160,7 @@
service_desk = m.ForeignKey(ServiceDesk)
access = m.CharField(max_length=5,
- default='LOGIN',
+ default='ANON',
choices = [
('ANON', _('World-accessible')),
('LOGIN', _('Accessible to all logged-in users')),
@@ -169,7 +169,7 @@
class Meta:
unique_together = (('course', 'term', 'owner'))
- ordering = ['-term__start', 'course__code']
+ ordering = ['-term__start', 'course__code', 'owner__last_name']
def save(self, *args, **kwargs):
# Ensure there is always an internal Group.
@@ -538,7 +538,7 @@
def parent_url(self, suffix=''):
if self.parent_heading:
- return self.parent_heading.item_url()
+ return self.parent_heading.item_url() + suffix
else:
return self.site.site_url()
Modified: servres/trunk/conifer/syrup/views/general.py
===================================================================
--- servres/trunk/conifer/syrup/views/general.py 2010-07-16 19:56:52 UTC (rev 929)
+++ servres/trunk/conifer/syrup/views/general.py 2010-07-19 01:35:55 UTC (rev 930)
@@ -111,9 +111,6 @@
page_num=page_num,
count=count)
- at login_required
-def my_sites(request):
- return g.render('my_sites.xhtml')
def instructor_detail(request, instructor_id):
page_num = int(request.GET.get('page', 1))
Modified: servres/trunk/conifer/syrup/views/items.py
===================================================================
--- servres/trunk/conifer/syrup/views/items.py 2010-07-16 19:56:52 UTC (rev 929)
+++ servres/trunk/conifer/syrup/views/items.py 2010-07-19 01:35:55 UTC (rev 930)
@@ -123,10 +123,7 @@
else:
raise NotImplementedError
- if parent_item:
- return HttpResponseRedirect(parent_item.item_url('meta'))
- else:
- return HttpResponseRedirect(site.site_url())
+ return HttpResponseRedirect(item.parent_url())
@instructors_only
def item_add_cat_search(request, site_id, item_id):
@@ -207,8 +204,9 @@
marcxml=raw_pickitem,
**dct)
item.save()
- return HttpResponseRedirect('../../../%d/meta' % item.id)
+ return HttpResponseRedirect(item.parent_url())
+
#------------------------------------------------------------
@instructors_only
@@ -244,12 +242,9 @@
if 'yes' in request.POST:
# I think Django's ON DELETE CASCADE-like behaviour will
# take care of the sub-items.
- if item.parent_heading:
- redir = HttpResponseRedirect(item.parent_heading.item_url('meta'))
- else:
- redir = HttpResponseRedirect(site.site_url())
+ redir = item.parent_url('meta')
item.delete()
- return redir
+ return HttpResponseRedirect(redir)
else:
return HttpResponseRedirect('../meta')
Modified: servres/trunk/conifer/syrup/views/search.py
===================================================================
--- servres/trunk/conifer/syrup/views/search.py 2010-07-16 19:56:52 UTC (rev 929)
+++ servres/trunk/conifer/syrup/views/search.py 2010-07-19 01:35:55 UTC (rev 930)
@@ -141,7 +141,8 @@
if not query_string: # empty query?
if in_site:
- return HttpResponseRedirect(reverse('site_detail', in_site))
+ return HttpResponseRedirect(reverse('site_detail',
+ kwargs={'site_id': in_site}))
else:
return HttpResponseRedirect(reverse('browse'))
else:
Modified: servres/trunk/conifer/syrup/views/sites.py
===================================================================
--- servres/trunk/conifer/syrup/views/sites.py 2010-07-16 19:56:52 UTC (rev 929)
+++ servres/trunk/conifer/syrup/views/sites.py 2010-07-19 01:35:55 UTC (rev 930)
@@ -9,18 +9,12 @@
model = models.Site
exclude = ('access',)
- def clean_code(self):
- v = (self.cleaned_data.get('code') or '').strip()
- is_valid_func = gethook('course_code_is_valid')
- if (not is_valid_func) or is_valid_func(v):
- return v
- else:
- raise ValidationError, _('invalid course code')
-
def __init__(self, *args, **kwargs):
owner = self.base_fields['owner']
- owner.label_from_instance = lambda u: u.get_list_name()
- owner.queryset = User.objects.order_by('last_name', 'first_name', 'username')
+ owner.label_from_instance = lambda u: '%s (%s)' % (
+ u.get_list_name(), u.username)
+ owner.queryset = User.objects.order_by('last_name', 'first_name',
+ 'username')
super(NewSiteForm, self).__init__(*args, **kwargs)
@@ -42,7 +36,6 @@
is_add = (instance is None)
if is_add:
instance = models.Site()
- current_access_level = not is_add and instance.access or None
if request.method != 'POST':
form = NewSiteForm(instance=instance)
return g.render('edit_site.xhtml', **locals())
@@ -55,7 +48,7 @@
site = form.instance
assert site.id
- if is_add or (current_access_level != site.access):
+ if is_add:
# we need to configure permissions.
return HttpResponseRedirect(site.site_url('edit/permission/'))
else:
@@ -74,94 +67,31 @@
]
choose_access = django.forms.RadioSelect(choices=choices)
-
+
if request.method != 'POST':
return g.render('edit_site_permissions.xhtml', **locals())
else:
POST = request.POST
+ access = POST.get('access')
+ site.access = access
+ site.save()
- if 'action_save_instructor' in POST:
- # update instructor details ----------------------------------
- iname = POST.get('new_instructor_name','').strip()
- irole = POST.get('new_instructor_role')
+ return HttpResponseRedirect('../../')
- def get_record_for(username):
- instr = models.maybe_initialize_user(iname)
- if instr:
- try:
- 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:
- instr = get_record_for(iname)
- if instr: # else? should have an error.
- instr.role = irole
- instr.save()
- else:
- instructor_error = 'No such user: %s' % iname
- return g.render('edit_site_permissions.xhtml', **locals())
-
-
- # removing and changing roles of instructors
- to_change_role = [(int(name.rsplit('_', 1)[-1]), POST[name]) \
- for name in POST if name.startswith('instructor_role_')]
- to_remove = [int(name.rsplit('_', 1)[-1]) \
- 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.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.Membership.objects.get(pk=instr_id, site=site)
- instr.delete()
- # todo, should have some error-reporting.
- return HttpResponseRedirect('.')
-
- elif 'action_save_student' in POST:
- # update student details ------------------------------------
- access = POST.get('access')
- site.access = access
- # drop all provided users. fixme, this could be optimized to do add/drops.
- #models.Membership.objects.filter(site=site, provided=True).delete()
- if site.access == u'STUDT':
- initial_sections = site.sections()
- # add the 'new section' if any
- new_sec = request.POST.get('add_section')
- new_sec = models.section_decode_safe(new_sec)
- if new_sec:
- site.add_sections(new_sec)
- # remove the sections to be dropped
- to_remove = [models.section_decode_safe(name.rsplit('_',1)[1]) \
- for name in POST \
- if name.startswith('remove_section_')]
- site.drop_sections(*to_remove)
- student_names = models.campus.students_in(*site.sections())
- for name in student_names:
- user = models.maybe_initialize_user(name)
- if user:
- 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()
- else:
- pass
- site.save()
- return HttpResponseRedirect('.#student_access')
-
@instructors_only
def delete_site(request, site_id):
site = get_object_or_404(models.Site, pk=site_id)
if request.POST.get('confirm_delete'):
site.delete()
- return HttpResponseRedirect(reverse('my_sites'))
+ return HttpResponseRedirect(reverse(my_sites))
else:
return HttpResponseRedirect('../')
+
+ at login_required
+def my_sites(request):
+ return g.render('my_sites.xhtml')
+
#-----------------------------------------------------------------------------
# Site Invitation Code handler
@@ -188,13 +118,13 @@
site = get_object_or_404(models.Site, pk=site_id)
if not site.is_joinable_by(request.user):
# user should never see this.
- return simple_message(_('You cannot join this site.'),
- _('Sorry, but you cannot join this site at this time.'))
+ return simple_message(_('You cannot join this site.'),
+ _('Sorry, but you cannot join this site '
+ 'at this time.'))
elif request.method != 'POST':
return g.render('site_join.xhtml', site=site)
else:
- mbr = models.Membership.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-16 19:56:52 UTC (rev 929)
+++ servres/trunk/conifer/templates/edit_site.xhtml 2010-07-19 01:35:55 UTC (rev 930)
@@ -1,6 +1,6 @@
<?python
if instance.id:
- title = _('Configure this site')
+ title = _('Site setup')
else:
title = _('Create a new site')
?>
@@ -16,7 +16,6 @@
<body>
<div py:if="instance.id">${site_banner(instance)}</div>
<h1>${title}</h1>
- <p py:if="instance.id"><a href="permission/">Edit site permissions</a> • <a href="${instance.site_url()}">Return to site page</a></p>
<div py:with="nfe=form.non_field_errors()">
<ul py:if="nfe" class="errorlist">
<li py:for="err in nfe">${err}</li>
@@ -33,7 +32,6 @@
</td>
<td class="example" py:if="example">e.g., ${example}</td>
</tr>
- <h2>General description</h2>
<table class="metadata_table">
${field_row(form.owner)}
${field_row(form.term)}
Modified: servres/trunk/conifer/templates/edit_site_permissions.xhtml
===================================================================
--- servres/trunk/conifer/templates/edit_site_permissions.xhtml 2010-07-16 19:56:52 UTC (rev 929)
+++ servres/trunk/conifer/templates/edit_site_permissions.xhtml 2010-07-19 01:35:55 UTC (rev 930)
@@ -1,5 +1,5 @@
<?python
-title = _('Edit site permissions')
+title = _('Site permissions')
instructors = site.get_instructors()
members = models.Membership.objects.select_related().filter(group__site=site).order_by('user__last_name', 'user__first_name')
extgroups = site.group_set.filter(external_id__isnull=False)
@@ -19,12 +19,11 @@
<body>
${site_banner(site)}
<h1>${title}</h1>
- <p><a href="../">Edit site details</a> • <a href="${site.site_url()}">Return to site page</a></p>
<form action="." method="POST">
- <h2>Site Access Level</h2>
<p>Who has permission to view resources in this site?</p>
<div id="access_level" style="margin-left: 12;">${Markup(choose_access.render('access', site.access, {'id':'id_access'}, []))}</div>
- <p><input type="submit" name="action_save_student" value="Save changes to student access"/></p>
+ <p><input type="submit" name="action_access_level" value="Change access level"/>
+ ${go_back_link()}</p>
<h2>Current Membership</h2>
<table class="pagetable" style="width: 100%;">
Modified: servres/trunk/conifer/templates/my_sites.xhtml
===================================================================
--- servres/trunk/conifer/templates/my_sites.xhtml 2010-07-16 19:56:52 UTC (rev 929)
+++ servres/trunk/conifer/templates/my_sites.xhtml 2010-07-19 01:35:55 UTC (rev 930)
@@ -18,12 +18,12 @@
?>
<p py:if="not my_sites">You are not part of any course-reserve sites at this time.</p>
<p py:for="site in my_sites" style="font-size: large;">
- <a href="${site.id}/">${site.list_display()}</a>
+ <a href="${site.id}/">${site}</a>
</p>
<div class="gap"/>
<div class="itemadd">
<p py:if="user.can_create_sites()"><a href="new/">Create a new course-reserves site</a></p>
- <p><a href="invitation/">Join a reserves list using an Invitation Code</a></p>
+ <!-- !<p><a href="invitation/">Join a reserves list using an Invitation Code</a></p> -->
</div>
</body>
</html>
Modified: servres/trunk/conifer/templates/site_detail.xhtml
===================================================================
--- servres/trunk/conifer/templates/site_detail.xhtml 2010-07-16 19:56:52 UTC (rev 929)
+++ servres/trunk/conifer/templates/site_detail.xhtml 2010-07-19 01:35:55 UTC (rev 930)
@@ -17,7 +17,8 @@
${site_banner(site)}
<div id="sidepanel">
<div py:if="is_editor" id="edit_site" class="little_action_panel">
- <a href="${site.site_url()}edit/">Configure site</a>
+ <div><a href="${site.site_url()}edit/">Setup</a></div>
+ <div><a href="${site.site_url()}edit/permission/">Permissions</a></div>
</div>
<div py:if="is_joinable">
<a href="${site.site_url()}join/">Join this site</a>
Modified: servres/trunk/conifer/urls.py
===================================================================
--- servres/trunk/conifer/urls.py 2010-07-16 19:56:52 UTC (rev 929)
+++ servres/trunk/conifer/urls.py 2010-07-19 01:35:55 UTC (rev 930)
@@ -42,5 +42,5 @@
if settings.LINKTOOL_AUTHENTICATION:
urlpatterns += patterns(
'conifer.integration.linktool.app',
- (r'^linktool-welcome/$', 'linktool_welcome'))
+ (r'^linktool-welcome/(?P<command>.*)$', 'linktool_welcome'))
More information about the open-ils-commits
mailing list