[open-ils-commits] r917 - in servres/trunk/conifer: libsystems/z3950 syrup syrup/views templates/admin templates/components templates/item (gfawcett)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Jul 14 20:55:14 EDT 2010
Author: gfawcett
Date: 2010-07-14 20:55:13 -0400 (Wed, 14 Jul 2010)
New Revision: 917
Modified:
servres/trunk/conifer/libsystems/z3950/marcxml.py
servres/trunk/conifer/libsystems/z3950/pyz3950_search.py
servres/trunk/conifer/syrup/models.py
servres/trunk/conifer/syrup/views/sites.py
servres/trunk/conifer/templates/admin/index.xhtml
servres/trunk/conifer/templates/components/site.xhtml
servres/trunk/conifer/templates/item/item_add_cat_search.xhtml
Log:
working around z3950/unicode issues; several minor changes.
Modified: servres/trunk/conifer/libsystems/z3950/marcxml.py
===================================================================
--- servres/trunk/conifer/libsystems/z3950/marcxml.py 2010-07-15 00:55:06 UTC (rev 916)
+++ servres/trunk/conifer/libsystems/z3950/marcxml.py 2010-07-15 00:55:13 UTC (rev 917)
@@ -1,7 +1,11 @@
from xml.etree import ElementTree
+# Note: the 'record' parameters passed to these functions must be
+# Unicode strings, not plain Python strings.
+
def marcxml_to_records(rec):
- tree = ElementTree.fromstring(rec)
+ assert isinstance(rec, unicode)
+ tree = ElementTree.fromstring(rec.encode('utf-8'))
if tree.tag == '{http://www.loc.gov/MARC21/slim}collection':
# then we may have multiple records
records = tree.findall('{http://www.loc.gov/MARC21/slim}record')
@@ -12,7 +16,8 @@
return records
def record_to_dictionary(record, multiples=True):
- tree = ElementTree.fromstring(record)
+ assert isinstance(record, unicode)
+ tree = ElementTree.fromstring(record.encode('utf-8'))
dct = {}
for df in tree.findall('{http://www.loc.gov/MARC21/slim}datafield'):
t = df.attrib['tag']
@@ -24,7 +29,8 @@
return dct
def marcxml_to_dictionary(rec, multiples=False):
- tree = ElementTree.fromstring(rec)
+ assert isinstance(rec, unicode)
+ tree = ElementTree.fromstring(rec.encode('utf-8'))
if tree.tag == '{http://www.loc.gov/MARC21/slim}collection':
# then we may have multiple records
records = tree.findall('{http://www.loc.gov/MARC21/slim}record')
Modified: servres/trunk/conifer/libsystems/z3950/pyz3950_search.py
===================================================================
--- servres/trunk/conifer/libsystems/z3950/pyz3950_search.py 2010-07-15 00:55:06 UTC (rev 916)
+++ servres/trunk/conifer/libsystems/z3950/pyz3950_search.py 2010-07-15 00:55:13 UTC (rev 917)
@@ -72,22 +72,15 @@
parsed = []
for rec in raw_records:
- try:
- rec = _marc_utf8_pattern.sub(_decode_marc_utf8, rec)
- except 'x':
- raise rec
+ # TODO: fix this ascii/replace, once our z3950/marc encoding
+ # issues are sorted out.
+ rec = unicode(rec, 'ascii', 'replace')
+
+ assert isinstance(rec, unicode) # this must be true.
parsed.append(rec)
return parsed, len(res)
-# decoding MARC \X.. UTF-8 patterns.
-
-_marc_utf8_pattern = re.compile(r'\\X([0-9A-F]{2})', re.I)
-
-def _decode_marc_utf8(regex_match):
- return chr(int(regex_match.group(1), 16))
-
-
#------------------------------------------------------------
# some tests
Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py 2010-07-15 00:55:06 UTC (rev 916)
+++ servres/trunk/conifer/syrup/models.py 2010-07-15 00:55:13 UTC (rev 917)
@@ -52,6 +52,9 @@
return self.is_staff or \
bool(callhook('can_create_sites', self))
+ def get_list_name(self):
+ return '%s, %s (%s)' % (self.last_name, self.first_name, self.username)
+
@classmethod
def active_instructors(cls):
"""Return a queryset of all active instructors."""
@@ -87,7 +90,7 @@
# Lookup tables
class ServiceDesk(BaseModel):
- name = m.CharField(max_length=100)
+ name = m.CharField(max_length=100, unique=True)
active = m.BooleanField(default=True)
external_id = m.CharField(max_length=256, blank=True, null=True)
@@ -95,14 +98,18 @@
return self.name
class Term(BaseModel):
- code = m.CharField(max_length=64)
+ code = m.CharField(max_length=64, unique=True)
name = m.CharField(max_length=256)
start = m.DateField('Start (Y-M-D)')
finish = m.DateField('Finish (Y-M-D)')
+ class Meta:
+ ordering = ['start', 'code']
+
def __unicode__(self):
- return self.code or self.name
+ return '%s: %s' % (self.code, self.name)
+
class Department(BaseModel):
name = m.CharField(max_length=256)
active = m.BooleanField(default=True)
@@ -111,15 +118,20 @@
def __unicode__(self):
return self.name
+
class Course(BaseModel):
"""An abstract course (not a course offering.)"""
- code = m.CharField(max_length=64)
+ code = m.CharField(max_length=64, unique=True)
name = m.CharField(max_length=1024)
department = m.ForeignKey(Department)
+ class Meta:
+ ordering = ['code']
+
def __unicode__(self):
- return self.name
+ return '%s: %s' % (self.code, self.name)
+
class Z3950Target(m.Model):
name = m.CharField(max_length=100)
host = m.CharField(max_length=50)
@@ -132,7 +144,7 @@
return self.name
class Config(m.Model):
- name = m.CharField(max_length=256)
+ name = m.CharField(max_length=256, unique=True)
value = m.CharField(max_length=8192)
@classmethod
@@ -254,13 +266,18 @@
'user__last_name', 'user__first_name')
def can_edit(self, user):
+ """
+ Return True if the user has permission to edit this
+ site. Staff, site owners and site instructors all have editing
+ permissions.
+ """
if user.is_anonymous():
return False
- if user.id == self.owner_id:
+ if (user.id == self.owner_id) or user.is_staff:
return True
try:
mbr = self.members().get(user=user)
- except Member.DoesNotExist:
+ except Membership.DoesNotExist:
return False
return mbr.role in (u'INSTR', u'ASSIST')
@@ -268,14 +285,14 @@
"""Return True if the user could feasibly register into this
site: she's not already in it, and the site allows open
registration."""
- return user.is_authenticated() \
- and self.access in ('ANON', 'LOGIN') \
+ return self.access in ('ANON', 'LOGIN') \
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()
+ return user.is_authenticated() and (
+ user.id == self.owner_id \
+ or bool(self.members().filter(user=user)))
#------------------------------------------------------------
# User membership in sites
Modified: servres/trunk/conifer/syrup/views/sites.py
===================================================================
--- servres/trunk/conifer/syrup/views/sites.py 2010-07-15 00:55:06 UTC (rev 916)
+++ servres/trunk/conifer/syrup/views/sites.py 2010-07-15 00:55:13 UTC (rev 917)
@@ -18,6 +18,14 @@
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')
+
+ super(NewSiteForm, self).__init__(*args, **kwargs)
+
+
# if we have course-code lookup, hack lookup support into the new-course form.
COURSE_CODE_LIST = bool(models.campus.course_code_list)
@@ -35,7 +43,7 @@
# NewSiteForm.base_fields['code'].empty_label = empty_label
#--------------------
-
+
@login_required
def add_new_site(request):
if not request.user.can_create_sites():
@@ -46,7 +54,7 @@
def edit_site(request, site_id):
instance = get_object_or_404(models.Site, pk=site_id)
return _add_or_edit_site(request, instance=instance)
-
+
def _add_or_edit_site(request, instance=None):
is_add = (instance is None)
if is_add:
@@ -67,11 +75,7 @@
site.generate_new_passkey()
site.save()
assert site.id
- 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()
-
+
if is_add or (current_access_level != site.access):
# we need to configure permissions.
return HttpResponseRedirect(site.site_url('edit/permission/'))
Modified: servres/trunk/conifer/templates/admin/index.xhtml
===================================================================
--- servres/trunk/conifer/templates/admin/index.xhtml 2010-07-15 00:55:06 UTC (rev 916)
+++ servres/trunk/conifer/templates/admin/index.xhtml 2010-07-15 00:55:13 UTC (rev 917)
@@ -7,6 +7,9 @@
<xi:include href="../master.xhtml"/>
<head>
<title>${title}</title>
+ <style type="text/css">
+ ul { margin-bottom: 2em; }
+ </style>
</head>
<body>
<h1>${title}</h1>
@@ -24,7 +27,7 @@
<!-- <li><a href="../zsearch/">Search Z39.50 Targets</a></li> -->
<!-- </ul> -->
<ul>
- <li><a href="../djadmin/">Django Administrative UI</a></li>
+ <li><a href="../site/new/">Create a new course site</a></li>
</ul>
<ul>
<li py:if="gethook('department_course_catalogue')">
@@ -34,6 +37,9 @@
<a href="update_terms">Automatically update terms</a>
</li>
</ul>
+ <ul>
+ <li><a href="../djadmin/">Advanced Administration</a></li>
+ </ul>
</div>
</body>
</html>
Modified: servres/trunk/conifer/templates/components/site.xhtml
===================================================================
--- servres/trunk/conifer/templates/components/site.xhtml 2010-07-15 00:55:06 UTC (rev 916)
+++ servres/trunk/conifer/templates/components/site.xhtml 2010-07-15 00:55:13 UTC (rev 917)
@@ -18,7 +18,10 @@
<div py:def="site_banner(site)" py:strip="True">
<div id="sitebanner">
${site_search(site)}
- <div class="deptident">${site.course.department} • ${site.term.name}</div>
+ <div class="deptident">
+ ${site.owner.last_name}
+ • ${site.term.name}
+ • ${site.course.department}</div>
<h1><a href="${site.site_url()}"><span py:if="site.course">${site.course.code}: </span>${site.course.name}</a></h1>
</div>
</div>
@@ -61,9 +64,13 @@
py:with="hier=item.hierarchy()[:-1]; lastnum=len(hier)"
class="nestedtitle">
<div id="breadcrumbs">
- <span><a href="${item.site.site_url()}">Top</a></span> »
- <span py:for="n, x in enumerate(hier)"><a href="${x.item_url()}">${x.title}</a> » </span>
- <span class="final_item">${item.title}</span>
+ <span><a href="${item.site.site_url()}">Top</a></span>
+ <span py:for="n, x in enumerate(hier)">
+ » <a href="${x.item_url()}">${x.title}</a>
+ </span>
+ <span py:if="item.item_type=='HEADING'">
+ » <span class="final_item">${item.title}</span>
+ </span>
</div>
</div>
Modified: servres/trunk/conifer/templates/item/item_add_cat_search.xhtml
===================================================================
--- servres/trunk/conifer/templates/item/item_add_cat_search.xhtml 2010-07-15 00:55:06 UTC (rev 916)
+++ servres/trunk/conifer/templates/item/item_add_cat_search.xhtml 2010-07-15 00:55:13 UTC (rev 917)
@@ -1,5 +1,4 @@
<?python
-from xml.etree import ElementTree as E
from django.utils.simplejson import dumps
from conifer.libsystems.z3950.marcxml import record_to_dictionary
from conifer.libsystems.z3950.marcxml import marcxml_dictionary_to_dc as to_dublin
@@ -70,7 +69,7 @@
<td>
<form action="." method="POST">
<!-- !TODO: is utf8 okay here? I shouldn't have to do any decoding here. -->
- <input type="hidden" name="pickitem" value="${unicode(res, 'utf8')}"/>
+ <input type="hidden" name="pickitem" value="${res}"/>
<input type="submit" value="Pick this item"/>
</form>
</td>
More information about the open-ils-commits
mailing list