[open-ils-commits] r113 - in servres/trunk/conifer: syrup templates
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Jan 14 22:21:57 EST 2009
Author: gfawcett
Date: 2009-01-14 22:21:55 -0500 (Wed, 14 Jan 2009)
New Revision: 113
Added:
servres/trunk/conifer/templates/item_add_elec.xhtml
Modified:
servres/trunk/conifer/syrup/models.py
servres/trunk/conifer/syrup/urls.py
servres/trunk/conifer/syrup/views.py
servres/trunk/conifer/templates/item_add_url.xhtml
servres/trunk/conifer/templates/item_metadata.xhtml
Log:
Basic support for Electronic docs (file uploads).
It's ugly, but the mechanism works. This commit changes the Item
model; if you don't want to rebuild your tables you can do this:
sqlite3 syrup.sqlite "alter table syrup_item add column
fileobj_mimetype varchar(128) NULL;"
Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py 2009-01-15 03:12:11 UTC (rev 112)
+++ servres/trunk/conifer/syrup/models.py 2009-01-15 03:21:55 UTC (rev 113)
@@ -290,7 +290,9 @@
fileobj = m.FileField(upload_to='uploads/%Y/%m/%d', max_length=255,
blank=True, null=True, default=None)
+ fileobj_mimetype = m.CharField(max_length=128, blank=True, null=True, default=None)
+
date_created = m.DateTimeField(auto_now_add=True)
last_modified = m.DateTimeField()
Modified: servres/trunk/conifer/syrup/urls.py
===================================================================
--- servres/trunk/conifer/syrup/urls.py 2009-01-15 03:12:11 UTC (rev 112)
+++ servres/trunk/conifer/syrup/urls.py 2009-01-15 03:21:55 UTC (rev 113)
@@ -17,6 +17,7 @@
(r'^instructors/$', 'instructors'),
(r'^course/(?P<course_id>\d+)/$', 'course_detail'),
(ITEM_PREFIX + r'$', 'item_detail'),
+ (ITEM_PREFIX + r'dl/(?P<filename>.*)$', 'item_download'),
(ITEM_PREFIX + r'meta/$', 'item_metadata'),
(ITEM_PREFIX + r'edit/$', 'item_edit'),
(ITEM_PREFIX + r'add/$', 'item_add'), # for adding sub-things
Modified: servres/trunk/conifer/syrup/views.py
===================================================================
--- servres/trunk/conifer/syrup/views.py 2009-01-15 03:12:11 UTC (rev 112)
+++ servres/trunk/conifer/syrup/views.py 2009-01-15 03:21:55 UTC (rev 113)
@@ -173,8 +173,8 @@
item_type = request.GET.get('item_type')
assert item_type, 'No item_type parameter was provided.'
- # for the moment, only HEADINGs and URLs can be added.
- assert item_type in ('HEADING', 'URL'), 'Sorry, only HEADINGs and URLs can be added right now.'
+ # for the moment, only HEADINGs, URLs and ELECs can be added.
+ assert item_type in ('HEADING', 'URL', 'ELEC'), 'Sorry, only HEADINGs, URLs and ELECs can be added right now.'
if request.method == 'GET':
return g.render('item_add_%s.xhtml' % item_type.lower(),
@@ -216,8 +216,35 @@
url = url)
item.save()
return HttpResponseRedirect(item_url(item) + 'meta/')
+ elif item_type == 'ELEC':
+ title = request.POST.get('title', '').strip()
+ upload = request.FILES.get('file')
+ item = models.Item(
+ course=course,
+ item_type='ELEC',
+ parent_heading=parent_item,
+ title=title,
+ author=author,
+ activation_date=datetime.now(),
+ last_modified=datetime.now(),
+ fileobj_mimetype = upload.content_type,
+ )
+ item.fileobj.save(upload.name, upload)
+ item.save()
+
+ return HttpResponseRedirect(item_url(item) + 'meta/')
else:
raise NotImplementedError
+
+def item_download(request, course_id, item_id, filename):
+ course = get_object_or_404(models.Course, pk=course_id)
+ item = get_object_or_404(models.Item, pk=item_id, course__id=course_id)
+ assert item.item_type == 'ELEC', 'Can only download ELEC documents!'
+ fileiter = item.fileobj.chunks()
+ resp = HttpResponse(fileiter)
+ resp['Content-Type'] = item.fileobj_mimetype or 'application/octet-stream'
+ #resp['Content-Disposition'] = 'attachment; filename=%s' % name
+ return resp
def normalize_query(query_string,
findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
Copied: servres/trunk/conifer/templates/item_add_elec.xhtml (from rev 111, servres/trunk/conifer/templates/item_add_url.xhtml)
===================================================================
--- servres/trunk/conifer/templates/item_add_elec.xhtml (rev 0)
+++ servres/trunk/conifer/templates/item_add_elec.xhtml 2009-01-15 03:21:55 UTC (rev 113)
@@ -0,0 +1,29 @@
+<?python
+title = 'Add a new Electronic Document'
+course_title = '%s: %s (%s)' % (course.code, course.title, course.term)
+?>
+<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"/>
+ <xi:include href="components/item.xhtml"/>
+ <head>
+ <title>${title}</title>
+ </head>
+ <body>
+ <div class="courseident">
+ <div>${course.department}</div>
+ <h1><a href="${course_url(course)}">${course_title}</a></h1>
+ <div py:if="parent_item">${nested_title(parent_item)}</div>
+ <h2>${title}</h2>
+ <form action=".?item_type=${item_type}" method="POST"
+ enctype="multipart/form-data">
+ <table>
+ <tr><th>Title of document</th><td><input type="text" name="title"/></td></tr>
+ <tr><th>File</th><td><input type="file" name="file"/></td></tr>
+ </table>
+ <p><input type="submit" value="Upload file and Create item"/></p>
+ </form>
+ </div>
+</body>
+</html>
Modified: servres/trunk/conifer/templates/item_add_url.xhtml
===================================================================
--- servres/trunk/conifer/templates/item_add_url.xhtml 2009-01-15 03:12:11 UTC (rev 112)
+++ servres/trunk/conifer/templates/item_add_url.xhtml 2009-01-15 03:21:55 UTC (rev 113)
@@ -18,10 +18,10 @@
<h2>${title}</h2>
<form action=".?item_type=${item_type}" method="POST">
<table>
- <tr><th>Heading</th><td><input type="text" name="title"/></td></tr>
+ <tr><th>Title</th><td><input type="text" name="title"/></td></tr>
<tr><th>URL</th><td><input type="text" name="url"/></td></tr>
</table>
- <p><input type="submit" value="Create heading"/></p>
+ <p><input type="submit" value="Create item"/></p>
</form>
</div>
</body>
Modified: servres/trunk/conifer/templates/item_metadata.xhtml
===================================================================
--- servres/trunk/conifer/templates/item_metadata.xhtml 2009-01-15 03:12:11 UTC (rev 112)
+++ servres/trunk/conifer/templates/item_metadata.xhtml 2009-01-15 03:21:55 UTC (rev 113)
@@ -24,5 +24,12 @@
<tr><th>Author</th><td>${item.author}</td></tr>
<tr py:if="item.url"><th>URL</th><td><a href="${item.url}">${item.url}</a></td></tr>
</table>
+ <div py:if="item.item_type=='ELEC'">
+ <p><a href="${item_url(item)}dl/${item.fileobj.name.split('/')[-1]}">Download</a></p>
+ <table>
+ <tr><th>Content type</th><td>${item.fileobj_mimetype}</td></tr>
+ <tr><th>Content length</th><td>${item.fileobj.size}</td></tr>
+ </table>
+ </div>
</body>
</html>
More information about the open-ils-commits
mailing list