Esempio n. 1
0
 def inner(request, uuid, *args, **kwargs):
     jobs = models.Job.objects.filter(sipuuid=uuid, subjobof='')
     if 0 == jobs.count:
         raise Http404
     kwargs['jobs'] = jobs
     kwargs['name'] = utils.get_directory_name_from_job(jobs[0])
     return view(request, uuid, *args, **kwargs)
Esempio n. 2
0
def ingest_metadata_event_detail(request, uuid):
    EventDetailFormset = modelformset_factory(models.Event,
                                              form=forms.EventDetailForm,
                                              extra=0)
    manual_norm_files = models.File.objects.filter(sip=uuid).filter(
        originallocation__icontains='manualNormalization/preservation')
    events = models.Event.objects.filter(
        derivation__derived_file__in=manual_norm_files).order_by(
            'file_uuid__currentlocation')
    formset = EventDetailFormset(request.POST or None, queryset=events)

    if formset.is_valid():
        formset.save()
        return redirect('components.unit.views.detail',
                        unit_type='ingest',
                        unit_uuid=uuid)

    # Add path for original and derived files to each form
    for form in formset:
        form.original_file = form.instance.file_uuid.originallocation.replace(
            "%transferDirectory%objects/", "", 1)
        form.derived_file = form.instance.file_uuid.derived_file_set.filter(
            derived_file__filegrpuse='preservation').get(
            ).derived_file.originallocation.replace(
                "%transferDirectory%objects/", "", 1)

    # Get name of SIP from directory name of most recent job
    # Making list and slicing for speed: http://stackoverflow.com/questions/5123839/fastest-way-to-get-the-first-object-from-a-queryset-in-django
    jobs = list(models.Job.objects.filter(sipuuid=uuid, subjobof='')[:1])
    name = utils.get_directory_name_from_job(jobs)
    return render(request, 'ingest/metadata_event_detail.html', locals())
Esempio n. 3
0
def rights_list(request, uuid, section):
    jobs = models.Job.objects.filter(sipuuid=uuid, subjobof='')
    name = utils.get_directory_name_from_job(jobs[0])

    # See MetadataAppliesToTypes table
    types = {'transfer': 'Transfer', 'ingest': 'SIP', 'file': 'File'}
    type_id = helpers.get_metadata_type_id_by_description(types[section])

    grants = models.RightsStatementRightsGranted.objects.filter(
        rightsstatement__metadataappliestotype=type_id,
        rightsstatement__metadataappliestoidentifier__exact=uuid
    )

    # create result list that incorporates multiple restriction records
    modifiedGrants = []
    for grant in grants:
        item = {
            'id':           grant.pk,
            'act':          grant.act,
            'basis':        grant.rightsstatement.rightsbasis,
            'restrictions': [],
            'startdate':    grant.startdate,
            'enddate':      grant.enddate,
            'rightsstatement': grant.rightsstatement
        }

        if (grant.enddateopen):
            item['enddate'] = '(open)'

        restriction_data = models.RightsStatementRightsGrantedRestriction.objects.filter(rightsgranted=grant)
        restrictions = []
        for restriction in restriction_data:
            #return HttpResponse(restriction.restriction)
            restrictions.append(restriction.restriction)
        item['restrictions'] = restrictions

        modifiedGrants.append(item)
    grants = modifiedGrants

    # When listing ingest rights we also want to show transfer rights
    # The only way I've found to get the related transfer of a SIP is looking into the File table
    if section is "ingest":
        try:
            transfer_uuid = models.File.objects.filter(sip__uuid__exact=uuid)[0].transfer.uuid
            transfer_grants = models.RightsStatementRightsGranted.objects.filter(
                rightsstatement__metadataappliestotype=types['transfer'],
                rightsstatement__metadataappliestoidentifier__exact=transfer_uuid
            )
        except:
            pass

    return render(request, 'rights/rights_list.html', locals())
Esempio n. 4
0
def microservices(request, unit_type, unit_uuid):
    """
    Display information about what microservices have run.

    :param unit_type: 'transfer' or 'ingest' for a Transfer or SIP respectively
    :param unit_uuid: UUID of the Transfer or SIP

    """
    jobs = models.Job.objects.filter(sipuuid=unit_uuid, subjobof='')
    name = utils.get_directory_name_from_job(jobs[0])
    return render(request, unit_type + '/microservices.html', {
        'jobs': jobs,
        'name': name,
        'uuid': unit_uuid,
        'unit_type': unit_type,
    })
Esempio n. 5
0
def ingest_metadata_add_files(request, sip_uuid):
    try:
        source_directories = storage_service.get_location(purpose="TS")
    except:
        messages.warning(request, 'Error retrieving source directories: is the storage server running? Please contact an administrator.')
    else:
        logging.debug("Source directories found: {}".format(source_directories))
        if not source_directories:
            msg = "No transfer source locations are available. Please contact an administrator."
            messages.warning(request, msg)
    # Get name of SIP from directory name of most recent job
    # Making list and slicing for speed: http://stackoverflow.com/questions/5123839/fastest-way-to-get-the-first-object-from-a-queryset-in-django
    jobs = list(models.Job.objects.filter(sipuuid=sip_uuid, subjobof='')[:1])
    name = utils.get_directory_name_from_job(jobs[0])

    return render(request, 'ingest/metadata_add_files.html', locals())
