Beispiel #1
0
    def post(self, request, *args, **kwargs):
        form = ImportFileForm(request.POST, request.FILES)
        provider_id = self.kwargs.get(
            f'{self.provider_namespaces[self.provider_class]}_id', None)

        if form.is_valid():
            file_str = self.parse_file(request.FILES['file'])
            file_json = json.loads(file_str)
            current_fields = [
                f.name for f in self.provider_class._meta.get_fields()
            ]
            # make sure not to import an exported access token for SHARE
            cleaned_result = {
                key: value
                for key, value in file_json['fields'].items()
                if key not in FIELDS_TO_NOT_IMPORT_EXPORT
                and key in current_fields
            }
            if provider_id:
                cleaned_result['id'] = provider_id

            provider = self.provider_class.update_or_create_from_json(
                cleaned_result, request.user)

            return redirect(
                f'{self.provider_namespaces[self.provider_class]}s:detail', **{
                    f'{self.provider_namespaces[self.provider_class]}_id':
                    provider.id
                })
Beispiel #2
0
    def post(self, request, *args, **kwargs):
        form = ImportFileForm(request.POST, request.FILES)
        if form.is_valid():
            file_str = self.parse_file(request.FILES['file'])
            file_json = json.loads(file_str)
            current_fields = [
                f.name for f in PreprintProvider._meta.get_fields()
            ]
            # make sure not to import an exported access token for SHARE
            cleaned_result = {
                key: value
                for key, value in file_json['fields'].items()
                if key not in FIELDS_TO_NOT_IMPORT_EXPORT
                and key in current_fields
            }
            try:
                preprint_provider = self.create_or_update_provider(
                    cleaned_result)
            except ValidationError:
                messages.error(
                    request,
                    'A Validation Error occured, this JSON is invalid or shares an id with an already existing provider.'
                )
                return redirect('preprint_providers:create')

            return redirect('preprint_providers:detail',
                            preprint_provider_id=preprint_provider.id)
Beispiel #3
0
 def post(self, request, *args, **kwargs):
     form = ImportFileForm(request.POST, request.FILES)
     if form.is_valid():
         file_str = self.parse_file(request.FILES['file'])
         file_json = json.loads(file_str)
         cleaned_result = file_json['fields']
         registration_provider = self.create_or_update_provider(cleaned_result)
         return redirect('registration_providers:detail', registration_provider_id=registration_provider.id)
Beispiel #4
0
 def post(self, request, *args, **kwargs):
     form = ImportFileForm(request.POST, request.FILES)
     if form.is_valid():
         file_str = self.parse_file(request.FILES['file'])
         file_json = json.loads(file_str)
         current_fields = [f.name for f in PreprintProvider._meta.get_fields()]
         # make sure not to import an exported access token for SHARE
         cleaned_result = {key: value for key, value in file_json['fields'].items() if key not in FIELDS_TO_NOT_IMPORT_EXPORT and key in current_fields}
         preprint_provider = self.create_or_update_provider(cleaned_result)
         return redirect('preprint_providers:detail', preprint_provider_id=preprint_provider.id)
Beispiel #5
0
    def post(self, request, *args, **kwargs):
        form = ImportFileForm(request.POST, request.FILES)
        if form.is_valid():
            file_str = self.parse_file(request.FILES['file'])
            file_json = json.loads(file_str)
            cleaned_result = file_json['fields']
            try:
                collection_provider = self.create_or_update_provider(cleaned_result)
            except exceptions.ValidationError:
                messages.error(request, 'A Validation Error occured, this JSON is invalid or shares an id with an already existing provider.')
                return redirect('collection_providers:create')

            return redirect('collection_providers:detail', collection_provider_id=collection_provider.id)
