示例#1
0
 def provider(self, schema, subjects):
     provider = RegistrationProvider.load('osf')
     provider.allow_bulk_uploads = True
     provider.schemas.add(schema)
     provider.subjects.add(*subjects)
     provider.save()
     return provider
示例#2
0
 def egap_reg(self):
     egap_schema = RegistrationSchema.objects.filter(
         name='EGAP Registration'
     ).order_by(
         '-schema_version'
     )[0]
     cos = RegistrationProvider.get_default()
     return RegistrationFactory(schema=egap_schema, provider=cos)
示例#3
0
文件: views.py 项目: xlecours/osf.io
    def create_or_update_provider(self, provider_data):
        provider = self.get_page_provider()
        licenses = [NodeLicense.objects.get(license_id=license_id) for license_id in provider_data.pop('licenses_acceptable', [])]
        default_license = provider_data.pop('default_license', False)
        subject_data = provider_data.pop('subjects', False)
        provider_data.pop('additional_providers')

        if provider:
            for key, val in provider_data.items():
                setattr(provider, key, val)
            provider.save()
        else:
            provider = RegistrationProvider(**provider_data)
            provider._creator = self.request.user
            provider.save()

        if licenses:
            provider.licenses_acceptable = licenses
        if default_license:
            provider.default_license = NodeLicense.objects.get(license_id=default_license)

        # Only adds the JSON taxonomy if there is no existing taxonomy data
        if subject_data and not provider.subjects.count():
            self.add_subjects(provider, subject_data)
        return provider
示例#4
0
 def __init__(self, *args, **kwargs):
     nodelicense_choices = get_nodelicense_choices()
     defaultlicense_choices = get_defaultlicense_choices()
     brand_choices = get_brand_choices()
     super(RegistrationProviderForm, self).__init__(*args, **kwargs)
     self.fields['licenses_acceptable'].choices = nodelicense_choices
     self.fields['default_license'].choices = defaultlicense_choices
     self.fields['brand'].choices = brand_choices
     if kwargs.get('initial', None) and kwargs.get('initial').get('_id', None):
         provider = RegistrationProvider.load(kwargs.get('initial').get('_id'))
         self.fields['default_schema'].choices = provider.schemas.filter(visible=True, active=True).values_list('id', 'name')
     else:
         self.fields['default_schema'].choices = RegistrationSchema.objects.filter(active=True).values_list('id', 'name')
示例#5
0
文件: utils.py 项目: jwalz/osf.io
    def __init__(self, bulk_upload_csv, provider_id):
        if isinstance(bulk_upload_csv, io.StringIO):
            self.raw_csv = bulk_upload_csv.read()
        else:
            self.raw_csv = bulk_upload_csv.read().decode('utf-8')
        csv_io = io.StringIO(self.raw_csv)
        self.reader = csv.DictReader(csv_io)
        self.headers = self.reader.fieldnames
        schema_id_row = next(self.reader)
        self.schema_id = schema_id_row[self.reader.fieldnames[0]]
        self.provider_id = provider_id

        self.registration_provider = RegistrationProvider.load(
            self.provider_id)
        if self.registration_provider is None:
            raise NotFound(
                detail=
                f'Registration provider with id "{self.provider_id}" was not found'
            )

        try:
            self.registration_schema = self.registration_provider.schemas.get(
                _id=self.schema_id)
        except RegistrationSchema.DoesNotExist:
            raise NotFound(
                detail=f'Schema with id "{self.schema_id}" was not found')

        if self.registration_schema.has_files and self.registration_schema.schema_blocks.filter(
                block_type='file-input', required=True).exists():
            raise FileUploadNotSupportedError('File uploads are not supported')

        self.schema_questions = get_schema_questions_validations(
            self.registration_schema)
        self.validations = {**self.schema_questions, **METADATA_FIELDS}
        self.errors = []
        self.validate_csv_header_list()
        self.store = Store(self.registration_provider)
        self.rows = [
            Row(row, self.validations, self.store,
                functools.partial(self.log_error, row_index=index + 3))
            for index, row in enumerate(self.reader)
        ]
        csv_io.close()
示例#6
0
 def non_egap_provider(self):
     return RegistrationProvider.get_default()
示例#7
0
 def provider(self):
     return RegistrationProvider.get_default()
示例#8
0
 def registration_provider(self, open_ended_schema, provider_subjects):
     osf_provider = RegistrationProvider.load('osf')
     osf_provider.schemas.add(open_ended_schema)
     osf_provider.subjects.add(*provider_subjects)
     osf_provider.save()
     return osf_provider