Esempio n. 6
0
    def encoder(obj):
        items = []
        for item in obj:
            # Check if hidden (TODO: this method is slow)
            if models.SIP.objects.is_hidden(item['sipuuid']):
                continue
            jobs = helpers.get_jobs_by_sipuuid(item['sipuuid'])
            item['directory'] = utils.get_directory_name_from_job(jobs)
            item['timestamp'] = calendar.timegm(item['timestamp'].timetuple())
            item['uuid'] = item['sipuuid']
            item['id'] = item['sipuuid']
            del item['sipuuid']
            item['jobs'] = []
            for job in jobs:
                newJob = {}
                item['jobs'].append(newJob)

                # allow user to know name of file that has failed normalization
                if job.jobtype == 'Access normalization failed - copying' or job.jobtype == 'Preservation normalization failed - copying' or job.jobtype == 'thumbnail normalization failed - copying':
                    task = models.Task.objects.get(job=job)
                    newJob['filename'] = task.filename

                newJob['uuid'] = job.jobuuid
                newJob['type'] = job.jobtype
                newJob['microservicegroup'] = job.microservicegroup
                newJob['subjobof'] = job.subjobof
                newJob['currentstep'] = job.currentstep
                newJob['timestamp'] = '%d.%s' % (calendar.timegm(
                    job.createdtime.timetuple()), str(
                        job.createdtimedec).split('.')[-1])
                try:
                    mcp_status
                except NameError:
                    pass
                else:
                    xml_unit = mcp_status.xpath(
                        'choicesAvailableForUnit[UUID="%s"]' % job.jobuuid)
                    if xml_unit:
                        xml_unit_choices = xml_unit[0].findall(
                            'choices/choice')
                        choices = {}
                        for choice in xml_unit_choices:
                            choices[choice.find("chainAvailable").
                                    text] = choice.find("description").text
                        newJob['choices'] = choices
            items.append(item)
        return items
Esempio n. 7
0
def ingest_normalization_report(request, uuid, current_page=None):
    jobs = models.Job.objects.filter(sipuuid=uuid, subjobof='')
    sipname = utils.get_directory_name_from_job(jobs)

    objects = getNormalizationReportQuery(sipUUID=uuid)
    for o in objects:
        o['location'] = archivematicaFunctions.escape(o['location'])

    results_per_page = 10

    if current_page == None:
        current_page = 1

    page = helpers.pager(objects, results_per_page, current_page)
    hit_count = len(objects)

    return render(request, 'ingest/normalization_report.html', locals())
Esempio n. 8
0
 def encoder(obj):
     items = []
     for item in obj:
         # Check if hidden (TODO: this method is slow)
         if models.Transfer.objects.is_hidden(item['sipuuid']):
             continue
         jobs = models.Job.objects.filter(sipuuid=item['sipuuid'],
                                          subjobof='').order_by(
                                              '-createdtime', 'subjobof')
         item['directory'] = os.path.basename(
             utils.get_directory_name_from_job(jobs))
         item['timestamp'] = calendar.timegm(item['timestamp'].timetuple())
         item['uuid'] = item['sipuuid']
         item['id'] = item['sipuuid']
         del item['sipuuid']
         item['jobs'] = []
         for job in jobs:
             newJob = {}
             item['jobs'].append(newJob)
             newJob['uuid'] = job.jobuuid
             newJob['type'] = job.jobtype
             newJob['link_id'] = job.microservicechainlink.pk
             newJob['microservicegroup'] = job.microservicegroup
             newJob['subjobof'] = job.subjobof
             newJob['currentstep'] = job.currentstep
             newJob['currentstep_label'] = job.get_currentstep_display()
             newJob['timestamp'] = '%d.%s' % (calendar.timegm(
                 job.createdtime.timetuple()), str(
                     job.createdtimedec).split('.')[-1])
             try:
                 mcp_status
             except NameError:
                 pass
             else:
                 xml_unit = mcp_status.xpath(
                     'choicesAvailableForUnit[UUID="%s"]' % job.jobuuid)
                 if xml_unit:
                     xml_unit_choices = xml_unit[0].findall(
                         'choices/choice')
                     choices = {}
                     for choice in xml_unit_choices:
                         choices[choice.find("chainAvailable").
                                 text] = choice.find("description").text
                     newJob['choices'] = choices
         items.append(item)
     return items
