From 4f6700d321ab8dba854ba0ce511fabd6e63240ec Mon Sep 17 00:00:00 2001 From: gfawcett Date: Sun, 8 Mar 2009 01:49:33 +0000 Subject: [PATCH] UI support for editing course details git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@145 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/genshi_namespace.py | 9 +++++++++ conifer/static/main.css | 5 ++++- conifer/syrup/urls.py | 1 + conifer/syrup/views.py | 20 ++++++++++++++++---- conifer/templates/add_new_course.xhtml | 5 ++++- conifer/templates/components/course.xhtml | 11 ++++++----- conifer/templates/course_detail.xhtml | 3 +++ 7 files changed, 43 insertions(+), 11 deletions(-) diff --git a/conifer/genshi_namespace.py b/conifer/genshi_namespace.py index e0bcf87..1022c05 100644 --- a/conifer/genshi_namespace.py +++ b/conifer/genshi_namespace.py @@ -17,3 +17,12 @@ def call_or_value(obj, dflt=None): 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 + diff --git a/conifer/static/main.css b/conifer/static/main.css index 61497f3..0699b7f 100644 --- a/conifer/static/main.css +++ b/conifer/static/main.css @@ -192,6 +192,8 @@ p.todo, div.todo { background-color: #fdd; padding: 6; margin: 12; border-left: #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; } @@ -205,4 +207,5 @@ p.todo, div.todo { background-color: #fdd; padding: 6; margin: 12; border-left: text-align: left; font-size: 90%; font-weight: normal; -} \ No newline at end of file +} + diff --git a/conifer/syrup/urls.py b/conifer/syrup/urls.py index fee1c3d..cc11b73 100644 --- a/conifer/syrup/urls.py +++ b/conifer/syrup/urls.py @@ -21,6 +21,7 @@ urlpatterns = patterns('conifer.syrup.views', (r'^instructor/(?P.*)/$', 'instructor_detail'), (r'^department/(?P.*)/$', 'department_detail'), (r'^course/(?P\d+)/search/$', 'course_search'), + (r'^course/(?P\d+)/edit/$', 'edit_course'), (ITEM_PREFIX + r'$', 'item_detail'), (ITEM_PREFIX + r'dl/(?P.*)$', 'item_download'), (ITEM_PREFIX + r'meta$', 'item_metadata'), diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index 1c3a658..8dc951e 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -171,20 +171,32 @@ if COURSE_CODE_LIST: @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 diff --git a/conifer/templates/add_new_course.xhtml b/conifer/templates/add_new_course.xhtml index 3f39a6c..bf6bf7d 100644 --- a/conifer/templates/add_new_course.xhtml +++ b/conifer/templates/add_new_course.xhtml @@ -1,5 +1,8 @@ -
-
${course.department}
- ${course_search(course)} -

${course.code}: ${course.title}

+
+
+
${course.department}
+ ${course_search(course)} +

${course.code}: ${course.title}

+
diff --git a/conifer/templates/course_detail.xhtml b/conifer/templates/course_detail.xhtml index ee40bec..07c24a0 100644 --- a/conifer/templates/course_detail.xhtml +++ b/conifer/templates/course_detail.xhtml @@ -14,6 +14,9 @@ is_editor = course.can_edit(request.user) ${course_banner(course)} +

There are no items associated with this course yet.

-- 2.11.0