def autoshare_delete(request, record, carenet): """ Remove an autoshare from a carenet. request.POST must contain: * *type*: the document schema namespace to remove an autoshare for This will effectively unshare all documents of type *type* from the carenet, except documents which were shared individually. Will return :http:statuscode:`200` on sucess, :http:statuscode:`404` if the specified *type* doesn't exist. """ TYPE = 'type' if request.POST.has_key(TYPE): try: docschema = DocumentSchema.objects.get( type=DocumentProcessing.expand_schema(request.POST[TYPE])) except DocumentSchema.DoesNotExist: raise Http404 CarenetAutoshare.objects.filter(record=record, carenet=carenet, type=docschema).delete() return DONE
def autoshare_list(request, record): """ For a single record, list all carenets that a given doctype is autoshared with. request.GET must contain: * *type*: the document schema namespace to check autoshares for Will return :http:statuscode:`200` with a list of carenets that have an autoshare set up for doctype *type* on success, :http:statuscode:`404` if the specified *type* doesn't exist. """ TYPE = 'type' autoshares = [] if request.GET.has_key(TYPE): try: docschema = DocumentSchema.objects.get( type=DocumentProcessing.expand_schema(request.GET[TYPE])) except DocumentSchema.DoesNotExist: raise Http404 carenets = [ autoshare.carenet for autoshare in CarenetAutoshare.objects.select_related().filter( record=record, type=docschema) ] return render_template('carenets', { 'carenets': carenets, 'record': record }, type="xml")
def document_list(request, limit, offset, status, order_by='created_at', record=None, pha=None): """ As of 2010-08-16, type is no longer part of the URL, it's only in the GET query parameters """ # SZ: CLEAN CODE! # SZ: CLEAN CODE! # SZ: CLEAN CODE! type = request.GET.get('type', None) type = DocumentProcessing.expand_schema(type) try: if type: try: type_obj = DocumentSchema.objects.get(type=type) if record: docs = record.documents.filter(type=type_obj, replaced_by=None, status=status, pha=pha).order_by(order_by) else: docs = Document.objects.filter(type=type_obj, pha=pha, replaced_by=None, status=status).order_by(order_by) return _render_documents(docs, record, pha, docs.count()) except DocumentSchema.DoesNotExist: raise Http404 docs = Document.objects.filter(record=record, replaced_by=None, pha=pha, status=status).order_by(order_by) except: docs = [] return _render_documents(docs[offset:offset+limit], record, pha, len(docs))
def autoshare_delete(request, record, carenet): """ Remove an autoshare from a carenet. request.POST must contain: * *type*: the document schema namespace to remove an autoshare for This will effectively unshare all documents of type *type* from the carenet, except documents which were shared individually. Will return :http:statuscode:`200` on sucess, :http:statuscode:`404` if the specified *type* doesn't exist. """ TYPE = 'type' if request.POST.has_key(TYPE): try: docschema = DocumentSchema.objects.get(type = DocumentProcessing.expand_schema(request.POST[TYPE])) except DocumentSchema.DoesNotExist: raise Http404 CarenetAutoshare.objects.filter(record = record, carenet = carenet, type = docschema).delete() return DONE
def document_list(request, limit, offset, status, order_by='created_at', record=None, pha=None): """ List Indivo documents. **Arguments:** * *request*: The incoming Django HttpRequest object. ``request.GET`` may contain: * *type*: The Indivo document schema type on which to filter the resut set. As of 2010-08-16, type is no longer part of the URL, it's only in the GET query parameters. * *limit*, *offset*, *status*, *order_by*: Standard paging and filtering arguments. See :py:func:`~indivo.lib.view_decorators.marsloader` or :doc:`/query-api`. * *record*: if desired documents are record-specific, this :py:class:`~indivo.models.records_and_documents.Record` instance refers to the record to filter on. * *pha*: if the desired documents are application-specific, this :py:class:`~indivo.models.apps.PHA` instance refers to the app to filter on. **Returns:** * an HTTPResponse whose body is an XML string containing the rendered list of documents (which might be empty), on success. **Raises:** * :py:exc:`django.http.Http404`: if *type* was passed, but didn't correspond to an existing Indivo schema. """ # SZ: CLEAN CODE! # SZ: CLEAN CODE! # SZ: CLEAN CODE! type = request.GET.get('type', None) type = DocumentProcessing.expand_schema(type) try: if type: try: type_obj = DocumentSchema.objects.get(type=type) if record: docs = record.documents.filter(type=type_obj, replaced_by=None, status=status, pha=pha).order_by(order_by) else: docs = Document.objects.filter(type=type_obj, pha=pha, replaced_by=None, status=status).order_by(order_by) return _render_documents(docs, record, pha, docs.count()) except DocumentSchema.DoesNotExist: raise Http404 docs = Document.objects.filter(record=record, replaced_by=None, pha=pha, status=status).order_by(order_by) except: docs = [] return _render_documents(docs[offset:offset+limit], record, pha, len(docs))
def document_list(request, query_options, record=None, pha=None): """ List Indivo documents. **Arguments:** * *request*: The incoming Django HttpRequest object. ``request.GET`` may contain: * *type*: The Indivo document schema type on which to filter the resut set. As of 2010-08-16, type is no longer part of the URL, it's only in the GET query parameters. * *limit*, *offset*, *status*, *order_by*: Standard paging and filtering arguments. See :py:func:`~indivo.lib.view_decorators.marsloader` or :doc:`/query-api`. * *record*: if desired documents are record-specific, this :py:class:`~indivo.models.records_and_documents.Record` instance refers to the record to filter on. * *pha*: if the desired documents are application-specific, this :py:class:`~indivo.models.apps.PHA` instance refers to the app to filter on. **Returns:** * an HTTPResponse whose body is an XML string containing the rendered list of documents (which might be empty), on success. **Raises:** * :py:exc:`django.http.Http404`: if *type* was passed, but didn't correspond to an existing Indivo schema. """ order_by = query_options['order_by'] offset = query_options['offset'] limit = query_options['limit'] status = query_options['status'] fqn = DocumentProcessing.expand_schema(request.GET.get('type', None)) try: if fqn: try: if record: docs = record.documents.filter(fqn=fqn, replaced_by=None, status=status, pha=pha).order_by(order_by) else: docs = Document.objects.filter(fqn=fqn, pha=pha, replaced_by=None, status=status).order_by(order_by) return _render_documents(docs, record, pha, docs.count()) except DocumentSchema.DoesNotExist: raise Http404 docs = Document.objects.filter(record=record, replaced_by=None, pha=pha, status=status).order_by(order_by) except: docs = [] return _render_documents(docs[offset:offset+limit], record, pha, len(docs))
def autoshare_delete(request, record, carenet): TYPE = 'type' if request.POST.has_key(TYPE): try: docschema = DocumentSchema.objects.get(type = DocumentProcessing.expand_schema(request.POST[TYPE])) except DocumentSchema.DoesNotExist: raise Http404 CarenetAutoshare.objects.filter(record = record, carenet = carenet, type = docschema).delete() return DONE
def autoshare_list(request, record): TYPE = 'type' autoshares = [] if request.GET.has_key(TYPE): try: docschema = DocumentSchema.objects.get(type = DocumentProcessing.expand_schema(request.GET[TYPE])) except DocumentSchema.DoesNotExist: raise Http404 carenets = [autoshare.carenet for autoshare in CarenetAutoshare.objects.select_related().filter( record = record, type = docschema)] return render_template('carenets', { 'carenets' : carenets, 'record' : record}, type="xml")
def document_list(request, limit, offset, status, order_by='created_at', record=None, pha=None): """ As of 2010-08-16, type is no longer part of the URL, it's only in the GET query parameters """ # SZ: CLEAN CODE! # SZ: CLEAN CODE! # SZ: CLEAN CODE! type = request.GET.get('type', None) type = DocumentProcessing.expand_schema(type) try: if type: try: type_obj = DocumentSchema.objects.get(type=type) if record: docs = record.documents.filter(type=type_obj, replaced_by=None, status=status, pha=pha).order_by(order_by) else: docs = Document.objects.filter( type=type_obj, pha=pha, replaced_by=None, status=status).order_by(order_by) return _render_documents(docs, record, pha, docs.count()) except DocumentSchema.DoesNotExist: raise Http404 docs = Document.objects.filter(record=record, replaced_by=None, pha=pha, status=status).order_by(order_by) except: docs = [] return _render_documents(docs[offset:offset + limit], record, pha, len(docs))
def autoshare_create(request, record, carenet): """ Automatically share all documents of a certain type into a carenet. request.POST must contain: * *type*: the document schema namespace to create an autoshare for Will return :http:statuscode:`200` on sucess, :http:statuscode:`404` if the specified *type* doesn't exist. """ TYPE = 'type' if request.POST.has_key(TYPE): try: docschema = DocumentSchema.objects.get(type = DocumentProcessing.expand_schema(request.POST[TYPE])) except DocumentSchema.DoesNotExist: raise Http404 CarenetAutoshare.objects.create(record = record, carenet = carenet, type = docschema) return DONE
def autoshare_create(request, record, carenet): """ Automatically share all documents of a certain type into a carenet. request.POST must contain: * *type*: the document schema namespace to create an autoshare for Will return :http:statuscode:`200` on sucess, :http:statuscode:`404` if the specified *type* doesn't exist. """ TYPE = 'type' if request.POST.has_key(TYPE): try: docschema = DocumentSchema.objects.get( type=DocumentProcessing.expand_schema(request.POST[TYPE])) except DocumentSchema.DoesNotExist: raise Http404 CarenetAutoshare.objects.create(record=record, carenet=carenet, type=docschema) return DONE
def autoshare_list(request, record): """ For a single record, list all carenets that a given doctype is autoshared with. request.GET must contain: * *type*: the document schema namespace to check autoshares for Will return :http:statuscode:`200` with a list of carenets that have an autoshare set up for doctype *type* on success, :http:statuscode:`404` if the specified *type* doesn't exist. """ TYPE = 'type' autoshares = [] if request.GET.has_key(TYPE): try: docschema = DocumentSchema.objects.get(type = DocumentProcessing.expand_schema(request.GET[TYPE])) except DocumentSchema.DoesNotExist: raise Http404 carenets = [autoshare.carenet for autoshare in CarenetAutoshare.objects.select_related().filter( record = record, type = docschema)] return render_template('carenets', { 'carenets' : carenets, 'record' : record}, type="xml")