Esempio n. 9
0
def ingest_browse(request, browse_type, jobuuid):
    watched_dir = helpers.get_server_config_value('watchDirectoryPath')
    if browse_type == 'normalization':
        title = 'Review normalization'
        directory = os.path.join(watched_dir, 'approveNormalization')
    elif browse_type == 'aip':
        title = 'Review AIP'
        directory = os.path.join(watched_dir, 'storeAIP')
    elif browse_type == 'dip':
        title = 'Review DIP'
        directory = os.path.join(watched_dir, 'uploadedDIPs')
    else:
        raise Http404

    jobs = models.Job.objects.filter(jobuuid=jobuuid, subjobof='')
    name = utils.get_directory_name_from_job(jobs)

    return render(request, 'ingest/aip_browse.html', locals())
Esempio n. 10
0
def ingest_browse(request, browse_type, jobuuid):
    watched_dir = django_settings.WATCH_DIRECTORY
    if browse_type == 'normalization':
        title = _('Review normalization')
        directory = os.path.join(watched_dir, 'approveNormalization')
    elif browse_type == 'aip':
        title = _('Review AIP')
        directory = os.path.join(watched_dir, 'storeAIP')
    elif browse_type == 'dip':
        title = _('Review DIP')
        directory = os.path.join(watched_dir, 'uploadedDIPs')
    else:
        raise Http404

    jobs = models.Job.objects.filter(jobuuid=jobuuid, subjobof='')
    name = utils.get_directory_name_from_job(jobs)

    return render(request, 'ingest/aip_browse.html', locals())
Esempio n. 11
0
def detail(request, unit_type, unit_uuid):
    """
    Display detailed information about the unit.

    :param unit_type: 'transfer' or 'ingest' for a Transfer or SIP respectively
    :param unit_uuid: UUID of the Transfer or SIP
    """
    jobs = models.Job.objects.filter(sipuuid=unit_uuid, subjobof='')
    name = utils.get_directory_name_from_job(jobs)
    is_waiting = jobs.filter(currentstep='Awaiting decision').count() > 0
    context = {
        'name': name,
        'is_waiting': is_waiting,
        'uuid': unit_uuid,
        'unit_type': unit_type,
    }
    if unit_type == 'transfer':
        set_uuid = models.Transfer.objects.get(uuid=unit_uuid).transfermetadatasetrow_id
        context['set_uuid'] = set_uuid
    return render(request, unit_type + '/detail.html', context)
Esempio n. 12
0
def transfer_metadata_edit(request, uuid, id=None):
    if id:
        dc = models.DublinCore.objects.get(pk=id)
    else:
        try:
            dc = models.DublinCore.objects.get(
                metadataappliestotype=transfer_metadata_type_id(),
                metadataappliestoidentifier__exact=uuid)
            return redirect('components.transfer.views.transfer_metadata_edit',
                            uuid, dc.id)
        except models.DublinCore.DoesNotExist:
            dc = models.DublinCore(
                metadataappliestotype=transfer_metadata_type_id(),
                metadataappliestoidentifier=uuid)

    fields = [
        'title', 'creator', 'subject', 'description', 'publisher',
        'contributor', 'date', 'type', 'format', 'identifier', 'source',
        'relation', 'language', 'coverage', 'rights'
    ]

    if request.method == 'POST':
        form = DublinCoreMetadataForm(request.POST)
        if form.is_valid():
            for item in fields:
                if item not in form.cleaned_data:
                    continue
                setattr(dc, item, form.cleaned_data[item])
            dc.save()
            return redirect('components.transfer.views.transfer_metadata_list',
                            uuid)
    else:
        initial = {}
        for item in fields:
            initial[item] = getattr(dc, item)
        form = DublinCoreMetadataForm(initial=initial)
        jobs = models.Job.objects.filter(sipuuid=uuid, subjobof='')
        name = utils.get_directory_name_from_job(jobs)

    return render(request, 'transfer/metadata_edit.html', locals())
Esempio n. 13
0
def rights_list(request, uuid, section):
    jobs = models.Job.objects.filter(sipuuid=uuid, subjobof='')
    name = utils.get_directory_name_from_job(jobs)

    # See MetadataAppliesToTypes table
    types = {'transfer': 'Transfer', 'ingest': 'SIP', 'file': 'File'}
    type_id = helpers.get_metadata_type_id_by_description(types[section])

    grants = models.RightsStatementRightsGranted.objects.filter(
        rightsstatement__metadataappliestotype=type_id,
        rightsstatement__metadataappliestoidentifier__exact=uuid)

    # When listing ingest rights we also want to show transfer rights
    # The only way I've found to get the related transfer of a SIP is looking into the File table
    transfer_grants = None
    if section is "ingest":
        try:
            transfer_uuids = models.File.objects.filter(
                sip_id=uuid,
                removedtime__isnull=True,
                transfer_id__isnull=False).values_list('transfer',
                                                       flat=True).distinct()
            transfer_grants = models.RightsStatementRightsGranted.objects.filter(
                rightsstatement__metadataappliestotype__description=types[
                    'transfer'],
                rightsstatement__metadataappliestoidentifier__in=transfer_uuids
            )
        except Exception:
            LOGGER.exception('Error fetching Transfer rights')

    return render(
        request, 'rights/rights_list.html', {
            'grants': grants,
            'jobs': jobs,
            'name': name,
            'section': section,
            'transfer_grants': transfer_grants,
            'uuid': uuid,
        })
