return obj() or dflt
else:
return obj or dflt
+
+
+def instructs(user, course):
+ try:
+ mbr = models.Member.objects.get(user=user, course=course)
+ return mbr.role in ('INSTR', 'PROXY')
+ except:
+ return False
+
#coursebanner h1 { padding: 0; font-size: 110%; }
+#edit_course_link { float: right; margin: 4 0 0 0; font-size: 95%; }
+
.breadcrumbs { margin: 8 8 8 0; }
.errorlist { float: right; }
text-align: left;
font-size: 90%;
font-weight: normal;
-}
\ No newline at end of file
+}
+
(r'^instructor/(?P<instructor_id>.*)/$', 'instructor_detail'),
(r'^department/(?P<department_id>.*)/$', 'department_detail'),
(r'^course/(?P<course_id>\d+)/search/$', 'course_search'),
+ (r'^course/(?P<course_id>\d+)/edit/$', 'edit_course'),
(ITEM_PREFIX + r'$', 'item_detail'),
(ITEM_PREFIX + r'dl/(?P<filename>.*)$', 'item_download'),
(ITEM_PREFIX + r'meta$', 'item_metadata'),
@login_required
def add_new_course(request):
+ return add_or_edit_course(request)
+
+@login_required
+def edit_course(request, course_id):
+ instance = models.Course.objects.get(pk=course_id)
+ return add_or_edit_course(request, instance=instance)
+
+def add_or_edit_course(request, instance=None):
+ if instance is None:
+ instance = models.Course()
example = models.course_codes.course_code_example
if request.method != 'POST':
- form = NewCourseForm(instance=models.Course())
+ form = NewCourseForm(instance=instance)
return g.render('add_new_course.xhtml', **locals())
else:
- form = NewCourseForm(request.POST, instance=models.Course())
+ form = NewCourseForm(request.POST, instance=instance)
if not form.is_valid():
return g.render('add_new_course.xhtml', **locals())
else:
form.save()
course = form.instance
assert course.id
- mbr = course.member_set.create(user=request.user, role='INSTR')
- mbr.save()
+ user_in_course = models.Member.objects.filter(user=request.user,course=course)
+ if not user_in_course: # for edits, might already be!
+ mbr = course.member_set.create(user=request.user, role='INSTR')
+ mbr.save()
# fixme, need to ask about PASWD and STUDT settings before redirect.
return HttpResponseRedirect('../') # back to My Courses
<?python
-title = _('Add a new course site')
+if instance.id:
+ title = _('Edit course details')
+else:
+ title = _('Add a new course site')
?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xi="http://www.w3.org/2001/XInclude"
</form>
</div>
- <div py:def="course_banner(course)"
- id="coursebanner">
- <div class="deptident">${course.department}</div>
- ${course_search(course)}
- <h1><a href="${course.course_url()}">${course.code}: ${course.title}</a></h1>
+ <div py:def="course_banner(course)" py:strip="True">
+ <div id="coursebanner">
+ <div class="deptident">${course.department}</div>
+ ${course_search(course)}
+ <h1><a href="${course.course_url()}">${course.code}: ${course.title}</a></h1>
+ </div>
</div>
<!-- !show_tree: display a tree of items in a hierarchical style. -->
</head>
<body>
${course_banner(course)}
+ <div py:if="instructs(request.user, course)" id="edit_course_link">
+ <a href="${course.course_url()}edit/">Edit course details</a>
+ </div>
<p py:if="not item_tree">
There are no items associated with this course yet.
</p>