def create_revision( owner, template, title, content, bibliography, images, comments, submission_id, revision_version, ): revision = Document() revision.owner = owner revision.template = template revision.title = title revision.content = content revision.bibliography = bibliography revision.path = f"/Submission {submission_id}/{title.replace('/', '')} ({revision_version})" revision.comments = comments revision.save() for image in images: if image is None: image = Image() image.uploader = owner f = open( path.join(settings.PROJECT_PATH, "base/static/img/error.png") ) image.image.save("error.png", File(f)) image.save() DocumentImage.objects.create(document=revision, image=image, title="") return revision
def author_first_submit(self): # The document is not part of an existing submission. journal_id = self.get_argument('journal_id') self.submission = Submission() self.submission.submitter = self.user self.submission.journal_id = journal_id self.submission.save() self.revision = SubmissionRevision() self.revision.submission = self.submission self.revision.version = "1.0.0" version = "1.0.0" # Connect a new document to the submission. title = self.get_argument('title') abstract = self.get_argument('abstract') contents = self.get_argument('contents') bibliography = self.get_argument('bibliography') image_ids = list( filter(None, self.get_argument('image_ids').split(','))) document = Document() journal = Journal.objects.get(id=journal_id) document.owner = journal.editor document.title = title document.contents = contents document.bibliography = bibliography document.save() for id in image_ids: image = Image.objects.filter(id=id).first() if image is None: image = Image() image.pk = id image.uploader = journal.editor f = open( os.path.join(settings.PROJECT_PATH, "base/static/img/error.png")) image.image.save('error.png', File(f)) image.save() DocumentImage.objects.create(document=document, image=image, title='') self.revision.document = document self.revision.save() fidus_url = '{protocol}://{host}'.format( protocol=self.request.protocol, host=self.request.host) post_data = { 'username': self.user.username.encode('utf8'), 'title': title.encode('utf8'), 'abstract': abstract.encode('utf8'), 'first_name': self.get_argument('firstname').encode('utf8'), 'last_name': self.get_argument('lastname').encode('utf8'), 'email': self.user.email.encode('utf8'), 'affiliation': self.get_argument('affiliation').encode('utf8'), 'author_url': self.get_argument('author_url').encode('utf8'), 'journal_id': journal.ojs_jid, 'fidus_url': fidus_url, 'fidus_id': self.submission.id, 'version': version } body = urlencode(post_data) key = journal.ojs_key base_url = journal.ojs_url url = base_url + self.plugin_path + 'authorSubmit' http = AsyncHTTPClient() http.fetch(HTTPRequest(url_concat(url, {'key': key}), 'POST', None, body), callback=self.on_author_first_submit_response)