def bulk_download(cls, request, items): out = [] if request.GET.get('title', None): out.append(request.GET.get('title')) else: out.append("Auto-generated document") item_querysets = items_for_bulk_download(items, request) for model, details in item_querysets.items(): out.append(model.get_verbose_name()) for item in details['qs']: template = select_template([ get_download_template_path_for_item(item, cls.download_type, subpath="inline"), ]) context = { 'item': item, 'request': request, } out.append(template.render(context)) return HttpResponse("\n\n".join(out), content_type='text/plain')
def downloadMenu(item): """ Returns the complete download menu for a partcular item. It accepts the id of the item to make a download menu for, and the id must be of an item that can be downloaded, otherwise the links will show, but not work. For example:: {% downloadMenu item %} """ from django.conf import settings from django.template.loader import get_template from django.template import Context downloadOpts = getattr(settings, 'ARISTOTLE_DOWNLOADS', "") from aristotle_mdr.utils import get_download_template_path_for_item downloadsForItem = [] for d in downloadOpts: downloadType = d[0] try: get_template(get_download_template_path_for_item(item,downloadType)) downloadsForItem.append(d) except template.TemplateDoesNotExist: pass return get_template("aristotle_mdr/helpers/downloadMenu.html").render( Context({'item':item,'downloadOptions':downloadsForItem,}) )
def download(cls, request, item): template = get_download_template_path_for_item(item, cls.download_type) response = render(request, template, {'item': item}, content_type='text/plain') return response
def download(request, downloadType, item): template = get_download_template_path_for_item(item, downloadType) response = render(request, template, {'item': item}, content_type='text/plain') return response
def bulk_download(properties, iids): items = [] out = properties.get('out', []) # Getting user from the available email data User = get_user_model() user = properties.get('user', None) if user and user != str(AnonymousUser()): user = User.objects.get(email=user) else: user = AnonymousUser() for iid in iids: item = MDR._concept.objects.get_subclass(pk=iid) if item.can_view(user): items.append(item) item_querysets = items_for_bulk_download(items, user) for model, details in item_querysets.items(): out.append(model.get_verbose_name()) for item in details['qs']: template = select_template([ get_download_template_path_for_item( item, TestTextDownloader.download_type, subpath="inline"), ]) context = { 'item': item, } out.append(template.render(context)) TestTextDownloader.cache_file( TestTextDownloader.get_cache_key(user, iids), ("\n\n".join(out), 'text/plain', {})) return True
def download(request,downloadType,item): template = get_download_template_path_for_item(item,downloadType) from django.conf import settings page_size = getattr(settings, 'PDF_PAGE_SIZE', "A4") if downloadType=="pdf": subItems = item.getPdfItems return render_to_pdf(template, {'item':item, 'items':subItems, 'tableOfContents':len(subItems)>0, 'view':request.GET.get('view','').lower(), 'pagesize':request.GET.get('pagesize',page_size), } ) elif downloadType=="csv-vd": response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="%s.csv"'%item.name writer = csv.writer(response) writer.writerow(['value', 'meaning','start date','end date', 'role']) for v in item.permissibleValues.all(): writer.writerow([v.value, v.meaning,v.start_date,v.end_date,"permissible"]) for v in item.supplementaryValues.all(): writer.writerow([v.value, v.meaning,v.start_date,v.end_date,"supplementary"]) return response
def downloadMenu(item): """ Returns the complete download menu for a partcular item. It accepts the id of the item to make a download menu for, and the id must be of an item that can be downloaded, otherwise the links will show, but not work. For example:: {% downloadMenu item %} """ from django.conf import settings from django.template.loader import get_template from django.template import Context downloadOpts = getattr(settings, 'ARISTOTLE_DOWNLOADS', "") from aristotle_mdr.utils import get_download_template_path_for_item downloadsForItem = [] for d in downloadOpts: downloadType = d[0] try: get_template( get_download_template_path_for_item(item, downloadType)) downloadsForItem.append(d) except template.TemplateDoesNotExist: pass # This is ok. except: pass # Something very bad has happened in the template. return get_template("aristotle_mdr/helpers/downloadMenu.html").render( Context({ 'item': item, 'downloadOptions': downloadsForItem, }))
def bulk_download(properties, iids): items = [] out = properties.get('out', []) # Getting user from the available email data User = get_user_model() user = properties.get('user', None) if user and user != str(AnonymousUser()): user = User.objects.get(email=user) else: user = AnonymousUser() for iid in iids: item = MDR._concept.objects.get_subclass(pk=iid) if item.can_view(user): items.append(item) item_querysets = items_for_bulk_download(items, user) for model, details in item_querysets.items(): out.append(model.get_verbose_name()) for item in details['qs']: template = select_template([ get_download_template_path_for_item(item, TestTextDownloader.download_type, subpath="inline"), ]) context = { 'item': item, } out.append(template.render(context)) TestTextDownloader.cache_file(TestTextDownloader.get_cache_key(user, iids), ("\n\n".join(out), 'text/plain', {})) return True
def download(properties, iid): """Built in download method create pdf_context and return the results to celery backend. :param properties: properties of the pdf template to be generated :param iid: id of the item :return: return the iid of the task """ User = get_user_model() user = properties['user'] if user and user != str(AnonymousUser()): user = User.objects.get(email=user) else: user = AnonymousUser() item = MDR._concept.objects.get_subclass(pk=iid) item = get_if_user_can_view(item.__class__, user, iid) template = get_download_template_path_for_item(item, PDFDownloader.download_type) sub_items = [ (obj_type, qs.visible(user).order_by('name').distinct()) for obj_type, qs in item.get_download_items() ] PDFDownloader.cache_file(PDFDownloader.get_cache_key(user, iid), (render_to_pdf(template, { 'title': properties['title'], 'item': item, 'subitems': sub_items, 'tableOfContents': len(sub_items) > 0, 'view': properties['view'].lower(), 'pagesize': properties['page_size'], }), 'application/pdf', {})) return iid
def download(request, downloadType, item): """Built in download method""" template = get_download_template_path_for_item(item, downloadType) from django.conf import settings page_size = getattr(settings, 'PDF_PAGE_SIZE', "A4") if downloadType == "pdf": subItems = item.get_download_items() return render_to_pdf( template, { 'item': item, 'subitems': subItems, 'tableOfContents': len(subItems) > 0, 'view': request.GET.get('view', '').lower(), 'pagesize': request.GET.get('pagesize', page_size), }) elif downloadType == "csv-vd": response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="%s.csv"' % ( item.name) writer = csv.writer(response) writer.writerow(['value', 'meaning', 'start date', 'end date', 'role']) for v in item.permissibleValues.all(): writer.writerow( [v.value, v.meaning, v.start_date, v.end_date, "permissible"]) for v in item.supplementaryValues.all(): writer.writerow([ v.value, v.meaning, v.start_date, v.end_date, "supplementary" ]) return response
def download(properties, iid): """Built in download method create pdf_context and return the results to celery backend. :param properties: properties of the pdf template to be generated :param iid: id of the item :return: return the iid of the task """ User = get_user_model() user = properties['user'] if user and user != str(AnonymousUser()): user = User.objects.get(email=user) else: user = AnonymousUser() item = MDR._concept.objects.get_subclass(pk=iid) item = get_if_user_can_view(item.__class__, user, iid) template = get_download_template_path_for_item( item, PDFDownloader.download_type) sub_items = [(obj_type, qs.visible(user).order_by('name').distinct()) for obj_type, qs in item.get_download_items()] PDFDownloader.cache_file(PDFDownloader.get_cache_key(user, iid), (render_to_pdf( template, { 'title': properties['title'], 'item': item, 'subitems': sub_items, 'tableOfContents': len(sub_items) > 0, 'view': properties['view'].lower(), 'pagesize': properties['page_size'], }), 'application/pdf', {})) return iid
def download(request,downloadType,item): template = get_download_template_path_for_item(item,downloadType) response = render(request,template, {'item':item, }, content_type='application/xml' ) #response['Content-Disposition'] = 'attachment; filename=%s.ddi.xml'%item.id return response
def downloadMenu(item): """ Returns the complete download menu for a partcular item. It accepts the id of the item to make a download menu for, and the id must be of an item that can be downloaded, otherwise the links will show, but not work. For example:: {% downloadMenu item %} """ from django.conf import settings from django.template.loader import get_template from django.template import Context downloadOpts = getattr(settings, 'ARISTOTLE_DOWNLOADS', "") from aristotle_mdr.utils import get_download_template_path_for_item from aristotle_mdr.utils.downloads import get_download_module downloadsForItem = [] app_label = item._meta.app_label model_name = item._meta.model_name for d in downloadOpts: download_type = d[0] module_name = d[3] downloader = get_download_module(module_name) item_register = getattr(downloader, 'item_register', {}) dl = item_register.get(download_type, {}) if type(dl) is not str: if dl.get(app_label, []) == '__all__': downloadsForItem.append(d) elif model_name in dl.get(app_label, []): downloadsForItem.append(d) else: if dl == '__all__': downloadsForItem.append(d) elif dl == '__template__': try: get_template( get_download_template_path_for_item( item, download_type)) downloadsForItem.append(d) except template.TemplateDoesNotExist: pass # This is ok. except: pass # Something very bad has happened in the template. return get_template("aristotle_mdr/helpers/downloadMenu.html").render( Context({ 'item': item, 'download_options': downloadsForItem, }))
def downloadMenu(item): """ Returns the complete download menu for a partcular item. It accepts the id of the item to make a download menu for, and the id must be of an item that can be downloaded, otherwise the links will show, but not work. For example:: {% downloadMenu item %} """ from django.template.loader import get_template downloadOpts = fetch_aristotle_downloaders() from aristotle_mdr.utils import get_download_template_path_for_item downloadsForItem = [] app_label = item._meta.app_label model_name = item._meta.model_name for d in downloadOpts: download_type = d.download_type item_register = d.metadata_register if type(item_register) is not str: if item_register.get(app_label, []) == '__all__': downloadsForItem.append(d) elif model_name in item_register.get(app_label, []): downloadsForItem.append(d) else: if item_register == '__all__': downloadsForItem.append(d) elif item_register == '__template__': try: get_template( get_download_template_path_for_item( item, download_type)) downloadsForItem.append(d) except template.TemplateDoesNotExist: pass # This is ok. except: # TODO: Should probably do something with this error pass # Something very bad has happened in the template. return get_template("aristotle_mdr/helpers/downloadMenu.html").render({ 'item': item, 'download_options': downloadsForItem, })
def downloadMenu(item): """ Returns the complete download menu for a partcular item. It accepts the id of the item to make a download menu for, and the id must be of an item that can be downloaded, otherwise the links will show, but not work. For example:: {% downloadMenu item %} """ from django.conf import settings from django.template.loader import get_template from django.template import Context downloadOpts = getattr(settings, 'ARISTOTLE_DOWNLOADS', "") from aristotle_mdr.utils import get_download_template_path_for_item from aristotle_mdr.utils.downloads import get_download_module downloadsForItem = [] app_label = item._meta.app_label model_name = item._meta.model_name for d in downloadOpts: download_type = d[0] module_name = d[3] downloader = get_download_module(module_name) item_register = getattr(downloader, 'item_register', {}) dl = item_register.get(download_type, {}) if type(dl) is not str: if dl.get(app_label, []) == '__all__': downloadsForItem.append(d) elif model_name in dl.get(app_label, []): downloadsForItem.append(d) else: if dl == '__all__': downloadsForItem.append(d) elif dl == '__template__': try: get_template(get_download_template_path_for_item(item, download_type)) downloadsForItem.append(d) except template.TemplateDoesNotExist: pass # This is ok. except: pass # Something very bad has happened in the template. return get_template("aristotle_mdr/helpers/downloadMenu.html").render( Context({'item': item, 'download_options': downloadsForItem, }) )
def downloadMenu(item): """ Returns the complete download menu for a partcular item. It accepts the id of the item to make a download menu for, and the id must be of an item that can be downloaded, otherwise the links will show, but not work. For example:: {% downloadMenu item %} """ downloadOpts = fetch_aristotle_downloaders() from aristotle_mdr.utils import get_download_template_path_for_item downloadsForItem = [] app_label = item._meta.app_label model_name = item._meta.model_name for d in downloadOpts: template_type = d.template_type item_register = d.metadata_register if type(item_register) is not str: if item_register.get(app_label, []) == '__all__': downloadsForItem.append(d) elif model_name in item_register.get(app_label, []): downloadsForItem.append(d) else: if item_register == '__all__': downloadsForItem.append(d) elif item_register == '__template__': try: get_template( get_download_template_path_for_item( item, template_type)) downloadsForItem.append(d) except template.TemplateDoesNotExist: pass # This is ok. dlOptionsForItem = [] for dl_class in downloadsForItem: dlOptionsForItem.append(dl_class.get_class_info()) return { 'item': item, 'download_options': dlOptionsForItem, }
def download(request,downloadType,item): template = get_download_template_path_for_item(item,downloadType) from django.conf import settings page_size = getattr(settings, 'PDF_PAGE_SIZE', "A4") if downloadType=="pdf": subItems = item.getPdfItems return render_to_pdf(template, {'item':item, 'items':subItems, 'tableOfContents':len(subItems)>0, 'view':request.GET.get('view','').lower(), 'pagesize':request.GET.get('pagesize',page_size), } ) raise Http404
def download(properties, iid): User = get_user_model() user = properties['user'] if user and user != str(AnonymousUser): user = User.objects.get(email=user) else: user = AnonymousUser() item = MDR._concept.objects.get_subclass(pk=iid) item = get_if_user_can_view(item.__class__, user, iid) template = get_download_template_path_for_item(item, TestTextDownloader.download_type) template = select_template([template]) context = {'item': item} txt = template.render(context) TestTextDownloader.cache_file(TestTextDownloader.get_cache_key(user, iid), (txt, 'text/plain', {})) return item
def downloadMenu(item): """ Returns the complete download menu for a partcular item. It accepts the id of the item to make a download menu for, and the id must be of an item that can be downloaded, otherwise the links will show, but not work. For example:: {% downloadMenu item %} """ from django.template.loader import get_template downloadOpts = fetch_aristotle_downloaders() from aristotle_mdr.utils import get_download_template_path_for_item downloadsForItem = [] app_label = item._meta.app_label model_name = item._meta.model_name for d in downloadOpts: download_type = d.download_type item_register = d.metadata_register if type(item_register) is not str: if item_register.get(app_label, []) == '__all__': downloadsForItem.append(d) elif model_name in item_register.get(app_label, []): downloadsForItem.append(d) else: if item_register == '__all__': downloadsForItem.append(d) elif item_register == '__template__': try: get_template(get_download_template_path_for_item(item, download_type)) downloadsForItem.append(d) except template.TemplateDoesNotExist: pass # This is ok. except: # TODO: Should probably do something with this error pass # Something very bad has happened in the template. return get_template( "aristotle_mdr/helpers/downloadMenu.html").render( {'item': item, 'download_options': downloadsForItem, } )
def download(cls, request, item): """Built in download method""" template = get_download_template_path_for_item(item, cls.download_type) from django.conf import settings response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="%s.csv"' % ( item.name) writer = csv.writer(response) writer.writerow(['value', 'meaning', 'start date', 'end date', 'role']) for v in item.permissibleValues.all(): writer.writerow( [v.value, v.meaning, v.start_date, v.end_date, "permissible"]) for v in item.supplementaryValues.all(): writer.writerow([ v.value, v.meaning, v.start_date, v.end_date, "supplementary" ]) return response
def download(properties, iid): User = get_user_model() user = properties['user'] if user and user != str(AnonymousUser): user = User.objects.get(email=user) else: user = AnonymousUser() item = MDR._concept.objects.get_subclass(pk=iid) item = get_if_user_can_view(item.__class__, user, iid) template = get_download_template_path_for_item( item, TestTextDownloader.download_type) template = select_template([template]) context = {'item': item} txt = template.render(context) TestTextDownloader.cache_file( TestTextDownloader.get_cache_key(user, iid), (txt, 'text/plain', {})) return item
def download(cls, request, item): """Built in download method""" template = get_download_template_path_for_item(item, cls.download_type) from django.conf import settings page_size = getattr(settings, 'PDF_PAGE_SIZE', "A4") subItems = [(obj_type, qs.visible(request.user).order_by('name').distinct()) for obj_type, qs in item.get_download_items()] return render_to_pdf( template, { 'title': "PDF Download for {obj.name}".format(obj=item), 'item': item, 'subitems': subItems, 'tableOfContents': len(subItems) > 0, 'view': request.GET.get('view', '').lower(), 'pagesize': request.GET.get('pagesize', page_size), 'request': request, }, )
def download(cls, request, item): """Built in download method""" template = get_download_template_path_for_item(item, cls.download_type) from django.conf import settings page_size = getattr(settings, 'PDF_PAGE_SIZE', "A4") subItems = [ (obj_type, qs.visible(request.user).order_by('name').distinct()) for obj_type, qs in item.get_download_items() ] return render_to_pdf( template, { 'title': "PDF Download for {obj.name}".format(obj=item), 'item': item, 'subitems': subItems, 'tableOfContents': len(subItems) > 0, 'view': request.GET.get('view', '').lower(), 'pagesize': request.GET.get('pagesize', page_size), 'request': request, }, )
def template_path(item, _type): from aristotle_mdr.utils import get_download_template_path_for_item _type, subpath = _type.split(',') return get_download_template_path_for_item(item, _type, subpath)
def template_path(item, _type): from aristotle_mdr.utils import get_download_template_path_for_item _type, subpath=_type.split(',') return get_download_template_path_for_item(item, _type, subpath)