def test_preprint_provider_form(self): formatted_rule = [[[self.parent_1._id], True]] new_data = { '_id': 'newname', 'name': 'New Name', 'share_publish_type': 'Preprint', 'subjects_chosen': '{}, {}, {}, {}'.format(self.parent_1.id, self.child_1.id, self.child_2.id, self.grandchild_1.id), 'toplevel_subjects': [self.parent_1.id], 'subjects_acceptable': '[]', 'preprint_word': 'preprint' } form = PreprintProviderForm(data=new_data) nt.assert_true(form.is_valid()) new_provider = form.save() nt.assert_equal(new_provider.name, new_data['name']) nt.assert_equal(new_provider.subjects_acceptable, formatted_rule)
def test_html_fields_are_stripped(self): new_data = { '_id': 'newname', 'name': 'New Name', 'share_publish_type': 'Preprint', 'subjects_chosen': '{}, {}, {}, {}'.format( self.parent_1.id, self.child_1.id, self.child_2.id, self.grandchild_1.id ), 'type': 'osf.preprintprovider', 'toplevel_subjects': [self.parent_1.id], 'subjects_acceptable': '[]', 'advisory_board': '<div><ul><li>Bill<i class="fa fa-twitter"></i> Nye</li></ul></div>', 'description': '<span>Open Preprints <code>Open</code> Science<script></script></span>', 'footer_links': '<p>Xiv: <script>Support</script> | <pre>Contact<pre> | <a href=""><span class="fa fa-facebook"></span></a></p>', 'preprint_word': 'preprint' } stripped_advisory_board = '<div><ul><li>Bill Nye</li></ul></div>' stripped_description = '<span>Open Preprints Open Science</span>' stripped_footer_links = '<p>Xiv: Support | </p>Contact | <a href=""><span class="fa fa-facebook"></span></a><p></p>' form = PreprintProviderForm(data=new_data) nt.assert_true(form.is_valid()) new_provider = form.save() nt.assert_equal(new_provider.name, new_data['name']) nt.assert_equal(new_provider.description, stripped_description) nt.assert_equal(new_provider.footer_links, stripped_footer_links) nt.assert_equal(new_provider.advisory_board, stripped_advisory_board)
def view(self, req, provider): plain_view = views.CreatePreprintProvider() view = setup_form_view(plain_view, req, form=PreprintProviderForm()) view.kwargs = { '{}_provider_id'.format(provider.readable_type): provider.id } return view
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
def test_preprint_provider_form(self): formatted_rule = [[[self.parent_1._id], True]] new_data = { '_id': 'newname', 'name': 'New Name', 'share_publish_type': 'Preprint', 'subjects_chosen': '{}, {}, {}, {}'.format( self.parent_1.id, self.child_1.id, self.child_2.id, self.grandchild_1.id ), 'toplevel_subjects': [self.parent_1.id], 'subjects_acceptable': '[]', 'preprint_word': 'preprint' } form = PreprintProviderForm(data=new_data) nt.assert_true(form.is_valid()) new_provider = form.save() nt.assert_equal(new_provider.name, new_data['name']) nt.assert_equal(new_provider.subjects_acceptable, formatted_rule)
def setUp(self): super(TestCreatePreprintProvider, self).setUp() self.user = AuthUserFactory() self.preprint_provider = PreprintProviderFactory() self.request = RequestFactory().get('/fake_path') self.request.user = self.user self.view = views.CreatePreprintProvider() self.view = setup_form_view(self.view, self.request, form=PreprintProviderForm()) self.view.kwargs = {'preprint_provider_id': self.preprint_provider.id}
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
def setUp(self): super(TestPreprintProviderChangeForm, self).setUp() self.user = AuthUserFactory() self.preprint_provider = PreprintProviderFactory() self.request = RequestFactory().get('/fake_path') self.request.user = self.user self.view = views.PreprintProviderChangeForm() self.view = setup_form_view(self.view, self.request, form=PreprintProviderForm()) self.parent_1 = SubjectFactory(provider=PreprintProviderFactory(_id='osf')) self.child_1 = SubjectFactory(parent=self.parent_1) self.child_2 = SubjectFactory(parent=self.parent_1) self.grandchild_1 = SubjectFactory(parent=self.child_1) self.view.kwargs = {'preprint_provider_id': self.preprint_provider.id}