def v_document_delete(document_id): document_api = DocumentApi() form = GenericDeleteForm() try: existing_document = document_api.read(document_id) except DatabaseItemDoesNotExist as e: flash(_('No document with id {0}').format(document_id)) return redirect(url_for('admin.v_document_list')) except Exception as e: flash(_('An unexpected error occurred: {0}').format(e)) # flash('An unexpected error occurred.') return redirect(url_for('admin.v_document_list')) if request.method == 'POST' and form.validate_on_submit(): # First delete the attached file if existing_document.filename and existing_document.filename != '': file_api = FileApi() try: file_api.delete(existing_document.filename) except FileDoesNotExist: flash( _('Unable to delete attached file. The document was not deleted' )) return render_template('admin/generic/delete.html', action_url=url_for( 'admin.v_document_delete', document_id=document_id), item_type=_('Document'), item_identifier=document_id, form=form) if document_api.delete(document_id) is True: flash(_('Document {0} deleted').format(document_id)) return redirect(url_for('admin.v_document_list')) else: flash(_('Unable to delete document {0}').format(document_id)) return render_template('admin/generic/delete.html', action_url=url_for( 'admin.v_document_delete', document_id=document_id), item_type=_('Document'), item_identifier=document_id, form=form) return render_template('admin/generic/delete.html', action_url=url_for('admin.v_document_delete', document_id=document_id), item_type=_('Document'), item_identifier=document_id, form=form)
def v_document_edit(document_id): document_api = DocumentApi() try: existing_document = document_api.read(document_id) except DatabaseItemDoesNotExist as e: flash(_('No document with id {0}').format(document_id)) return redirect(url_for('admin.v_document_list')) except Exception as e: flash(_('An unexpected error occurred: {0}').format(e)) # flash('An unexpected error occurred.') return redirect(url_for('admin.v_document_list')) lang_api = LangApi() languages = lang_api.list() return render_template('admin/document/create.html', languages=languages, document=existing_document)
def hook_check_filename(input_data): parsed_data = input_data document_api = DocumentApi() try: existing_document = document_api.read(document_id) except Exception as e: return input_data if 'original_filename' not in parsed_data: return input_data if parsed_data[ 'original_filename'] != existing_document.original_filename: raise RequiredAttributeMissing( _('You cannot modify original_filename!')) if 'filename' in parsed_data and parsed_data[ 'filename'] != existing_document.filename: raise RequiredAttributeMissing(_('You cannot modify filename!')) return input_data
def v_api_document_resource(document_id): file_api = FileApi() document_api = DocumentApi() try: existing_document = document_api.read(document_id) except DatabaseItemDoesNotExist as e: response = make_response() response.status_code = 404 return response except Exception as e: response = make_response() response.status_code = 400 return response try: existing_file = file_api.read(existing_document.filename) except FileDoesNotExist as e: response = make_response() response.status_code = 404 return response return send_from_directory(app.config['UPLOAD_FULL_PATH'], existing_file['filename'])