-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 '/'))
--- /dev/null
+<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>
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)
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()
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')),
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.
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()
page_num=page_num,
count=count)
-@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))
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):
marcxml=raw_pickitem,
**dct)
item.save()
- return HttpResponseRedirect('../../../%d/meta' % item.id)
+
+ return HttpResponseRedirect(item.parent_url())
#------------------------------------------------------------
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')
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:
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)
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())
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:
]
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')
-
- 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')
+ return HttpResponseRedirect('../../')
@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('../')
+
+@login_required
+def my_sites(request):
+ return g.render('my_sites.xhtml')
+
#-----------------------------------------------------------------------------
# Site Invitation Code handler
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())
-
-
<?python
if instance.id:
- title = _('Configure this site')
+ title = _('Site setup')
else:
title = _('Create a new site')
?>
<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>
</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)}
<?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)
<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%;">
?>
<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>
${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>
if settings.LINKTOOL_AUTHENTICATION:
urlpatterns += patterns(
'conifer.integration.linktool.app',
- (r'^linktool-welcome/$', 'linktool_welcome'))
+ (r'^linktool-welcome/(?P<command>.*)$', 'linktool_welcome'))