def create_authority(self, request, draftauthority_id):
        """
        A staff user can create a new :class:`isisdata.Authority` record using
        data from a :class:`zotero.DraftAuthority` instance.
        """
        context = dict(self.admin_site.each_context(request))
        context.update({'title': 'Create new authority record'})
        draftauthority = DraftAuthority.objects.get(pk=draftauthority_id)
        context.update({'draftauthority': draftauthority})

        AttributeInlineFormSet = formset_factory(AttributeForm)
        LinkedDataInlineFormSet = formset_factory(LinkedDataForm)

        if request.method == 'GET':
            form = AuthorityForm(initial={
                'name': draftauthority.name,
                'type_controlled': draftauthority.type_controlled,
                'record_history': u'Created from Zotero accession {0}, performed at {1} by {2}. Subsequently validated and curated by {3}.'.format(draftauthority.part_of.id, draftauthority.part_of.imported_on, draftauthority.part_of.imported_by, request.user.username),
                })
            attributeFormset = AttributeInlineFormSet()
            linkeddataFormset = LinkedDataInlineFormSet()


        elif request.method == 'POST':
            form = AuthorityForm(request.POST)
            attributeFormset = AttributeInlineFormSet(request.POST)
            linkeddataFormset = LinkedDataInlineFormSet(request.POST)

            if form.is_valid() and attributeFormset.is_valid() and linkeddataFormset.is_valid():
                # Create the Authority entry.
                instance = form.save()

                # Create new Attributes.
                for attributeForm in attributeFormset:
                    try:    # ISISCB-396; some invalid forms are getting past.
                        attributeType = attributeForm.cleaned_data['type_controlled']
                    except __HOLE__:
                        continue

                    valueModel = attributeType.value_content_type.model_class()
                    value = attributeForm.cleaned_data['value']

                    attribute_instance = Attribute(
                        source=instance,
                        type_controlled=attributeType,
                    )
                    attribute_instance.save()
                    value_instance = valueModel(
                        attribute=attribute_instance,
                        value=value,
                    )
                    value_instance.save()

                # Create new LinkedData entries.
                for linkeddataForm in linkeddataFormset:
                    linkeddataType = linkeddataForm.cleaned_data['type_controlled']
                    urn = linkeddataForm.cleaned_data['universal_resource_name']
                    linkeddata_instance = LinkedData(
                        subject=instance,
                        universal_resource_name=urn,
                        type_controlled=linkeddataType,
                    )
                    linkeddata_instance.save()

                # Add a new InstanceResolutionEvent.
                irEvent = InstanceResolutionEvent(
                    for_instance=draftauthority,
                    to_instance=instance
                )
                irEvent.save()

                # Update the DraftAuthority.
                draftauthority.processed = True
                draftauthority.save()

                # If successful, take the user to the Authority change view.
                return HttpResponseRedirect(reverse("admin:isisdata_authority_change", args=[instance.id]))

        context.update({
            'form': form,
            'attribute_formset': attributeFormset,
            'linkeddata_formset': linkeddataFormset,
            })
        return TemplateResponse(request, "admin/authority_create.html", context)
dataset/ETHPy150Open upconsulting/IsisCB/isiscb/zotero/admin.py/DraftAuthorityAdmin.create_authority