def _get_document(self, pk): if isinstance(pk, int) or (pk and pk.isdigit()): query = Document.all().where(Document._meta.primary_key == pk) try: return query.get() except Document.DoesNotExist: pass return get_object_or_404(Document.all(), Document.identifier == pk)
def attachment_download(document_id, pk): document = get_object_or_404(Document.all(), Document._meta.primary_key == document_id) attachment = get_object_or_404(document.attachments, Attachment.filename == pk) response = make_response(attachment.blob.data) response.headers['Content-Type'] = attachment.mimetype response.headers['Content-Length'] = attachment.length response.headers['Content-Disposition'] = 'inline; filename=%s' % ( attachment.filename) return response
def refresh_doc(self, doc): return (Document.all().where( Document._meta.primary_key == doc.get_id()).get())