From f271d65ec223d6814d22a3246aa5b1cb904b9387 Mon Sep 17 00:00:00 2001 From: gfawcett Date: Thu, 15 Jul 2010 00:54:47 +0000 Subject: [PATCH] Create site, view site, add items to site mostly working again The 'about/metadata' item links are not working yet. I need to refactor the add-item forms quite a bit, esp. wrt. consistent metadata entry. The site-permissions screen is still a farce, and needs to be rewritten to address the new membership-group model. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@913 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/genshi_namespace.py | 1 + conifer/static/main.css | 25 ++++++----- conifer/syrup/models.py | 16 ++++--- conifer/syrup/views/_common.py | 1 + conifer/syrup/views/items.py | 53 +++++++----------------- conifer/syrup/views/sites.py | 2 +- conifer/templates/browse_index.xhtml | 21 +++++++++- conifer/templates/components/site.xhtml | 4 +- conifer/templates/edit_site_permissions.xhtml | 35 +--------------- conifer/templates/item/item_add_elec.xhtml | 11 +++-- conifer/templates/item/item_add_heading.xhtml | 4 +- conifer/templates/item/item_add_phys.xhtml | 4 +- conifer/templates/item/item_add_url.xhtml | 4 +- conifer/templates/item/item_delete_confirm.xhtml | 3 +- conifer/templates/item/item_heading_detail.xhtml | 2 +- conifer/templates/item/item_metadata.xhtml | 10 ++--- conifer/templates/site_detail.xhtml | 2 +- 17 files changed, 80 insertions(+), 118 deletions(-) diff --git a/conifer/genshi_namespace.py b/conifer/genshi_namespace.py index 154342a..ac9dedb 100644 --- a/conifer/genshi_namespace.py +++ b/conifer/genshi_namespace.py @@ -3,6 +3,7 @@ # Toplevel definitions in this module will be available in when # rendering a Genshi template. +import itertools from itertools import cycle from conifer.syrup import models import django.forms diff --git a/conifer/static/main.css b/conifer/static/main.css index 7403ddc..0146aa7 100644 --- a/conifer/static/main.css +++ b/conifer/static/main.css @@ -16,6 +16,9 @@ table, caption, tbody, tfoot, thead, tr, th, td { font-family: inherit; vertical-align: baseline; } + +li { margin-left: 16px; } + /* remember to define focus styles! */ :focus { outline: 0; @@ -25,9 +28,7 @@ body { color: black; background: white; } -ol, ul { - list-style: none; -} + /* tables still need 'cellspacing="0"' in the markup */ table { border-collapse: separate; @@ -73,6 +74,7 @@ min-height: 300px; background-color: #448; } + #header div#search { float: right; margin: 0; @@ -92,12 +94,12 @@ min-height: 300px; tbody td, tbody th { vertical-align: top; } #footer { - margin: 12px; - padding-bottom: 12px; - background-color: #ddf; - color: black; - border-bottom: white 10px solid; + margin: 0; + padding-top: 16px; + color: #eee; + font-size: small; } +#footer a { color: white; text-decoration: underline; } /* heading sizes and colours. */ @@ -122,7 +124,7 @@ a:hover { text-decoration: underline; } .action a { font-weight: bold; } #tabbar { margin: 18px 0; padding: 0; clear: both; } -#tabbar li { display: inline; } +#tabbar li { display: inline; margin: 0; } #tabbar li a { padding: 15px 18px 5px 18px; background-color: #ddf; color: black; text-decoration: none; } #tabbar li a:hover { background-color: #fc8; } @@ -157,7 +159,7 @@ span.final_item { font-weight: bold; font-size: 110%; } #sidepanel { width: 183px; float: right; text-align: right;} #sidepanel div { margin: 6px 0; } -#treepanel { width: 740px; } +#treepanel { width: 740px; margin-top: 24px; } .helptext { margin-top: 30px; font-size: 90%; @@ -205,6 +207,7 @@ span.final_item { font-weight: bold; font-size: 110%; } .itemtree li.item_HEADING { list-style-image: url(tango/folder.png); + margin-top: 24px; } .itemtree li.item_HEADING > a { color: navy; @@ -215,7 +218,7 @@ li.item_HEADING .headingmainline { } li.item_HEADING .headingmainline a.mainlink { - border-bottom: #aaa 1px solid; + font-size: large; color: navy; } li.item_HEADING .headingmainline a.mainlink:hover { diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index 8d076bf..7473633 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -167,7 +167,10 @@ class Site(BaseModel): unique_together = (('course', 'term', 'owner')) def __unicode__(self): - return u'%s %s %s' % (self.course, self.term, self.owner) + return u'%s: %s (%s, %s)' % ( + self.course.code, self.course.name, + self.owner.last_name or self.owner.username, + self.term) def list_display(self): if self.code: @@ -200,7 +203,8 @@ class Site(BaseModel): for item in items: dct.setdefault(item.parent_heading, []).append(item) for lst in dct.values(): - lst.sort(key=lambda item: item.sort_order) # sort in place + # TODO: what's the sort order? + lst.sort(key=lambda item: (item.item_type=='HEADING', item.title)) # sort in place # walk the tree out = [] def walk(parent, accum): @@ -239,11 +243,11 @@ class Site(BaseModel): return Membership.objects.filter(group__site=self) def get_students(self): - return self.memberships(role='STUDT').order_by( + return self.members().filter(role='STUDT').order_by( 'user__last_name', 'user__first_name') def get_instructors(self): - return self.memberships(role='INSTR').order_by( + return self.members().filter(role='INSTR').order_by( 'user__last_name', 'user__first_name') def can_edit(self, user): @@ -252,7 +256,7 @@ class Site(BaseModel): if user.id == self.owner_id: return True try: - mbr = self.members.get(user=user) + mbr = self.members().get(user=user) except Member.DoesNotExist: return False return mbr.role in (u'INSTR', u'ASSIST') @@ -268,7 +272,7 @@ class Site(BaseModel): def is_member(self, user): assert user return user.id == self.owner_id \ - or self.members.filter(user=user).exists() + or self.members().filter(user=user).exists() #------------------------------------------------------------ # User membership in sites diff --git a/conifer/syrup/views/_common.py b/conifer/syrup/views/_common.py index 428fad7..896ddc3 100644 --- a/conifer/syrup/views/_common.py +++ b/conifer/syrup/views/_common.py @@ -113,6 +113,7 @@ def _fast_user_membership_query(user_id, site_id, where=None): # I use a raw SQL query here because I want the lookup to be as # fast as possible. Caching would help too, but let's try this # first. (todo, review later.) + return True # TODO: fixme!!!! query = ('select count(*) from syrup_member ' 'where user_id=%s and site_id=%s ') if where: diff --git a/conifer/syrup/views/items.py b/conifer/syrup/views/items.py index 44e7ed0..e7b2d2e 100644 --- a/conifer/syrup/views/items.py +++ b/conifer/syrup/views/items.py @@ -70,19 +70,12 @@ def item_add(request, site_id, item_id): if request.method != 'POST': item = models.Item() # dummy object - metadata_formset = metadata_formset_class(queryset=item.metadata_set.all()) return g.render('item/item_add_%s.xhtml' % item_type.lower(), **locals()) else: # fixme, this will need refactoring. But not yet. author = request.user.get_full_name() or request.user.username item = models.Item() # dummy object - metadata_formset = metadata_formset_class(request.POST, queryset=item.metadata_set.all()) - assert metadata_formset.is_valid() - def do_metadata(item): - for obj in [obj for obj in metadata_formset.cleaned_data if obj]: # ignore empty dicts - if not obj.get('DELETE'): - item.metadata_set.create(name=obj['name'], value=obj['value']) if item_type == 'HEADING': title = request.POST.get('title', '').strip() @@ -93,13 +86,10 @@ def item_add(request, site_id, item_id): item = models.Item( site=site, item_type='HEADING', - sort_order = next_order, parent_heading=parent_item, title=title, ) item.save() - do_metadata(item) - item.save() elif item_type == 'URL': title = request.POST.get('title', '').strip() url = request.POST.get('url', '').strip() @@ -111,12 +101,9 @@ def item_add(request, site_id, item_id): site=site, item_type='URL', parent_heading=parent_item, - sort_order = next_order, title=title, url = url) item.save() - do_metadata(item) - item.save() elif item_type == 'ELEC': title = request.POST.get('title', '').strip() upload = request.FILES.get('file') @@ -127,14 +114,11 @@ def item_add(request, site_id, item_id): site=site, item_type='ELEC', parent_heading=parent_item, - sort_order = next_order, title=title, fileobj_mimetype = upload.content_type, ) item.fileobj.save(upload.name, upload) item.save() - do_metadata(item) - item.save() else: raise NotImplementedError @@ -157,11 +141,6 @@ def item_add_cat_search(request, site_id, item_id): site = parent_item.site siblings = site.item_set.filter(parent_heading=parent_item) - try: - next_order = 1 + max(i.sort_order for i in siblings) - except: - next_order = 0 - #---------- if request.method != 'POST': @@ -202,16 +181,19 @@ def item_add_cat_search(request, site_id, item_id): else: dct = dict(item_type='PHYS') - item = site.item_set.create(parent_heading=parent_item, - sort_order=next_order, - title=dublin.get('dc:title','Untitled'), - **dct) - item.save() + try: + pubdate = dublin.get('dc:date') + pubdate = re.search('^([0-9]+)', pubdate).group(1) + pubdate = '%d-01-01' % int(pubdate) + except: + pubdate = None - for dc, value in dublin.items(): - md = item.metadata_set.create(item=item, name=dc, value=value) - # store the whole darn MARC-dict as well (JSON) - item.metadata_set.create(item=item, name='syrup:marc', value=raw_pickitem) + item = site.item_set.create(parent_heading=parent_item, + title=dublin.get('dc:title','Untitled'), + author=dublin.get('dc:creator'), + publisher=dublin.get('dc:publisher',''), + published=pubdate, + **dct) item.save() return HttpResponseRedirect('../../../%d/meta' % item.id) @@ -226,11 +208,8 @@ def item_edit(request, site_id, item_id): parent_item = item.parent_heading if request.method != 'POST': - metadata_formset = metadata_formset_class(queryset=item.metadata_set.all()) return g.render(template, **locals()) else: - metadata_formset = metadata_formset_class(request.POST, queryset=item.metadata_set.all()) - assert metadata_formset.is_valid() if 'file' in request.FILES: # this is a 'replace-current-file' action. upload = request.FILES.get('file') @@ -239,11 +218,6 @@ def item_edit(request, site_id, item_id): else: # generally update the item. [setattr(item, k, v) for (k,v) in request.POST.items()] - # generally update the metadata - item.metadata_set.all().delete() - for obj in [obj for obj in metadata_formset.cleaned_data if obj]: # ignore empty dicts - if not obj.get('DELETE'): - item.metadata_set.create(name=obj['name'], value=obj['value']) item.save() return HttpResponseRedirect(item.parent_url()) @@ -289,7 +263,8 @@ def _reseq(request, site, parent_heading): # get at the ints. new_order = [int(n.split('_')[1]) for n in new_order] print >> sys.stderr, new_order - the_items = list(site.item_set.filter(parent_heading=parent_heading).order_by('sort_order')) + # TODO .orderBy, now there is no sort_order. + the_items = list(site.item_set.filter(parent_heading=parent_heading)) # sort the items by position in new_order the_items.sort(key=lambda item: new_order.index(item.id)) for newnum, item in enumerate(the_items): diff --git a/conifer/syrup/views/sites.py b/conifer/syrup/views/sites.py index f8029ca..ea8c1c6 100644 --- a/conifer/syrup/views/sites.py +++ b/conifer/syrup/views/sites.py @@ -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.Membership.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 diff --git a/conifer/templates/browse_index.xhtml b/conifer/templates/browse_index.xhtml index dd6fad3..f06be1e 100644 --- a/conifer/templates/browse_index.xhtml +++ b/conifer/templates/browse_index.xhtml @@ -1,5 +1,8 @@