Beispiel #6
0
    def get_context_data(self, *args, **kwargs):
        registration_provider = self.get_object()
        registration_provider_attributes = model_to_dict(registration_provider)
        registration_provider_attributes['default_license'] = registration_provider.default_license.name if registration_provider.default_license else None

        # compile html list of licenses_acceptable so we can render them as a list
        licenses_acceptable = list(registration_provider.licenses_acceptable.values_list('name', flat=True))
        licenses_html = '<ul>'
        for license in licenses_acceptable:
            licenses_html += '<li>{}</li>'.format(license)
        licenses_html += '</ul>'
        registration_provider_attributes['licenses_acceptable'] = licenses_html

        # compile html list of subjects
        subject_ids = registration_provider.all_subjects.values_list('id', flat=True)
        kwargs['registration_provider'] = registration_provider_attributes
        kwargs['subject_ids'] = list(subject_ids)

        subject_html = '<ul class="subjects-list">'
        for parent in registration_provider.top_level_subjects:
            if parent.id in subject_ids:
                mapped_text = ''
                if parent.bepress_subject and parent.text != parent.bepress_subject.text:
                    mapped_text = ' (mapped from {})'.format(parent.bepress_subject.text)
                hash_id = abs(hash(parent.text))
                subject_html = subject_html + '<li data-id={}>{}'.format(hash_id, parent.text) + mapped_text + '</li>'
                child_html = '<ul class="three-cols" data-id={}>'.format(hash_id)
                for child in parent.children.all():
                    grandchild_html = ''
                    if child.id in subject_ids:
                        child_mapped_text = ''
                        if child.bepress_subject and child.text != child.bepress_subject.text:
                            child_mapped_text = ' (mapped from {})'.format(child.bepress_subject.text)
                        child_html = child_html + '<li>{}'.format(child.text) + child_mapped_text + '</li>'
                        grandchild_html = '<ul>'
                        for grandchild in child.children.all():
                            if grandchild.id in subject_ids:
                                grandchild_mapped_text = ''
                                if grandchild.bepress_subject and grandchild.text != grandchild.bepress_subject.text:
                                    grandchild_mapped_text = ' (mapped from {})'.format(grandchild.bepress_subject.text)
                                grandchild_html = grandchild_html + '<li>{}'.format(grandchild.text) + grandchild_mapped_text + '</li>'
                        grandchild_html += '</ul>'
                    child_html += grandchild_html

                child_html += '</ul>'
                subject_html += child_html

        subject_html += '</ul>'
        registration_provider_attributes['subjects'] = subject_html

        fields = model_to_dict(registration_provider)
        kwargs['show_taxonomies'] = False if registration_provider.subjects.exists() else True
        kwargs['form'] = RegistrationProviderForm(initial=fields)
        kwargs['import_form'] = ImportFileForm()
        kwargs['taxonomy_form'] = RegistrationProviderCustomTaxonomyForm()

        # set api key for tinymce
        kwargs['tinymce_apikey'] = settings.TINYMCE_APIKEY

        return kwargs
Beispiel #7
0
 def get_context_data(self, *args, **kwargs):
     kwargs['import_form'] = ImportFileForm()
     kwargs['preprint_provider_id'] = self.kwargs.get(
         'preprint_provider_id')
     kwargs['tinymce_apikey'] = settings.TINYMCE_APIKEY
     kwargs['subject_ids'] = self.get_subject_ids(self.request)
     return super(PreprintProviderChangeForm,
                  self).get_context_data(*args, **kwargs)