Esempio n. 14
0
def ingest_metadata_edit(request, uuid, id=None):
    if id:
        # If we have the ID of the DC object, use that - Edit
        dc = models.DublinCore.objects.get(pk=id)
    else:
        # Otherwise look for a SIP with the provided UUID, creating a new one
        # if needed.  Not using get_or_create because that save the empty
        # object, even if the form is not submitted.
        sip_type_id = ingest_sip_metadata_type_id()
        try:
            dc = models.DublinCore.objects.get(
                metadataappliestotype=sip_type_id,
                metadataappliestoidentifier=uuid)
            id = dc.id
        except models.DublinCore.DoesNotExist:
            dc = models.DublinCore(
                metadataappliestotype=sip_type_id,
                metadataappliestoidentifier=uuid)

    # If the SIP is an AIC, use the AIC metadata form
    if 'AIC' in models.SIP.objects.get(uuid=uuid).sip_type:
        form = ingest_forms.AICDublinCoreMetadataForm(request.POST or None,
            instance=dc)
        dc_type = "Archival Information Collection"
    else:
        form = ingest_forms.DublinCoreMetadataForm(request.POST or None,
            instance=dc)
        dc_type = "Archival Information Package"

    if form.is_valid():
        dc = form.save()
        dc.type = dc_type
        dc.save()
        return redirect('components.ingest.views.ingest_metadata_list', uuid)
    jobs = models.Job.objects.filter(sipuuid=uuid, subjobof='')
    name = utils.get_directory_name_from_job(jobs[0])

    return render(request, 'ingest/metadata_edit.html', locals())
Esempio n. 15
0
 def get_title(self):
     try:
         jobs = main.models.Job.objects.filter(sipuuid=self.sipuuid, subjobof='')
         return utils.get_directory_name_from_job(jobs[0])
     except:
         return 'N/A'
Esempio n. 16
0
def microservices(request, uuid):
    jobs = models.Job.objects.filter(sipuuid=uuid)
    name = utils.get_directory_name_from_job(jobs[0])
    return render(request, 'transfer/microservices.html', locals())
Esempio n. 17
0
def ingest_detail(request, uuid):
    jobs = models.Job.objects.filter(sipuuid=uuid, subjobof='')
    is_waiting = jobs.filter(currentstep='Awaiting decision').count() > 0
    name = utils.get_directory_name_from_job(jobs[0])
    return render(request, 'ingest/detail.html', locals())
Esempio n. 18
0
def ingest_microservices(request, uuid):
    jobs = models.Job.objects.filter(sipuuid=uuid, subjobof='')
    name = utils.get_directory_name_from_job(jobs[0])
    return render(request, 'ingest/microservices.html', locals())