${title}

- (Note: some reserve materials may require you +
+ (Note: some reserve materials may require you to log in) +
+ + +
+

${dept}

+

+ ${site} +

+ +
+ +

Choose from one of the options below:

    @@ -22,6 +38,7 @@ title = _('Browse the Reserves') href="departments">Browse by Department
+
diff --git a/conifer/templates/components/site.xhtml b/conifer/templates/components/site.xhtml index c903692..7b63bc9 100644 --- a/conifer/templates/components/site.xhtml +++ b/conifer/templates/components/site.xhtml @@ -18,8 +18,8 @@ searchtext = _('search this site...')
${site_search(site)} -
${site.department}
-

${site.code}: ${site.title}

+
${site.course.department} • ${site.term.name}
+

${site.course.code}: ${site.course.name}

diff --git a/conifer/templates/edit_site_permissions.xhtml b/conifer/templates/edit_site_permissions.xhtml index 2552dba..d6d0987 100644 --- a/conifer/templates/edit_site_permissions.xhtml +++ b/conifer/templates/edit_site_permissions.xhtml @@ -1,6 +1,6 @@

Course section numbers

- - - - - - - - - - - - - -
Associated sectionRemove?
${code}, section ${sec}, in term ${term}
-

Add section: - -

+

Not implemented yet.

diff --git a/conifer/templates/item/item_add_elec.xhtml b/conifer/templates/item/item_add_elec.xhtml index df23053..a9a2b83 100644 --- a/conifer/templates/item/item_add_elec.xhtml +++ b/conifer/templates/item/item_add_elec.xhtml @@ -1,7 +1,7 @@ $(function() {$('input[name="title"]').focus();}); - ${item_metadata_formset_header()} ${site_banner(site)} @@ -29,7 +28,6 @@ site_title = '%s: %s (%s)' % (site.code, site.title, site.term) value="${item.title}"/> File - ${item_metadata_formset()}

${go_back_link()}

@@ -41,8 +39,13 @@ site_title = '%s: %s (%s)' % (site.code, site.title, site.term) + + + - ${item_metadata_formset()}

File contents

diff --git a/conifer/templates/item/item_add_heading.xhtml b/conifer/templates/item/item_add_heading.xhtml index b380859..5d8ca08 100644 --- a/conifer/templates/item/item_add_heading.xhtml +++ b/conifer/templates/item/item_add_heading.xhtml @@ -1,7 +1,7 @@ $(function() {$('input[name="title"]').focus();}); - ${item_metadata_formset_header()} ${site_banner(site)} @@ -27,7 +26,6 @@ site_title = '%s: %s (%s)' % (site.code, site.title, site.term) value="${item.title}"/> - ${item_metadata_formset()}

diff --git a/conifer/templates/item/item_add_phys.xhtml b/conifer/templates/item/item_add_phys.xhtml index ac33f65..a5be26e 100644 --- a/conifer/templates/item/item_add_phys.xhtml +++ b/conifer/templates/item/item_add_phys.xhtml @@ -1,7 +1,7 @@ ${offer_to_delete(item)}

${title}

-
@@ -28,7 +27,6 @@ site_title = '%s: %s (%s)' % (site.code, site.title, site.term)

Metadata

- ${item_metadata_formset(show_more=False)}

diff --git a/conifer/templates/item/item_add_url.xhtml b/conifer/templates/item/item_add_url.xhtml index ad752d7..cbb8ec7 100644 --- a/conifer/templates/item/item_add_url.xhtml +++ b/conifer/templates/item/item_add_url.xhtml @@ -1,7 +1,7 @@ $(function() {$('input[name="title"]').focus();}); - ${item_metadata_formset_header()} ${site_banner(site)} @@ -25,7 +24,6 @@ site_title = '%s: %s (%s)' % (site.code, site.title, site.term) Title URL - ${item_metadata_formset()}

diff --git a/conifer/templates/item/item_delete_confirm.xhtml b/conifer/templates/item/item_delete_confirm.xhtml index 1d7a57e..2c3d244 100644 --- a/conifer/templates/item/item_delete_confirm.xhtml +++ b/conifer/templates/item/item_delete_confirm.xhtml @@ -1,5 +1,5 @@ diff --git a/conifer/templates/item/item_metadata.xhtml b/conifer/templates/item/item_metadata.xhtml index 9aeb6d8..8e2f00a 100644 --- a/conifer/templates/item/item_metadata.xhtml +++ b/conifer/templates/item/item_metadata.xhtml @@ -1,10 +1,8 @@ Status

${status}
- - Small Number${smallint} - URL${item.url}
@@ -53,7 +48,8 @@ is_editor = site.can_edit(request.user) Download
-
+

TODO: get metadata back...

+
diff --git a/conifer/templates/site_detail.xhtml b/conifer/templates/site_detail.xhtml index 23c33be..edae78f 100644 --- a/conifer/templates/site_detail.xhtml +++ b/conifer/templates/site_detail.xhtml @@ -1,5 +1,5 @@