Beispiel #8
0
    def get_context_data(self, *args, **kwargs):
        preprint_provider = self.get_object()
        subject_ids = preprint_provider.all_subjects.values_list('id', flat=True)

        preprint_provider_attributes = model_to_dict(preprint_provider)
        kwargs.setdefault('page_number', self.request.GET.get('page', '1'))

        licenses_acceptable = list(preprint_provider.licenses_acceptable.values_list('name', flat=True))
        licenses_html = '<ul>'
        for license in licenses_acceptable:
            licenses_html += '<li>{}</li>'.format(license)
        licenses_html += '</ul>'
        preprint_provider_attributes['licenses_acceptable'] = licenses_html

        subject_html = '<ul class="three-cols">'
        for parent in preprint_provider.top_level_subjects:
            mapped_text = ''
            if parent.bepress_subject and parent.text != parent.bepress_subject.text:
                mapped_text = ' (mapped from {})'.format(parent.bepress_subject.text)
            subject_html = subject_html + '<li>{}'.format(parent.text) + mapped_text + '</li>'
            child_html = '<ul>'
            for child in parent.children.all():
                grandchild_html = ''
                if child.id in subject_ids:
                    child_mapped_text = ''
                    if child.bepress_subject and child.text != child.bepress_subject.text:
                        child_mapped_text = ' (mapped from {})'.format(child.bepress_subject.text)
                    child_html = child_html + '<li>{}'.format(child.text) + child_mapped_text + '</li>'
                    grandchild_html = '<ul>'
                    for grandchild in child.children.all():
                        if grandchild.id in subject_ids:
                            grandchild_mapped_text = ''
                            if grandchild.bepress_subject and grandchild.text != grandchild.bepress_subject.text:
                                grandchild_mapped_text = ' (mapped from {})'.format(grandchild.bepress_subject.text)
                            grandchild_html = grandchild_html + '<li>{}'.format(grandchild.text) + grandchild_mapped_text + '</li>'
                    grandchild_html += '</ul>'
                child_html += grandchild_html

            child_html += '</ul>'
            subject_html += child_html

        subject_html += '</ul>'
        preprint_provider_attributes['subjects_acceptable'] = subject_html
        preprint_provider_attributes['lower_name'] = preprint_provider._id

        kwargs['preprint_provider_id'] = preprint_provider._id
        kwargs['preprint_provider'] = preprint_provider_attributes
        kwargs['subject_ids'] = list(subject_ids)
        kwargs['logo'] = preprint_provider.get_asset_url('square_color_no_transparent')
        fields = model_to_dict(preprint_provider)
        fields['toplevel_subjects'] = list(subject_ids)
        fields['subjects_chosen'] = ', '.join(str(i) for i in subject_ids)
        kwargs['show_taxonomies'] = False if preprint_provider.subjects.exists() else True
        kwargs['form'] = PreprintProviderForm(initial=fields)
        kwargs['taxonomy_form'] = PreprintProviderCustomTaxonomyForm()
        kwargs['import_form'] = ImportFileForm()
        kwargs['tinymce_apikey'] = settings.TINYMCE_APIKEY
        return kwargs
Beispiel #9
0
    def get_context_data(self, *args, **kwargs):
        institution = self.get_object()
        institution_dict = model_to_dict(institution)
        kwargs.setdefault('page_number', self.request.GET.get('page', '1'))
        kwargs['institution'] = institution_dict
        kwargs['logohost'] = settings.OSF_URL
        fields = institution_dict
        kwargs['change_form'] = InstitutionForm(initial=fields)
        kwargs['import_form'] = ImportFileForm()
        kwargs['node_count'] = institution.nodes.count()

        return kwargs
Beispiel #10
0
    def get_context_data(self, *args, **kwargs):
        preprint_provider = self.get_object()
        subject_ids = preprint_provider.all_subjects.values_list('id',
                                                                 flat=True)

        preprint_provider_attributes = model_to_dict(preprint_provider)
        kwargs.setdefault('page_number', self.request.GET.get('page', '1'))

        licenses_acceptable = list(
            preprint_provider.licenses_acceptable.values_list('name',
                                                              flat=True))
        licenses_html = '<ul>'
        for license in licenses_acceptable:
            licenses_html += '<li>{}</li>'.format(license)
        licenses_html += '</ul>'
        preprint_provider_attributes['licenses_acceptable'] = licenses_html

        subject_html = '<ul class="three-cols">'
        for parent in preprint_provider.top_level_subjects:
            subject_html += '<li>{}</li>'.format(parent.text)
            child_html = '<ul>'
            for child in parent.children.all():
                grandchild_html = ''
                if child.id in subject_ids:
                    child_html += '<li>{}</li>'.format(child.text)
                    grandchild_html = '<ul>'
                    for grandchild in child.children.all():
                        if grandchild.id in subject_ids:
                            grandchild_html += '<li>{}</li>'.format(
                                grandchild.text)
                    grandchild_html += '</ul>'
                child_html += grandchild_html

            child_html += '</ul>'
            subject_html += child_html

        subject_html += '</ul>'
        preprint_provider_attributes['subjects_acceptable'] = subject_html

        kwargs['preprint_provider'] = preprint_provider_attributes
        kwargs['subject_ids'] = list(subject_ids)
        kwargs['logohost'] = settings.OSF_URL
        fields = model_to_dict(preprint_provider)
        fields['toplevel_subjects'] = list(subject_ids)
        fields['subjects_chosen'] = ', '.join(str(i) for i in subject_ids)
        kwargs['show_taxonomies'] = False if preprint_provider.subjects.exists(
        ) else True
        kwargs['form'] = PreprintProviderForm(initial=fields)
        kwargs['import_form'] = ImportFileForm()
        kwargs['tinymce_apikey'] = settings.TINYMCE_APIKEY
        return kwargs