Esempio n. 19
0
def rights_edit(request, uuid, id=None, section='ingest'):
    jobs = models.Job.objects.filter(sipuuid=uuid, subjobof='')
    name = utils.get_directory_name_from_job(jobs[0])

    # flag indicating what kind of new content, if any, has been created
    new_content_type_created = None

    max_notes = 1

    if id:
        viewRights = models.RightsStatement.objects.get(pk=id)
        agentId = None
        if request.method == 'POST':
            postData = request.POST.copy()
            """
            agentId = rights_parse_agent_id(postData.get('rightsholder'))
            if agentId == 0 and postData.get('rightsholder') != '0' and postData.get('rightsholder') != '':
                agent = models.RightsStatementLinkingAgentIdentifier()
                agent.rightsstatement = viewRights
                agent.linkingagentidentifiervalue = postData.get('rightsholder')
                agent.save()
                agentId = agent.id
            postData.__setitem__('rightsholder', agentId)
            """
            form = forms.RightsForm(postData, instance=viewRights)
            form.cleaned_data = postData
            viewRights = form.save()
        else:
            form = forms.RightsForm(instance=viewRights)
            form.cleaned_data = viewRights
            form.save()

        # determine how many empty forms should be shown for children
        extra_copyright_forms = max_notes - models.RightsStatementCopyright.objects.filter(rightsstatement=viewRights).count()
        extra_statute_forms = max_notes - models.RightsStatementStatuteInformation.objects.filter(rightsstatement=viewRights).count()
        extra_license_forms = max_notes - models.RightsStatementLicense.objects.filter(rightsstatement=viewRights).count()
        extra_other_forms = max_notes - models.RightsStatementOtherRightsInformation.objects.filter(rightsstatement=viewRights).count()
    else:
        if request.method == 'POST':
            postData = request.POST.copy()
            agentId = rights_parse_agent_id(postData.get('rightsholder'))
            postData.__setitem__('rightsholder', agentId)
            form = forms.RightsForm(postData)
        else:
            form = forms.RightsForm()
            viewRights = models.RightsStatement()

        extra_copyright_forms = max_notes
        extra_statute_forms   = max_notes
        extra_license_forms   = max_notes
        extra_license_notes   = max_notes
        extra_other_forms     = max_notes

    # create inline formsets for child elements
    CopyrightFormSet = inlineformset_factory(
        models.RightsStatement,
        models.RightsStatementCopyright,
        extra=extra_copyright_forms,
        can_delete=False,
        form=forms.RightsCopyrightForm
    )

    StatuteFormSet = inlineformset_factory(
        models.RightsStatement,
        models.RightsStatementStatuteInformation,
        extra=extra_statute_forms,
        can_delete=False,
        form=forms.RightsStatuteForm
    )

    LicenseFormSet = inlineformset_factory(
        models.RightsStatement,
        models.RightsStatementLicense,
        extra=extra_license_forms,
        can_delete=False,
        form=forms.RightsLicenseForm
    )

    OtherFormSet = inlineformset_factory(
        models.RightsStatement,
        models.RightsStatementOtherRightsInformation,
        extra=extra_other_forms,
        can_delete=False,
        form=forms.RightsOtherRightsForm
    )

    # handle form creation/saving
    if request.method == 'POST':
        if id:
            createdRights = viewRights
        else:
            sectionTypeID = {'transfer': 'Transfer', 'ingest': 'SIP'}
            type_id = helpers.get_metadata_type_id_by_description(sectionTypeID[section])
            newRights = models.RightsStatement(metadataappliestotype=type_id, metadataappliestoidentifier=uuid)
            form = forms.RightsForm(request.POST, instance=newRights)
            createdRights = form.save()

        copyrightFormset = CopyrightFormSet(request.POST, instance=createdRights)
        createdCopyrightSet = copyrightFormset.save()

        # establish whether or not there is a copyright information instance to use as a parent
        if len(createdCopyrightSet) == 1:
            createdCopyright = createdCopyrightSet[0]
        else:
            createdCopyright = False

        # handle creation of new copyright notes, creating parent if necessary
        if request.POST.get('copyright_note', '') != '':
            # make new copyright record if it doesn't exist
            if not createdCopyright:
                try:
                    createdCopyright = models.RightsStatementCopyright.objects.get(rightsstatement=createdRights)
                except:
                    createdCopyright = models.RightsStatementCopyright(rightsstatement=createdRights)
                    createdCopyright.save()

            copyrightNote = models.RightsStatementCopyrightNote(rightscopyright=createdCopyright)
            copyrightNote.copyrightnote = request.POST.get('copyright_note', '')
            copyrightNote.save()

            new_content_type_created = 'copyright'

        # handle creation of new documentation identifiers
        if request.POST.get('copyright_documentation_identifier_type', '') != '' or request.POST.get('copyright_documentation_identifier_value', '') != '' or request.POST.get('copyright_documentation_identifier_role', ''):
            # make new copyright record if it doesn't exist
            if not createdCopyright:
                try:
                    createdCopyright = models.RightsStatementCopyright.objects.get(rightsstatement=createdRights)
                except:
                    createdCopyright = models.RightsStatementCopyright(rightsstatement=createdRights)
                    createdCopyright.save()

            copyrightDocIdentifier = models.RightsStatementCopyrightDocumentationIdentifier(rightscopyright=createdCopyright)
            copyrightDocIdentifier.copyrightdocumentationidentifiertype  = request.POST.get('copyright_documentation_identifier_type', '')
            copyrightDocIdentifier.copyrightdocumentationidentifiervalue = request.POST.get('copyright_documentation_identifier_value', '')
            copyrightDocIdentifier.copyrightdocumentationidentifierrole  = request.POST.get('copyright_documentation_identifier_role', '')
            copyrightDocIdentifier.save()

            new_content_type_created = 'copyright'

        licenseFormset = LicenseFormSet(request.POST, instance=createdRights)
        createdLicenseSet = licenseFormset.save()

        # establish whether or not there is a license instance to use as a parent
        if len(createdLicenseSet) == 1:
            createdLicense = createdLicenseSet[0]
        else:
            createdLicense = False

        # handle creation of new copyright notes, creating parent if necessary
        if request.POST.get('license_note', '') != '':
            # make new copyright record if it doesn't exist
            if not createdLicense:
                try:
                    createdLicense = models.RightsStatementLicense.objects.get(rightsstatement=createdRights)
                except:
                    createdLicense = models.RightsStatementLicense(rightsstatement=createdRights)
                    createdLicense.save()

            licenseNote = models.RightsStatementLicenseNote(rightsstatementlicense=createdLicense)
            licenseNote.licensenote = request.POST.get('license_note', '')
            licenseNote.save()

            new_content_type_created = 'license'

        # handle creation of new documentation identifiers
        if request.POST.get('license_documentation_identifier_type', '') != '' or request.POST.get('license_documentation_identifier_value', '') != '' or request.POST.get('license_documentation_identifier_role', ''):
            # make new license record if it doesn't exist
            if not createdLicense:
                try:
                    createdLicense = models.RightsStatementLicense.objects.get(rightsstatement=createdRights)
                except:
                    createdLicense = models.RightsStatementLicense(rightsstatement=createdRights)
                    createdLicense.save()

            licenseDocIdentifier = models.RightsStatementLicenseDocumentationIdentifier(rightsstatementlicense=createdLicense)
            licenseDocIdentifier.licensedocumentationidentifiertype  = request.POST.get('license_documentation_identifier_type', '')
            licenseDocIdentifier.licensedocumentationidentifiervalue = request.POST.get('license_documentation_identifier_value', '')
            licenseDocIdentifier.licensedocumentationidentifierrole  = request.POST.get('license_documentation_identifier_role', '')
            licenseDocIdentifier.save()

            new_content_type_created = 'license'

        statuteFormset = StatuteFormSet(request.POST, instance=createdRights)
        createdStatuteSet = statuteFormset.save()
        if request.POST.get('statute_previous_pk', '') == 'None' and len(createdStatuteSet) == 1:
            new_content_type_created = 'statute'

        noteCreated = False
        for form in statuteFormset.forms:
            statuteCreated = False

            # handle documentation identifier creation for a parent that's a blank statute
            if (request.POST.get('statute_documentation_identifier_type_None', '') != '' or request.POST.get('statute_documentation_identifier_value_None', '') != '' or request.POST.get('statute_documentation_identifier_role_None', '') != ''):
                if form.instance.pk:
                    statuteCreated = form.instance
                else:
                    statuteCreated = models.RightsStatementStatuteInformation(rightsstatement=createdRights)
                    statuteCreated.save()

                statuteDocIdentifier = models.RightsStatementStatuteDocumentationIdentifier(rightsstatementstatute=statuteCreated)
                statuteDocIdentifier.statutedocumentationidentifiertype = request.POST.get('statute_documentation_identifier_type_None', '')
                statuteDocIdentifier.statutedocumentationidentifiervalue = request.POST.get('statute_documentation_identifier_value_None', '')
                statuteDocIdentifier.statutedocumentationidentifierrole = request.POST.get('statute_documentation_identifier_role_None', '')
                statuteDocIdentifier.save()
                new_content_type_created = 'statute'
            else:
                # handle documentation identifier creation for a parent statute that already exists
                if request.POST.get('statute_documentation_identifier_type_' + str(form.instance.pk), '') != '' or request.POST.get('statute_documentation_identifier_value_' + str(form.instance.pk), '') or request.POST.get('statute_documentation_identifier_role_' + str(form.instance.pk), ''):
                    statuteDocIdentifier = models.RightsStatementStatuteDocumentationIdentifier(rightsstatementstatute=form.instance)
                    statuteDocIdentifier.statutedocumentationidentifiertype = request.POST.get('statute_documentation_identifier_type_' +  str(form.instance.pk), '')
                    statuteDocIdentifier.statutedocumentationidentifiervalue = request.POST.get('statute_documentation_identifier_value_' +  str(form.instance.pk), '')
                    statuteDocIdentifier.statutedocumentationidentifierrole = request.POST.get('statute_documentation_identifier_role_' +  str(form.instance.pk), '')
                    statuteDocIdentifier.save()
                    new_content_type_created = 'statute'

            # handle note creation for a parent that's a blank grant
            if request.POST.get('new_statute_note_None', '') != '' and not form.instance.pk:
                if not statuteCreated:
                    statuteCreated = models.RightsStatementStatuteInformation(rightsstatement=createdRights)
                    statuteCreated.save()
                noteCreated = models.RightsStatementStatuteInformationNote(rightsstatementstatute=statuteCreated)
                noteCreated.statutenote = request.POST.get('new_statute_note_None', '')
                noteCreated.save()
                new_content_type_created = 'statue'
            else:
                # handle note creation for a parent grant that already exists 
                if request.POST.get('new_statute_note_' + str(form.instance.pk), '') != '':
                    noteCreated = models.RightsStatementStatuteInformationNote(rightsstatementstatute=form.instance)
                    noteCreated.statutenote = request.POST.get('new_statute_note_' + str(form.instance.pk), '')
                    noteCreated.save()
                    new_content_type_created = 'statute'

        # handle note creation for a parent that's just been created
        if request.POST.get('new_statute_note_None', '') != '' and not noteCreated:
            noteCreated = models.RightsStatementStatuteInformationNote(rightsstatementstatute=form.instance)
            noteCreated.statutenote = request.POST.get('new_statute_note_None', '')
            noteCreated.save()

        # display (possibly revised) formset
        statuteFormset = StatuteFormSet(instance=createdRights)

        otherFormset = OtherFormSet(request.POST, instance=createdRights)
        createdOtherSet = otherFormset.save()

        # establish whether or not there is an "other" instance to use as a parent
        if len(createdOtherSet) == 1:
            createdOther = createdOtherSet[0]
        else:
            createdOther = False

        # handle creation of new "other" notes, creating parent if necessary
        if request.POST.get('otherrights_note', '') != '':
            # make new "other" record if it doesn't exist
            if not createdOther:
                try:
                    createdOther = models.RightsStatementOtherRightsInformation.objects.get(rightsstatement=createdRights)
                except:
                    createdOther = models.RightsStatementOtherRightsInformation(rightsstatement=createdRights)
                    createdOther.save()

            otherNote = models.RightsStatementOtherRightsInformationNote(rightsstatementotherrights=createdOther)
            otherNote.otherrightsnote = request.POST.get('otherrights_note', '')
            otherNote.save()

            new_content_type_created = 'other'

        # handle creation of new documentation identifiers
        if request.POST.get('other_documentation_identifier_type', '') != '' or request.POST.get('other_documentation_identifier_value', '') != '' or request.POST.get('other_documentation_identifier_role', ''):
            # make new other record if it doesn't exist
            if not createdOther:
                try:
                    createdOther = models.RightsStatementOtherRightsInformation.objects.get(rightsstatement=createdRights)
                except:
                    createdOther = models.RightsStatementOtherRightsInformation(rightsstatement=createdRights)
                    createdOther.save()

            otherDocIdentifier = models.RightsStatementOtherRightsDocumentationIdentifier(rightsstatementotherrights=createdOther)
            otherDocIdentifier.otherrightsdocumentationidentifiertype  = request.POST.get('other_documentation_identifier_type', '')
            otherDocIdentifier.otherrightsdocumentationidentifiervalue = request.POST.get('other_documentation_identifier_value', '')
            otherDocIdentifier.otherrightsdocumentationidentifierrole  = request.POST.get('other_documentation_identifier_role', '')
            otherDocIdentifier.save()

            new_content_type_created = 'other'

        if request.POST.get('next_button', '') != None and request.POST.get('next_button', '') != '':
            return redirect('components.rights.views.%s_rights_grants_edit' % section, uuid, createdRights.pk)
        else:
            url = reverse('components.rights.views.%s_rights_edit' % section, args=[uuid, createdRights.pk])
            try:
                url = url + '?created=' + new_content_type_created
            except:
                pass
            return redirect(url)
    else:
        copyrightFormset = CopyrightFormSet(instance=viewRights)
        statuteFormset   = StatuteFormSet(instance=viewRights)
        licenseFormset   = LicenseFormSet(instance=viewRights)
        otherFormset     = OtherFormSet(instance=viewRights)

    # show what content's been created after a redirect
    if request.GET.get('created', '') != '':
        new_content_type_created = request.GET.get('created', '')

    return render(request, 'rights/rights_edit.html', locals())
