From: Art Rhyno Date: Sat, 5 Jul 2014 21:26:51 +0000 (-0400) Subject: Fix Up Parts Support for Copy/Paste and Term Duplication X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9d39ec485306319d4a9b7ca7f7b92b48704124d2;p=Syrup.git Fix Up Parts Support for Copy/Paste and Term Duplication There was a bug that was causing titles with multiple parts to drop everything but the first part when using the copy/paste mechanism and/or duplicating courses across Terms. This should bring the other parts along as well. Signed-off-by: Art Rhyno --- diff --git a/conifer/syrup/views/sites.py b/conifer/syrup/views/sites.py index 8dd3878..035b3c0 100644 --- a/conifer/syrup/views/sites.py +++ b/conifer/syrup/views/sites.py @@ -407,26 +407,46 @@ def site_clipboard_copy_from(request, site_id): _('This site has been marked as the copying source. Visit the new site, ' 'and click "Paste to Here," to copy this site\'s materials into the new site.')) +#a part with a barcode will be picked up once, add other entries if other barcodes are also there +def sort_out_parts(theid,bc,bcs,tids): + partids = [] + partbcs = [] + + if len(tids) > 0: + if theid in tids[0]: + print "would add", bcs + partids = tids[0] + partpos = partids.index(theid) + partbcs = bcs[0] + + if len(partbcs) == 0: + partbcs.append(bc) + + return partbcs def _copy_contents(request, source_site, dest_site): item_map = {} - def process_item(parent, (item, subitems,extra1,extra2)): + def process_item(parent, (item, subs, barcodes, titleids)): dct = dict((k,v) for k,v in item.__dict__.items() if not k.startswith('_')) old_id = dct['id'] del dct['id'] dct['parent_heading_id'] = parent.id if parent else None - newitem = models.Item.objects.create(**dct) - newitem.site = dest_site - newitem.save() - item_map[old_id] = newitem.id - for sub in subitems: + partbcs = sort_out_parts(int(old_id),dct['barcode'],barcodes,titleids) + for bc in partbcs: + newitem = models.Item.objects.create(**dct) + newitem.site = dest_site + newitem.barcode = bc + newitem.save() + item_map[old_id] = newitem.id + for sub in subs: process_item(newitem, sub) for branch in source_site.item_tree(): process_item(None, branch) request.session['last_paste'] = (source_site.id, dest_site.id, item_map.values()) + def site_clipboard_paste_to(request, site_id): source_id = request.session['copy_source'] source_site = get_object_or_404(models.Site, pk=source_id)