Beispiel #11
0
    def get_context_data(self, *args, **kwargs):
        collection_provider = self.get_object()
        collection_provider_attributes = model_to_dict(collection_provider)
        collection_provider_attributes[
            'default_license'] = collection_provider.default_license.name if collection_provider.default_license else None
        kwargs['collection_provider'] = collection_provider_attributes
        kwargs['import_form'] = ImportFileForm()

        # compile html list of licenses_acceptable so we can render them as a list
        licenses_acceptable = list(
            collection_provider.licenses_acceptable.values_list('name',
                                                                flat=True))
        licenses_html = '<ul>'
        for license in licenses_acceptable:
            licenses_html += '<li>{}</li>'.format(license)
        licenses_html += '</ul>'
        collection_provider_attributes['licenses_acceptable'] = licenses_html

        # compile html list of collected_type_choices
        collected_type_choices_html = '<ul>'
        for choice in collection_provider.primary_collection.collected_type_choices:
            collected_type_choices_html += '<li>{}</li>'.format(choice)
        collected_type_choices_html += '</ul>'
        kwargs['collected_type_choices'] = collected_type_choices_html

        # compile html list of status_choices
        status_choices_html = '<ul>'
        for choice in collection_provider.primary_collection.status_choices:
            status_choices_html += '<li>{}</li>'.format(choice)
        status_choices_html += '</ul>'
        kwargs['status_choices'] = status_choices_html

        # get a dict of model fields so that we can set the initial value for the update form
        fields = model_to_dict(collection_provider)
        fields['collected_type_choices'] = json.dumps(
            collection_provider.primary_collection.collected_type_choices)
        fields['status_choices'] = json.dumps(
            collection_provider.primary_collection.status_choices)
        kwargs['form'] = CollectionProviderForm(initial=fields)

        # set api key for tinymce
        kwargs['tinymce_apikey'] = settings.TINYMCE_APIKEY

        return kwargs
Beispiel #12
0
 def post(self, request, *args, **kwargs):
     form = ImportFileForm(request.POST, request.FILES)
     if form.is_valid():
         file_str = self.parse_file(request.FILES['file'])
         file_json = json.loads(file_str)
         return JsonResponse(file_json[0]['fields'])
Beispiel #13
0
 def get_context_data(self, *args, **kwargs):
     kwargs['import_form'] = ImportFileForm()
     return super(CreateInstitution, self).get_context_data(*args, **kwargs)
Beispiel #14
0
 def get_context_data(self, *args, **kwargs):
     kwargs['import_form'] = ImportFileForm()
     kwargs['show_taxonomies'] = SHOW_TAXONOMIES_IN_PREPRINT_PROVIDER_CREATE
     kwargs['tinymce_apikey'] = settings.TINYMCE_APIKEY
     return super(CreatePreprintProvider,
                  self).get_context_data(*args, **kwargs)
Beispiel #15
0
 def get_context_data(self, *args, **kwargs):
     kwargs['import_form'] = ImportFileForm()
     return super(PreprintProviderChangeForm,
                  self).get_context_data(*args, **kwargs)
Beispiel #16
0
 def post(self, request, *args, **kwargs):
     form = ImportFileForm(request.POST, request.FILES)
     if form.is_valid():
         file_str = self.parse_file(request.FILES['file'])
         file_json = json.loads(file_str)
         return JsonResponse(file_json[0]['fields'])
Beispiel #17
0
 def get_context_data(self, *args, **kwargs):
     kwargs['import_form'] = ImportFileForm()
     kwargs['show_taxonomies'] = True
     kwargs['tinymce_apikey'] = settings.TINYMCE_APIKEY
     return super(CreateRegistrationProvider,
                  self).get_context_data(*args, **kwargs)
Beispiel #18
0
 def get_context_data(self, *args, **kwargs):
     kwargs['import_form'] = ImportFileForm()
     kwargs['tinymce_apikey'] = settings.TINYMCE_APIKEY
     return super().get_context_data(*args, **kwargs)
Beispiel #19
0
 def get_context_data(self, *args, **kwargs):
     kwargs['import_form'] = ImportFileForm()
     kwargs['tinymce_apikey'] = settings.TINYMCE_APIKEY
     return super(CreateCollectionProvider,
                  self).get_context_data(*args, **kwargs)