Esempio n. 20
0
def rights_grants_edit(request, uuid, id, section='ingest'):
    jobs = models.Job.objects.filter(sipuuid=uuid, subjobof='')
    name = utils.get_directory_name_from_job(jobs[0])

    viewRights = models.RightsStatement.objects.get(pk=id)

    # determine how many empty forms should be shown for children
    extra_grant_forms = 1

    # create inline formsets for child elements
    GrantFormSet = inlineformset_factory(
      models.RightsStatement,
      models.RightsStatementRightsGranted,
      extra=extra_grant_forms,
      can_delete=False,
      form=forms.RightsGrantedForm
    )

    # handle form creation/saving
    if request.method == 'POST':
        grantFormset = GrantFormSet(request.POST, instance=viewRights)
        grantFormset.save()
        restrictionCreated = False
        noteCreated = False
        for form in grantFormset.forms:
            grantCreated = False

            # handle restriction creation for a parent that's a blank grant
            if request.POST.get('new_rights_restriction_None', '') != '' and not form.instance.pk:
                grantCreated = models.RightsStatementRightsGranted(rightsstatement=viewRights)
                grantCreated.save()
                restrictionCreated = models.RightsStatementRightsGrantedRestriction(rightsgranted=grantCreated)
                restrictionCreated.restriction = request.POST.get('new_rights_restriction_None', '')
                restrictionCreated.save()
            else:
                # handle restriction creation for a parent grant that already exists
                if request.POST.get('new_rights_restriction_' + str(form.instance.pk), '') != '':
                    restrictionCreated = models.RightsStatementRightsGrantedRestriction(rightsgranted=form.instance)
                    restrictionCreated.restriction = request.POST.get('new_rights_restriction_' + str(form.instance.pk), '')
                    restrictionCreated.save()

            # handle note creation for a parent that's a blank grant
            if request.POST.get('new_rights_note_None', '') != '' and not form.instance.pk:
                if not grantCreated:
                    grantCreated = models.RightsStatementRightsGranted(rightsstatement=viewRights)
                    grantCreated.save()
                noteCreated = models.RightsStatementRightsGrantedNote(rightsgranted=grantCreated)
                noteCreated.rightsgrantednote = request.POST.get('new_rights_note_None', '')
                noteCreated.save()
            else:
                # handle note creation for a parent grant that already exists 
                if request.POST.get('new_rights_note_' + str(form.instance.pk), '') != '':
                    noteCreated = models.RightsStatementRightsGrantedNote(rightsgranted=form.instance)
                    noteCreated.rightsgrantednote = request.POST.get('new_rights_note_' + str(form.instance.pk), '')
                    noteCreated.save()

    # handle restriction creation for a parent that's just been created
    if request.POST.get('new_rights_restriction_None', '') != '' and not restrictionCreated:
        restrictionCreated = models.RightsStatementRightsGrantedRestriction(rightsgranted=form.instance)
        restrictionCreated.restriction = request.POST.get('new_rights_restriction_None', '')
        restrictionCreated.save()

    # handle note creation for a parent that's just been created
    if request.POST.get('new_rights_note_None', '') != '' and not noteCreated:
        noteCreated = models.RightsStatementRightsGrantedNote(rightsgranted=form.instance)
        noteCreated.rightsgrantednote = request.POST.get('new_rights_note_None', '')
        noteCreated.save()

    # display (possibly revised) formset
    grantFormset = GrantFormSet(instance=viewRights)

    if request.method == 'POST':
        if request.POST.get('next_button', '') != None and request.POST.get('next_button', '') != '':
            return redirect('components.rights.views.%s_rights_list' % section, uuid)
        else:
            url = reverse('components.rights.views.%s_rights_grants_edit' % section, args=[uuid, viewRights.pk])
            return redirect(url)
    else:
        return render(request, 'rights/rights_grants_edit.html', locals())
