def canonical_url(self): return url_for( 'invenio_records_rest.draft-common-community_item', pid_value=CommunityPIDValue( self['control_number'], current_oarepo_communities.get_primary_community_field(self)), _external=True)
def canonical_url(self): return url_for( f'invenio_records_rest.draft-datasets_item', pid_value=CommunityPIDValue( self['id'], current_oarepo_communities.get_primary_community_field(self)), _external=True)
def to_python(self, value): """Resolve PID value.""" args = value.split('/') community, pid_value = args[0], args[-1] lazy_pid = super().to_python(pid_value) pid, record = lazy_pid.data if community != current_oarepo_communities.get_primary_community_field(record) \ and community not in (current_oarepo_communities.get_communities_field(record) or []): raise PIDDoesNotExistRESTError(pid_error=PIDDoesNotExistError( pid_type=pid.pid_type, pid_value=pid.pid_value)) pid.pid_value = CommunityPIDValue( pid.pid_value, current_oarepo_communities.get_primary_community_field(record)) return lazy_pid
def create(cls, data=dict, id_=None, **kwargs): """ Creates a new record instance and store it in the database. For parameters see :py:class:invenio_records.api.Record """ if not current_oarepo_communities.get_primary_community_field(data): raise AttributeError('Primary Community is missing from record') ret = super().create(data, id_, **kwargs) return ret
def canonical_url(self): if not self.get('oarepo:draft'): endpoint = 'invenio_records_rest.nresults-community_item' else: endpoint = 'invenio_records_rest.draft-nresults-community_item' return url_for(endpoint, pid_value=CommunityPIDValue( self['control_number'], current_oarepo_communities.get_primary_community_field(self)), _external=True)
def community_json_loader(): data = request.get_json(force=True) rcomid = community_id_from_request() dcomid = current_oarepo_communities.get_primary_community_field(data) if dcomid: if rcomid != dcomid: raise BadRequest('Primary Community mismatch') else: current_oarepo_communities.set_primary_community_field(data, rcomid) return data
def community_record_links_factory(pid, record=None, original_links_factory=None, **kwargs): """Ensures that primary community is set in self link.""" if not isinstance(pid.pid_value, CommunityPIDValue): if record: primary_community = current_oarepo_communities.get_primary_community_field(record) elif 'record_hit' in kwargs: primary_community = current_oarepo_communities.get_primary_community_field(kwargs['record_hit']['_source']) else: raise AttributeError('Record or record hit is missing') if isinstance(pid, FetchedPID): pid = FetchedPID(pid.provider, pid.pid_type, CommunityPIDValue(pid.pid_value, primary_community)) elif isinstance(pid, PersistentIdentifier): pid.pid_value = CommunityPIDValue(pid.pid_value, primary_community) else: raise NotImplementedError links = record_fsm_links_factory( pid, record, original_links_factory=original_links_factory, **kwargs) return links
def inner(record, *args, **kwargs): if record is None: raise RuntimeError('Record is missing.') arg = None if isinstance(record, Record): arg = record.primary_community elif isinstance(record, dict): arg = current_oarepo_communities.get_primary_community_field(record) else: raise RuntimeError('Unknown or missing object') return require_all( require_action_allowed(action), Permission(ParameterizedActionNeed(action, arg)))
def nr_id_generic_fetcher(record_uuid, data): """Fetch a record's identifiers. :param record_uuid: The record UUID. :param data: The record metadata. :returns: A :data:`invenio_pidstore.fetchers.FetchedPID` instance. """ id_field = "control_number" return FetchedPID( provider=NRIdGenericProvider, pid_type=NRIdGenericProvider.pid_type, pid_value=CommunityPIDValue( str(data[id_field]), current_oarepo_communities.get_primary_community_field(data)))
def _check_community(self, data): val = current_oarepo_communities.get_primary_community_field(data) if val and val != self.primary_community: raise AttributeError('Primary Community cannot be changed')
def primary_community(self): return current_oarepo_communities.get_primary_community_field(self)