def prepared_eadxml(request, archive, filename): """On GET, serves out a prepared version of the EAD file in the specified archive subversion directory. Response header is set so the user should be prompted to download the xml, with a filename matching that of the original document. On POST, commits the prepared version of the EAD file to the subversion directory of the specified archive, with a log message indicating the user who requested the commit. Steps taken to prepare a document are documented in :meth:`~findingaids.fa_admin.utils.prep_ead`. :param filename: name of the file to prep; should be base filename only, document will be pulled from the configured source directory. """ # find relative to svn path if associated with an archive prepped_xml = cache.get(filename) arch = get_object_or_404(Archive, slug=archive) fullpath = os.path.join(arch.svn_local_path, filename) if prepped_xml is None: try: ead = load_xmlobject_from_file(fullpath, FindingAid) # validate or not? except XMLSyntaxError, e: # xml is not well-formed : return 500 with error message return HttpResponseServerError("Could not load document: %s" % e) # flash meesage that appear on the screen for user, message itself is generated in utils.py with message_logging(request, 'findingaids.fa_admin.utils', logging.INFO): try: ead = utils.prep_ead(ead, filename) prepped_xml = ead.serializeDocument() cache.set(filename, prepped_xml) except Exception as e: # any exception on prep is most likely ark generation return HttpResponseServerError('Failed to prep the document: ' + str(e))
Steps taken to prepare a document are documented in :meth:`~findingaids.fa_admin.utils.prep_ead`. :param filename: name of the file to prep; should be base filename only, document will be pulled from the configured source directory. """ # find relative to svn path if associated with an archive arch = get_object_or_404(Archive, slug=archive) fullpath = os.path.join(arch.svn_local_path, filename) try: ead = load_xmlobject_from_file(fullpath, FindingAid) # validate or not? except XMLSyntaxError, e: # xml is not well-formed : return 500 with error message return HttpResponseServerError("Could not load document: %s" % e) with message_logging(request, 'findingaids.fa_admin.utils', logging.INFO): try: ead = utils.prep_ead(ead, filename) except Exception as e: # any exception on prep is most likely ark generation return HttpResponseServerError('Failed to prep the document: ' + str(e)) # on GET, display the xml and make available for download if request.method == 'GET': prepped_xml = ead.serializeDocument() response = HttpResponse(prepped_xml, mimetype='application/xml') response['Content-Disposition'] = "attachment; filename=%s" % filename return response # on POST, save to file and commit to subversion if request.method == 'POST':