def _insert_publication(request, publication_id): content_type = RestView.get_content_type(request) data = request.raw_post_data logger.info("Attempt to insert publication: %s" % (data)) requester = request.user if 'application/x-bibtex' in content_type: inserted_publication = insert.insert_bibtex_publication(data, requester) else: inserter = insert.get_inserter(content_type) inserted_publication = inserter.modify_publication(data, publication_id, requester=requester) return inserted_publication
def POST(request): """Inserts publications via POST request.""" try: content_type = RestView.get_content_type(request) data = request.raw_post_data logger.info("Attempt to insert publication: %s" % (data)) requester = request.user inserted_publications = None if 'application/x-bibtex' in content_type: inserted_publications = insert.insert_bibtex_publication(data, requester) else: inserter = insert.get_inserter(content_type) inserted_publications = inserter.modify_publication(data, requester=requester) values = {'publication_list': inserted_publications} response = RestView.render_response(request, 'publications', values) response.status_code = RestView.CREATED_STATUS if type(inserted_publications) == type(Publication): response['Location'] = "%s/publication/%s" % (service_url, inserted_publications.id) except InvalidDataException, e: logger.error(e) response = HttpResponse(e.message) response.status_code = RestView.BAD_REQUEST_STATUS
def test_insert_book_bibtex(self): publications = insert_bibtex_publication(self.book_bibtex, self.user) expected_publications = [self.book] self.assertEqual(len(expected_publications), len(publications))