def createOrUpdateGroupPid(request, obj, change): import ezid import log f = ezid.setMetadata if change else ezid.createIdentifier r = f( obj.pid, models.getAdminUser(), { "_ezid_role": "group", "_export": "no", "_profile": "ezid", "ezid.group.groupname": obj.groupname, "ezid.group.realm": obj.realm.name, "ezid.group.organizationName": obj.organizationName, "ezid.group.organizationAcronym": obj.organizationAcronym, "ezid.group.organizationUrl": obj.organizationUrl, "ezid.group.organizationStreetAddress": obj.organizationStreetAddress, "ezid.group.agreementOnFile": str(obj.agreementOnFile), "ezid.group.crossrefEnabled": str(obj.crossrefEnabled), "ezid.group.shoulders": " ".join(s.prefix for s in obj.shoulders.all()), "ezid.group.notes": obj.notes }) if r.startswith("success:"): django.contrib.messages.success(request, "Group PID %s." %\ ("updated" if change else "created")) else: log.otherError("admin.createOrUpdateGroupPid", Exception( "ezid.%s call failed: %s" % ("setMetadata" if change else\ "createIdentifier", r))) django.contrib.messages.error(request, "Error %s group PID." %\ ("updating" if change else "creating"))
def createOrUpdateUserPid(request, obj, change): import ezid import log f = ezid.setMetadata if change else ezid.createIdentifier r = f( obj.pid, models.getAdminUser(), { "_ezid_role": "user", "_export": "no", "_profile": "ezid", "ezid.user.username": obj.username, "ezid.user.group": "%s|%s " % (obj.group.groupname, obj.group.pid), "ezid.user.realm": obj.realm.name, "ezid.user.displayName": obj.displayName, "ezid.user.accountEmail": obj.accountEmail, "ezid.user.primaryContactName": obj.primaryContactName, "ezid.user.primaryContactEmail": obj.primaryContactEmail, "ezid.user.primaryContactPhone": obj.primaryContactPhone, "ezid.user.secondaryContactName": obj.secondaryContactName, "ezid.user.secondaryContactEmail": obj.secondaryContactEmail, "ezid.user.secondaryContactPhone": obj.secondaryContactPhone, "ezid.user.inheritGroupShoulders": str(obj.inheritGroupShoulders), "ezid.user.shoulders": " ".join(s.prefix for s in obj.shoulders.all()), "ezid.user.crossrefEnabled": str(obj.crossrefEnabled), "ezid.user.crossrefEmail": obj.crossrefEmail, "ezid.user.proxies": " ".join( "%s|%s" % (u.username, u.pid) for u in obj.proxies.all() ), "ezid.user.isGroupAdministrator": str(obj.isGroupAdministrator), "ezid.user.isRealmAdministrator": str(obj.isRealmAdministrator), "ezid.user.isSuperuser": str(obj.isSuperuser), "ezid.user.loginEnabled": str(obj.loginEnabled), "ezid.user.password": obj.password, "ezid.user.notes": obj.notes, }, ) if r.startswith("success:"): if request != None: django.contrib.messages.success( request, "User PID %s." % ("updated" if change else "created") ) else: log.otherError( "admin.createOrUpdateUserPid", Exception( "ezid.%s call failed: %s" % ("setMetadata" if change else "createIdentifier", r) ), ) if request != None: django.contrib.messages.error( request, "Error %s user PID." % ("updating" if change else "creating") )
def updateUserPids(request, users): import ezid import log errors = False for u in users: r = ezid.setMetadata( u.pid, models.getAdminUser(), { "ezid.user.shoulders": " ".join(s.prefix for s in u.shoulders.all()), "ezid.user.crossrefEnabled": str(u.crossrefEnabled), "ezid.user.crossrefEmail": u.crossrefEmail }) if not r.startswith("success:"): errors = True log.otherError("admin.updateUserPids", Exception("ezid.setMetadata call failed: " + r)) if errors: django.contrib.messages.error(request, "Error updating user PIDs.") else: django.contrib.messages.success(request, "User PIDs updated.")