Пример #1
0
    def store_grant_info(self, rights_statement):
        """Store grant information in the database."""
        grant_info = models.RightsStatementRightsGranted()
        grant_info.rightsstatement = rights_statement
        grant_info.act = self.column_value("grant_act")
        grant_info.startdate = self.column_value("grant_start_date")

        end_date = self.column_value("grant_end_date")
        if end_date and end_date.lower() == "open":
            grant_info.enddateopen = True
        elif end_date:
            grant_info.enddate = end_date

        grant_info.save()

        # Optionally store restriction
        if self.column_value("grant_restriction"):
            restriction = models.RightsStatementRightsGrantedRestriction()
            restriction.rightsgranted = grant_info
            restriction.restriction = self.column_value("grant_restriction")
            restriction.save()

        # Optionally store note
        if self.column_value("grant_note"):
            note = models.RightsStatementRightsGrantedNote()
            note.rightsgranted = grant_info
            note.rightsgrantednote = self.column_value("grant_note")
            note.save()
Пример #2
0
def rights_grants_edit(request, uuid, id, section="ingest"):
    jobs = models.Job.objects.filter(sipuuid=uuid)
    name = jobs.get_directory_name()

    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", "") is not None
                and request.POST.get("next_button", "") != ""):
            return redirect("rights_%s:index" % section, uuid)
        else:
            url = reverse("rights_%s:grants_edit" % section,
                          args=[uuid, viewRights.pk])
            return redirect(url)
    else:
        return render(request, "rights/rights_grants_edit.html", locals())
Пример #3
0
def rights_grants_edit(request, uuid, id, section='ingest'):
    jobs = models.Job.objects.filter(sipuuid=uuid, subjobof='')
    name = utils.get_directory_name(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 HttpResponseRedirect(reverse('components.rights.views.%s_rights_list' % section, args=[uuid]))
        else:
            url = reverse('components.rights.views.%s_rights_grants_edit' % section, args=[uuid, viewRights.pk])
            try:
                new_content_type_created
                url = url + '?created=' + new_content_type_created
            except:
                pass
            return HttpResponseRedirect(url)
    else:
        return render(request, 'rights/rights_grants_edit.html', locals())