Example #1
0
def _createAdvancedId(d, request, P):
    """ Like _createSimpleId, but also checks for elements on advanced create page:
      _status and _export variables; Adds datacite_xml if present. If no remainder
      is supplied, simply mints an ID                                         """
    # ToDo: Clean this up
    if d['current_profile'].name == 'datacite' and 'generated_xml' in d:
        to_write = {
            "_profile": 'datacite',
            '_target': P['target'],
            "_status": ("public" if P["publish"] == "True" else "reserved"),
            "_export": ("yes" if P["export"] == "yes" else "no"),
            "datacite": d['generated_xml'],
        }
    else:
        to_write = uic.assembleUpdateDictionary(
            request,
            d['current_profile'],
            {
                '_target': P['target'],
                "_status":
                ("public" if P["publish"] == "True" else "reserved"),
                "_export": ("yes" if P["export"] == "yes" else "no"),
            },
        )
    if P['remainder'] == '' or P[
            'remainder'] == form_objects.REMAINDER_BOX_DEFAULT:
        s = ezid.mintIdentifier(
            P['shoulder'], userauth.getUser(request, returnAnonymous=True),
            to_write)
    else:
        s = ezid.createIdentifier(
            P['shoulder'] + P['remainder'],
            userauth.getUser(request, returnAnonymous=True),
            to_write,
        )
    if s.startswith("success:"):
        new_id = s.split()[1]
        django.contrib.messages.success(request, _("Identifier Created."))
        d['id_gen_result'] = 'created_identifier: ' + new_id
    else:
        if "-" in s:
            err_msg = re.search(r'^error: .+?- (.+)$', s).group(1)
        else:
            err_msg = re.search(r'^error: (.+)$', s).group(1)
        django.contrib.messages.error(
            request,
            _("There was an error creating your identifier") + ": " + err_msg)
        d['accordions_open'] = 'open'
        d['id_gen_result'] = 'edit_page'
    return d
Example #2
0
def _createSimpleId(d, request, P):
    s = ezid.mintIdentifier(
        request.POST['shoulder'],
        userauth.getUser(request, returnAnonymous=True),
        uic.assembleUpdateDictionary(request, d['current_profile'], {
            '_target': P['target'],
            '_export': 'yes'
        }))
    if s.startswith("success:"):
        new_id = s.split()[1]
        django.contrib.messages.success(request, _("Identifier Created."))
        d['id_gen_result'] = "created_identifier: " + new_id
    else:
        err = _("Identifier could not be created as submitted") + ": " + s
        django.contrib.messages.error(request, err)
        d['id_gen_result'] = 'edit_page'
    return d
Example #3
0
def _createSimpleId(d, request, P):
    s = ezid.mintIdentifier(
        request.POST["shoulder"],
        userauth.getUser(request, returnAnonymous=True),
        uic.assembleUpdateDictionary(request, d["current_profile"], {
            "_target": P["target"],
            "_export": "yes"
        }),
    )
    if s.startswith("success:"):
        new_id = s.split()[1]
        django.contrib.messages.success(request, _("Identifier Created."))
        d["id_gen_result"] = "created_identifier: " + new_id
    else:
        err = _("Identifier could not be created as submitted") + ": " + s
        django.contrib.messages.error(request, err)
        d["id_gen_result"] = "edit_page"
    return d
Example #4
0
def _updateEzid(request, d, stts, m_to_upgrade=None):
    """
  Takes data from form fields in /manage/edit and applies them to IDs metadata
  If m_to_upgrade is specified, converts record to advanced datacite 
  Returns ezid.setMetadata (successful return is the identifier string)
  Also removes tags related to old profile if converting to advanced datacite
  """
    m_dict = {
        '_target': request.POST['target'],
        '_status': stts,
        '_export': ('yes' if
                    (not 'export' in d) or d['export'] == 'yes' else 'no')
    }
    if m_to_upgrade:
        d['current_profile'] = metadata.getProfile('datacite')
        # datacite_xml ezid profile is defined by presence of 'datacite' assigned to the
        # '_profile' key and XML present in the 'datacite' key
        m_dict['datacite'] = datacite.formRecord(d['id_text'], m_to_upgrade,
                                                 True)
        m_dict['_profile'] = 'datacite'
        # Old tag cleanup
        if m_to_upgrade.get("_profile", "") == "datacite":
            m_dict['datacite.creator'] = ''
            m_dict['datacite.publisher'] = ''
            m_dict['datacite.publicationyear'] = ''
            m_dict['datacite.title'] = ''
            m_dict['datacite.type'] = ''
        if m_to_upgrade.get("_profile", "") == "dc":
            m_dict['dc.creator'] = ''
            m_dict['dc.date'] = ''
            m_dict['dc.publisher'] = ''
            m_dict['dc.title'] = ''
            m_dict['dc.type'] = ''
        if m_to_upgrade.get("_profile", "") == "erc":
            m_dict['erc.who'] = ''
            m_dict['erc.what'] = ''
            m_dict['erc.when'] = ''
    # ToDo: Using current_profile here, but isn't this confusing if executing simpleToAdvanced
    to_write = uic.assembleUpdateDictionary(request, d['current_profile'],
                                            m_dict)
    return ezid.setMetadata(d['id_text'],
                            userauth.getUser(request, returnAnonymous=True),
                            to_write)