From 3a6dbb432b0f4872db8c4c1d7dd8aefb1e5cca2f Mon Sep 17 00:00:00 2001 From: Art Rhyno Date: Thu, 10 Apr 2014 11:49:34 -0400 Subject: [PATCH] Add Term Changeover option Moving courses to a new Term has previously been a process of going though each course site. This option allows groups of course sites to be copied over to a new Term all at once. Signed-off-by: Art Rhyno --- conifer/syrup/views/sites.py | 116 +++++++++++++++++++++++++++++++--- conifer/templates/admin/index.xhtml | 16 +++-- conifer/templates/browse_index.xhtml | 119 +++++++++++++++++++++++++++++++++-- 3 files changed, 231 insertions(+), 20 deletions(-) diff --git a/conifer/syrup/views/sites.py b/conifer/syrup/views/sites.py index 9eac7fe..83cc5a8 100644 --- a/conifer/syrup/views/sites.py +++ b/conifer/syrup/views/sites.py @@ -196,22 +196,118 @@ def my_sites(request): def my_tests(request): return g.render('my_test.xhtml', **locals()) +#add occurence value to sites +def add_to_sites(sites): + term_sites = [] + i = 0 + for site in sites: + term_sites.append([i,site]) + i = i + 1 + + return term_sites + +#get specified terms if provided +def get_sel_terms(request): + start_term = None + end_term = None + + if request.method == 'POST': + sel_start = int(request.POST['site_start_term']) + sel_end = int(request.POST['site_end_term']) + if sel_start > 0 and sel_end > 0: + start_term = models.Term.objects.get(pk=sel_start) + end_term = models.Term.objects.get(pk=sel_end) + + return start_term, end_term + +#get ids for selected sites +def get_sel_sites(request): + selected = [] + if request.method == 'POST': + sites_count = int(request.POST['sites_count']) + if sites_count > 0: + for i in range(sites_count): + site_bx = 'site_%d' % i + if site_bx in request.POST: + site_sel = request.POST[site_bx] + selected.append(int(site_sel)) + return selected + +#copy sites to new terms +def duplicate_sites(request,sel_sites,new_start_term,new_end_term): + duplicated = [] + if len(sel_sites) > 0 and new_start_term is not None and new_end_term is not None: + for sel in sel_sites: + sel_site = models.Site.objects.get(pk=sel) + course_site = models.Site.objects.create( + course = sel_site.course, + start_term = new_start_term, + end_term = new_end_term, + owner = sel_site.owner, + service_desk = sel_site.service_desk) + _copy_contents(request, sel_site, course_site) + duplicated.append(course_site.pk) + return duplicated + + +#set up query for browse display +def setup_site_list(browse_option, time_query, dup_list): + sites = None + blocks = None + if browse_option == 'Instructor': + if len(dup_list) == 0: + sites = list(models.Site.objects.order_by('owner__last_name', 'course__department__name', 'course__code'). + select_related().filter(time_query)) + else: + sites = list(models.Site.objects.order_by('owner__last_name', 'course__department__name', 'course__code'). + select_related().filter(id__in=dup_list)) + sites = add_to_sites(sites) + blocks = itertools.groupby(sites, lambda s: s[1].owner.last_name) + elif browse_option == 'Course': + if len(dup_list) == 0: + sites = list(models.Site.objects.order_by('course__code', 'owner__last_name', 'course__department__name'). + select_related().filter(time_query)) + else: + sites = list(models.Site.objects.order_by('course__code', 'owner__last_name', 'course__department__name'). + select_related().filter(id__in=dup_list)) + sites = add_to_sites(sites) + blocks = itertools.groupby(sites, lambda s: s[1].course.code) + else: + if len(dup_list) == 0: + sites = list(models.Site.objects.order_by('course__department__name', 'course__code', 'owner__last_name'). + select_related().filter(time_query)) + else: + sites = list(models.Site.objects.order_by('course__department__name', 'course__code', 'owner__last_name'). + select_related().filter(id__in=dup_list)) + sites = add_to_sites(sites) + blocks = itertools.groupby(sites, lambda s: s[1].course.department) + + return sites, blocks + def browse(request, browse_option='Department'): #the defaults should be moved into a config file or something... page_num = int(request.GET.get('page', 1)) count = int(request.GET.get('count', 5)) + + sel_sites = get_sel_sites(request) + start_term, end_term = get_sel_terms(request) timeframe = request.session.get('timeframe', 0) time_query = models.Term.timeframe_query(timeframe) + + term_sites = [] + show_terms = 0 queryset = None - if browse_option == 'Instructor': - sites = list(models.Site.objects.order_by('owner__last_name', 'course__department__name', 'course__code').select_related().filter(time_query)) - blocks = itertools.groupby(sites, lambda s: s.owner.last_name) - elif browse_option == 'Course': - sites = list(models.Site.objects.order_by('course__code', 'owner__last_name', 'course__department__name').select_related().filter(time_query)) - blocks = itertools.groupby(sites, lambda s: s.course.code) - else: - sites = list(models.Site.objects.order_by('course__department__name', 'course__code', 'owner__last_name').select_related().filter(time_query)) - blocks = itertools.groupby(sites, lambda s: s.course.department) + if request.method == 'POST': + term_sites = duplicate_sites(request,sel_sites,start_term,end_term) + + sites, blocks = setup_site_list(browse_option, time_query, term_sites) + + if not request.user.is_anonymous(): + if request.user.can_create_sites() and request.method == 'GET': + show_terms = int(request.GET.get('termdup', 0)) + if show_terms > 0: + instance = models.Site() + form = NewSiteForm(instance=instance) return g.render('browse_index.xhtml', **locals()) @@ -285,7 +381,7 @@ def _revert_parms(request, source_site): if barcode and orig_call and orig_desk and orig_modifier: update_status = opensrf.ils_item_update(barcode, orig_prefix, orig_call, orig_suffix, orig_modifier, orig_desk) - # print "update_status", update_status + #print "update_status", update_status if update_status: for sub in subitems: revert_item(parent, sub) diff --git a/conifer/templates/admin/index.xhtml b/conifer/templates/admin/index.xhtml index 263d679..d68a865 100644 --- a/conifer/templates/admin/index.xhtml +++ b/conifer/templates/admin/index.xhtml @@ -22,24 +22,28 @@ title = _('Administrative Options')
  • Service Desks
  • Departments
  • Courses
  • +
  • Term Changeover
  • Z39.50 Targets
  • Configuration settings
  • - - - - + + diff --git a/conifer/templates/browse_index.xhtml b/conifer/templates/browse_index.xhtml index 0082932..ecb544c 100644 --- a/conifer/templates/browse_index.xhtml +++ b/conifer/templates/browse_index.xhtml @@ -7,6 +7,9 @@ if browse_option == 'Instructor': elif browse_option == 'Course': option2 = _('Department') option3 = _('Instructor') +dup_option = _('Duplicate Courses') +check_option = _('Check/Uncheck All') +sites_count = len(sites) ?> All Reserves by ${browse_option} + +

    All Reserves by ${browse_option}

    (list by ${option2}, list by ${option3}) +
    + +

    All Reserves by ${browse_option}

    + (list by ${option2}, + list by ${option3}) +
    ${timeframe_nav(timeframe)}

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

    + +
    +
      +
    • ${err}
    • +
    +
    +
    + +

    ${dept}

    - + ${lock()}

    - - ${site} -

    + ${site[1]} +

    +
    + + +
    + + ${field.label} + +
      +
    • ${err}
    • +
    + ${Markup(field)} + + e.g., ${example} + + + ${field_row(form.start_term)} + ${field_row(form.end_term)} + + + + + +
    +
    ${check_option}
    +
    +

    ${dept}

    +
    + + ${site[1]} +
    +
    +
    + + ${field_row(form.start_term)} + ${field_row(form.end_term)} + + +
    ${check_option}
    +
    +
    +
    + + -- 2.11.0