From: gfawcett Date: Tue, 2 Dec 2008 01:24:48 +0000 (+0000) Subject: more work on Item class; refactoring and cleanup of template code. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d1dc0d3f35140a6d85dddb1d9d0236ce55f42ec7;p=Syrup.git more work on Item class; refactoring and cleanup of template code. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@75 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- diff --git a/conifer/genshi_namespace.py b/conifer/genshi_namespace.py index c1ef28c..8ce3c09 100644 --- a/conifer/genshi_namespace.py +++ b/conifer/genshi_namespace.py @@ -6,3 +6,6 @@ from itertools import cycle from conifer.syrup import models + +def item_url(item, suffix=''): + return '/syrup/course/%d/item/%d/%s' % (item.course_id, item.id, suffix) diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index 6361139..964a2cd 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -144,7 +144,7 @@ class Course(m.Model): You can provide a 'subtree', an item which is the top node in a subtree of the item-tree. If subtree is provided, then - return either a signle (Item, [Item]) pair, where Item is the + return either a single (Item, [Item]) pair, where Item is the subtree element, or None if there is no match. """ items = self.items() @@ -208,16 +208,24 @@ class Item(m.Model): # dictates the sequencing of items within their parent group. course = m.ForeignKey(Course) - ITEM_TYPE_CHOICES = (('ITEM', 'Item'), - ('HEADING', 'Heading')) - item_type = m.CharField(max_length=7, choices=ITEM_TYPE_CHOICES, - default='ITEM') + ITEM_TYPE_CHOICES = ( + ('ELEC', 'Attached Electronic Document'), # PDF, Doc, etc. + ('PHYS', 'Physical Book or Document'), + ('URL', 'URL'), + ('HEADING', 'Heading')) + item_type = m.CharField(max_length=7, choices=ITEM_TYPE_CHOICES) sort_order = m.IntegerField(default=0) # parent must be a heading. could use ForeignKey.limit_choices_to, # to enforce this in the admin ui. parent_heading = m.ForeignKey('Item', blank=True, null=True) - # Metadata + # Metadata. + + # TODO: Are all these relevant to all item types? If not, which + # ones should be 'required' for which item-types? We cannot + # enforce these requirements through model constraints, unless we + # break Item up into multiple tables. But there are other ways we + # can specify the constraints. title = m.CharField(max_length=255,db_index=True) author = m.CharField(max_length=255,db_index=True) source = m.CharField(max_length=255,db_index=True, blank=True, null=True) @@ -228,9 +236,8 @@ class Item(m.Model): volume_edition = m.CharField(max_length=255, blank=True, null=True) pages_times = m.CharField(max_length=255, blank=True, null=True) performer = m.CharField(max_length=255,db_index=True, blank=True, null=True) + local_control_key = m.CharField(max_length=30, blank=True, null=True) - creation_date = m.DateField(auto_now=False) - last_modified = m.DateField(auto_now=False) url = m.URLField(blank=True, null=True) mime_type = m.CharField(max_length=100,default='text/html') @@ -272,9 +279,11 @@ class Item(m.Model): # requested_loan_period: why is this a text field? requested_loan_period = m.CharField(max_length=255,blank=True,default='', null=True) + # for items of type ELEC (attached electronic document) fileobj = m.FileField(upload_to='uploads/%Y/%m/%d', max_length=255, blank=True, null=True, default=None) + date_created = m.DateTimeField(auto_now_add=True) last_modified = m.DateTimeField() diff --git a/conifer/syrup/urls.py b/conifer/syrup/urls.py index 81acbb6..45c6e40 100644 --- a/conifer/syrup/urls.py +++ b/conifer/syrup/urls.py @@ -1,5 +1,11 @@ from django.conf.urls.defaults import * +# I'm not ready to break items out into their own urls.py, but I do +# want to cut down on the common boilerplate in the urlpatterns below. + +ITEM_PREFIX = r'^course/(?P\d+)/item/(?P\d+)/' + + urlpatterns = patterns('conifer.syrup.views', (r'^$', 'welcome'), (r'^course/$', 'my_courses'), @@ -8,6 +14,7 @@ urlpatterns = patterns('conifer.syrup.views', (r'^search/$', 'search'), (r'^instructors/$', 'instructors'), (r'^course/(?P\d+)/$', 'course_detail'), - (r'^course/(?P\d+)/item/(?P\d+)/$', 'item_detail'), - (r'^course/(?P\d+)/item/(?P\d+)/meta$', 'item_metadata'), + (ITEM_PREFIX + r'$', 'item_detail'), + (ITEM_PREFIX + r'meta/$', 'item_metadata'), + (ITEM_PREFIX + r'edit/$', 'item_edit'), ) diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index 83ec58e..980c810 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -98,6 +98,12 @@ def item_metadata(request, course_id, item_id): return g.render('item_metadata.xhtml', course=item.course, item=item) +def item_edit(request, course_id, item_id): + """Edit an item.""" + # For now, just pop to the Admin interface. + admin_url = '/admin/syrup/item/%s/' % item_id + return HttpResponseRedirect(admin_url) + def _heading_url(request, item): return HttpResponseRedirect(item.url) diff --git a/conifer/templates/components/item.xhtml b/conifer/templates/components/item.xhtml index 6dc06f2..d1e8ffe 100644 --- a/conifer/templates/components/item.xhtml +++ b/conifer/templates/components/item.xhtml @@ -8,8 +8,8 @@
  • ${item} - [about - • edit + [about + • edit ] ${show_tree(subs)} diff --git a/conifer/templates/course_detail.xhtml b/conifer/templates/course_detail.xhtml index a7f1ed9..c2c43a6 100644 --- a/conifer/templates/course_detail.xhtml +++ b/conifer/templates/course_detail.xhtml @@ -1,6 +1,6 @@ hey ${foo.user.last_name}
    - hey ${foo.instr_name_hl(norm_query)}
    + hey ${Markup(foo.instr_name_hl(norm_query))}

    TermTitle