def get_citation_for_draft(self, request, accession_id, draftcitation_id):

        draftcitation = get_object_or_404(DraftCitation, pk=draftcitation_id)

        if draftcitation.resolutions.count() == 1:
            citation = draftcitation.resolutions.first().to_instance
        else:
            try:
                iso_publication_date = iso8601.parse_date(draftcitation.publication_date).date()
            except iso8601.ParseError:
                iso_publication_date = None

            creation_msg = self._get_creation_message(request, draftcitation)
            pages = '%s - %s' % (draftcitation.page_start,
                                 draftcitation.page_end)
            if draftcitation.pages_free_text:
                pages_free_text = draftcitation.pages_free_text
            else:
                pages_free_text = '%s - %s' % (draftcitation.page_start,
                                               draftcitation.page_end)

            part_details = PartDetails(**{
                'page_begin': draftcitation.page_start,
                'page_end': draftcitation.page_end,
                'pages_free_text': pages_free_text,
                'volume': draftcitation.volume,
                'issue_free_text': draftcitation.issue,
            })
            part_details.save()

            citation = Citation(**{
                'title': draftcitation.title,
                'description': draftcitation.description,
                'abstract': draftcitation.abstract,
                'type_controlled': draftcitation.type_controlled,
                'record_history': creation_msg,
                'part_details': part_details,
            })

            if iso_publication_date:
                citation.publication_date = iso_publication_date
            citation.save()

            InstanceResolutionEvent(for_instance=draftcitation,
                                    to_instance=citation).save()

            # If the publication date is available and parse-able, create the
            #  Attribute and other attendant objects.
            if iso_publication_date:
                # Chances are good that this already exists, but just in case.
                attribute_type, _ = AttributeType.objects.get_or_create(
                    name='PublicationDate',
                    defaults={
                        'value_content_type': ContentType.objects.get(model='datevalue'),
                        'display_name': 'Publication Date',
                    }
                )

                attribute = Attribute.objects.create(
                    value_freeform=draftcitation.publication_date,
                    source=citation,
                    type_controlled=attribute_type,
                )
                value = DateValue.objects.create(
                    value=iso_publication_date,
                    attribute=attribute,
                )

            for draftacrelation in draftcitation.authority_relations.all():
                self._get_or_create_acrelation(request, draftcitation,
                                               citation, draftacrelation)

            # Reload the Citation instance so that we are assured to have all
            #  of the updated fields/relations. This might be overkill, but a
            #  relatively small price to pay.
            citation = Citation.objects.get(pk=citation.id)

        data = {'citation': CitationSerializer(citation).data}
        response_data = JSONRenderer().render(data)
        return HttpResponse(response_data, content_type='application/json')
Generate a :class:`.Citation` instance and attendant relations for a
dataset/ETHPy150Open upconsulting/IsisCB/isiscb/zotero/admin.py/ImportAccessionAdmin.get_citation_for_draft