Esempio n. 21
0
def detail(request, uuid):
    jobs = models.Job.objects.filter(sipuuid=uuid)
    name = utils.get_directory_name_from_job(jobs[0])
    is_waiting = jobs.filter(currentstep='Awaiting decision').count() > 0
    set_uuid = models.Transfer.objects.get(uuid=uuid).transfermetadatasetrow_id
    return render(request, 'transfer/detail.html', locals())
Esempio n. 22
0
def ingest_status(request, uuid=None):
    """Returns the status of the SIPs in ingest as a JSON object with an
    ``objects`` attribute that is an array of objects, each of which represents
    a single SIP. Each SIP object has a ``jobs`` attribute whose value is an
    array of objects, each of which represents a Job of the SIP.
    """
    sql = """
        SELECT SIPUUID,
                MAX(UNIX_TIMESTAMP(createdTime) + createdTimeDec) AS timestamp
            FROM Jobs
            WHERE unitType='unitSIP' AND NOT SIPUUID LIKE '%%None%%'
            GROUP BY SIPUUID;"""
    with connection.cursor() as cursor:
        cursor.execute(sql)
        sipuuids_and_timestamps = cursor.fetchall()
    mcp_available = False
    try:
        client = MCPClient()
        mcp_status = etree.XML(client.list())
        mcp_available = True
    except Exception:
        pass
    objects = []
    for sipuuid, timestamp in sipuuids_and_timestamps:
        timestamp = float(timestamp)
        item = {'sipuuid': sipuuid, 'timestamp': timestamp}
        # Check if hidden (TODO: this method is slow)
        if models.SIP.objects.is_hidden(sipuuid):
            continue
        jobs = models.Job.objects\
            .filter(sipuuid=item['sipuuid'], subjobof='')\
            .order_by('-createdtime', 'subjobof')
        item['directory'] = utils.get_directory_name_from_job(jobs)
        item['uuid'] = item['sipuuid']
        item['id'] = item['sipuuid']
        del item['sipuuid']
        item['jobs'] = []
        for job in jobs:
            newJob = {}
            item['jobs'].append(newJob)
            newJob['uuid'] = job.jobuuid
            newJob['type'] = job.jobtype
            newJob['microservicegroup'] = job.microservicegroup
            newJob['subjobof'] = job.subjobof
            newJob['currentstep'] = job.currentstep
            newJob['currentstep_label'] = job.get_currentstep_display()
            newJob['timestamp'] = '%d.%s' % (calendar.timegm(
                job.createdtime.timetuple()), str(
                    job.createdtimedec).split('.')[-1])
            try:
                mcp_status
            except NameError:
                pass
            else:
                xml_unit = mcp_status.xpath(
                    'choicesAvailableForUnit[UUID="%s"]' % job.jobuuid)
                if xml_unit:
                    xml_unit_choices = xml_unit[0].findall('choices/choice')
                    choices = {}
                    for choice in xml_unit_choices:
                        choices[choice.find("chainAvailable").
                                text] = choice.find("description").text
                    newJob['choices'] = choices
        objects.append(item)
    response = {}
    response['objects'] = objects
    response['mcp'] = mcp_available
    return HttpResponse(json.dumps(response), content_type='application/json')