from django.http import HttpResponse, HttpResponseRedirect
+from django.http import HttpResponseForbidden
from django.core.paginator import Paginator
from django.shortcuts import get_object_or_404
from django.contrib.auth.decorators import login_required
return g.render('item_metadata.xhtml', course=item.course,
item=item)
+@login_required
def item_edit(request, course_id, item_id):
"""Edit an item."""
# For now, just pop to the Admin interface.
return g.render('item_heading_detail.xhtml', item=item)
-
+@login_required
def item_add(request, course_id, item_id):
# The item-id is the id for the parent-heading item. Zero represents
# 'top-level', i.e. the new item should have no heading. For any other
parent_item = get_object_or_404(models.Item, pk=item_id, course__id=course_id)
assert parent_item.item_type == 'HEADING', 'Can only add items to headings!'
course = parent_item.course
+
+ if not course.can_edit(user):
+ return HttpResponseForbidden('not an editor') # fixme, prettier msg?
+
item_type = request.GET.get('item_type')
assert item_type, 'No item_type parameter was provided.'
**locals())
else:
# fixme, this will need refactoring. But not yet.
+ author = request.user.get_full_name() or request.user.username
if item_type == 'HEADING':
title = request.POST.get('title', '').strip()
if not title:
item_type='HEADING',
parent_heading=parent_item,
title=title,
- author=request.user.get_full_name() or request.user.username,
+ author=author,
activation_date=datetime.now(),
last_modified=datetime.now())
item.save()
item_type='URL',
parent_heading=parent_item,
title=title,
- author=request.user.get_full_name() or request.user.username,
+ author=author,
activation_date=datetime.now(),
last_modified=datetime.now(),
url = url)
course = item.course
title = item.title
course_title = '%s: %s (%s)' % (course.code, course.title, course.term)
+is_editor = course.can_edit(request.user)
item_tree = course.item_tree(subtree=item)
?>
<html xmlns="http://www.w3.org/1999/xhtml"
<!-- <p py:if="not item_tree"> -->
<!-- There are no items associated in this subheading. -->
<!-- </p> -->
- ${show_tree(item_tree)}
- ${add_subs(item)}
+ ${show_tree(item_tree, edit=is_editor)}
+ <div py:if="is_editor">${add_subs(item)}</div>
</body>
</html>