Esempio n. 1
0
def document_meta(request, docbox, document=None, pha=None, external_id=None, app_specific = False):
  """
  The metadata for a single document
  
  The app-specific parameter needs to be specified in the URL route
  """

  if not document:
    try:
      if docbox and docbox.record:
        full_external_id = Document.prepare_external_id(external_id, pha = pha, pha_specific = app_specific)

        # clear the pha argument if it's not app specific
        if not app_specific:
          pha = None

        document = docbox.record.documents.get(record=docbox.record, pha=pha, external_id = full_external_id)
      else:
        full_external_id = Document.prepare_external_id(external_id, pha = pha,
                                                        pha_specific = app_specific, record_specific=False)
        document = Document.objects.get(record=None, pha=pha, external_id = full_external_id)
    except Document.DoesNotExist:
      raise Http404
    except MultipleObjectsReturned:
      return HttpResponseBadRequest("Multiple external_ids returned, db is in a corrupted state")
  _set_doc_latest(document)

  # related stuff
  document.relates_to, document.is_related_from = _get_doc_relations(document)

  return render_template('single_document', {'doc' : document, 'record': document.record})
def _document_meta(record=None, carenet=None, document=None, pha=None, external_id=None, app_specific=False):
  """
  The metadata for a single document
  """
  if carenet:
    record = carenet.record

  if not document:
    full_external_id = Document.prepare_external_id(external_id, pha=pha, 
                                                    pha_specific=app_specific, 
                                                    record_specific=(record is not None))
    if not full_external_id:
      raise Http404

    if not app_specific:
      pha = None
    document = _get_document(record=record, pha=pha, external_id=full_external_id)
    if not document:
      raise Http404

  _set_doc_latest(document)

  # related stuff
  document.relates_to, document.is_related_from = _get_doc_relations(document)

  return render_template('single_document', {'doc' : document, 'record': document.record})
def get_doc_obj_rels(doc_id):
  #print doc_id
  try:
    document = Document.objects.get(id=doc_id)
    document.relates_to, document.is_related_from = _get_doc_relations(document)
    return loader.get_template('document.xml').render(Context({'doc':document}))
  except Exception, e:
    return "Exception: " + str(e)
def get_doc_obj_rels(doc_id):
    print doc_id
    try:
        document = Document.objects.get(id=doc_id)
        document.relates_to, document.is_related_from = _get_doc_relations(
            document)
        return loader.get_template('document.xml').render(
            Context({'doc': document}))
    except Exception, e:
        return "Exception: " + str(e)
def get_doc_obj(doc_id):
  try:
    doc = Document.objects.get(id=doc_id)
    
    # append the doc metadata
    _set_doc_latest(doc)
    doc.relates_to, doc.is_related_from = _get_doc_relations(doc)

    return loader.get_template('document.xml').render(Context({'doc': doc, 'record': doc.record}))
  except:
    return ""
Esempio n. 6
0
def get_doc_obj(doc_id):
    try:
        doc = Document.objects.get(id=doc_id)

        # append the doc metadata
        _set_doc_latest(doc)
        doc.relates_to, doc.is_related_from = _get_doc_relations(doc)

        return loader.get_template('document.xml').render(
            Context({
                'doc': doc,
                'record': doc.record
            }))
    except:
        return ""
Esempio n. 7
0
def _document_meta(record=None,
                   carenet=None,
                   document=None,
                   pha=None,
                   external_id=None,
                   app_specific=False):
    """
  The metadata for a single document
  """
    if carenet:
        record = carenet.record

    if not document:
        full_external_id = Document.prepare_external_id(
            external_id,
            pha=pha,
            pha_specific=app_specific,
            record_specific=(record is not None))
        if not full_external_id:
            raise Http404

        if not app_specific:
            pha = None
        document = _get_document(record=record,
                                 pha=pha,
                                 external_id=full_external_id)
        if not document:
            raise Http404

    _set_doc_latest(document)

    # related stuff
    document.relates_to, document.is_related_from = _get_doc_relations(
        document)

    return render_template('single_document', {
        'doc': document,
        'record': document.record
    })
Esempio n. 8
0
def _document_meta(record=None, carenet=None, document=None, pha=None, external_id=None, app_specific=False):
  """ Fetch the metadata of a single document.
  
  Metadata includes:
  
  * id

  * date created
  
  * creator 

  * the document that replaced this one

  * the document that this one replaces

  * the original document in the version chain

  * the latest document in the version chain

  * label

  * current status

  * nevershare status

  * related documents
  

  **ARGUMENTS:**
  
  * *record*: The 
    :py:class:`~indivo.models.records_and_documents.Record` that
    the document is scoped to, if applicable.

  * *carenet*: The 
    :py:class:`~indivo.models.shares.Carenet` that
    the document is shared into, if applicable.

  * *document*: The document to get metadata for, if it has been prefetched.

    .. Note::

       One of *external_id* or *document* MUST be passed to this function, 
       or it cannot retrieve a unique document.

  * *pha*: The :py:class:`~indivo.models.apps.PHA` object that the
    document is scoped to. Also serves to scope *external_id*, if present and
    *app_specific* is ``True``.

  * *external_id*: The external identifier of the document to re-label.

    .. Note::

       One of *external_id* or *document* MUST be passed to this function, 
       or it cannot retrieve a unique document.

  * *app_specific*: Whether or not the document is app-specific. The mere presence
    of the *pha* argument isn't enough to satisfy this question, as *pha* might
    have been passed in only to scope an external id for a non-app-specific
    document.

  **RETURNS:**

  * An HttpResponse object with an XML string describing the document metadata
    on success.

  **RAISES:**

  * :py:exc:`django.http.Http404` if *document* isn't passed and *external_id*
    doesn't identify an existing document.

  """

  if carenet:
    record = carenet.record

  if not document:
    full_external_id = Document.prepare_external_id(external_id, pha=pha, 
                                                    pha_specific=app_specific, 
                                                    record_specific=(record is not None))
    if not full_external_id:
      raise Http404

    if not app_specific:
      pha = None
    document = _get_document(record=record, pha=pha, external_id=full_external_id)
    if not document:
      raise Http404

  _set_doc_latest(document)

  # related stuff
  document.relates_to, document.is_related_from = _get_doc_relations(document)

  return render_template('single_document', {'doc' : document, 'record': document.record})