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 save_js(request): response = {} response['errormsg'] = {} status = 403 if request.is_ajax() and request.method == 'POST': the_id = int(request.POST['id']) if 'owner_id' in request.POST: owner_id = int(request.POST['owner_id']) if owner_id != request.user.id: if not check_write_access_rights(owner_id, request.user): return False else: owner_id = request.user.id if 'image' in request.FILES and \ request.FILES['image'].content_type not in ALLOWED_FILETYPES: status = 200 # Not implemented response['errormsg']['error'] = _('Filetype not supported') else: # We only allow owners to change their images. image = Image.objects.filter(pk=the_id, owner=request.user) if image.exists(): image = image[0] status = 200 else: image = Image() image.uploader = request.user image.owner_id = owner_id status = 201 if 'checksum' in request.POST: image.checksum = request.POST['checksum'] image.title = request.POST['title'] if 'imageCat' in request.POST: image.image_cat = request.POST['imageCat'] if 'image' in request.FILES: image.image = request.FILES['image'] if status == 201 and 'image' not in request.FILES: status = 200 response['errormsg']['error'] = _('No file uploaded') else: image.save() response['values'] = { 'pk': image.pk, 'title': image.title, 'image': image.image.url, 'file_type': image.file_type, 'added': mktime(image.added.timetuple()) * 1000, 'checksum': image.checksum, 'cats': image.image_cat.split(',') } if image.thumbnail: response['values']['thumbnail'] = image.thumbnail.url response['values']['height'] = image.height response['values']['width'] = image.width return JsonResponse(response, status=status)
def save_js(request): response = {} response['errormsg'] = {} status = 403 if request.is_ajax() and request.method == 'POST': the_id = int(request.POST['id']) if 'owner_id' in request.POST: owner_id = int(request.POST['owner_id']) if owner_id != request.user.id: if not check_access_rights(owner_id, request.user): return False else: owner_id = request.user.id if 'image' in request.FILES and \ request.FILES['image'].content_type not in ALLOWED_FILETYPES: status = 200 # Not implemented response['errormsg']['error'] = _('Filetype not supported') else: # We only allow owners to change their images. image = Image.objects.filter(pk=the_id, owner=request.user) if image.exists(): image = image[0] status = 200 else: image = Image() image.uploader = request.user image.owner_id = owner_id status = 201 if 'checksum' in request.POST: image.checksum = request.POST['checksum'] image.title = request.POST['title'] if 'imageCat' in request.POST: image.image_cat = request.POST['imageCat'] if 'image' in request.FILES: image.image = request.FILES['image'] if status == 201 and 'image' not in request.FILES: status = 200 response['errormsg']['error'] = _('No file uploaded') else: image.save() response['values'] = { 'pk': image.pk, 'title': image.title, 'image': image.image.url, 'file_type': image.file_type, 'added': mktime(image.added.timetuple()) * 1000, 'checksum': image.checksum, 'cats': image.image_cat.split(',') } if image.thumbnail: response['values']['thumbnail'] = image.thumbnail.url response['values']['height'] = image.height response['values']['width'] = image.width return JsonResponse( response, status=status )
def add_images_to_doc_js(request): response = {} status = 405 if request.is_ajax() and request.method == 'POST': status = 201 doc_id = request.POST['doc_id'] doc = Document.objects.get(id=doc_id) # Delete all existing image links DocumentImage.objects.filter(document_id=doc_id).delete() ids = request.POST.getlist('ids[]') for id in ids: title = 'Deleted' image = Image.objects.filter(id=id).first() if image: user_image = image.userimage_set.all().first() if user_image: title = user_image.title else: image = Image() image.pk = id image.uploader = doc.owner 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=doc, image=image, title=title) return JsonResponse(response, status=status)
def add_images_to_doc(request): response = {} status = 201 doc_id = request.POST["doc_id"] doc = Document.objects.get(id=doc_id) # Delete all existing image links DocumentImage.objects.filter(document_id=doc_id).delete() ids = request.POST.getlist("ids[]") for id in ids: doc_image_data = {"document": doc, "title": "Deleted"} image = Image.objects.filter(id=id).first() if image: user_image = image.userimage_set.all().first() if user_image: doc_image_data["title"] = user_image.title doc_image_data["copyright"] = user_image.copyright else: image = Image() image.pk = id image.uploader = doc.owner f = open( os.path.join( settings.PROJECT_PATH, "base/static/img/error.png" ) ) image.image.save("error.png", File(f)) image.save() doc_image_data["image"] = image DocumentImage.objects.create(**doc_image_data) return JsonResponse(response, status=status)
def save(request): response = {} response['errormsg'] = {} if 'image' in request.FILES and \ request.FILES['image'].content_type not in ALLOWED_FILETYPES: status = 200 # Not implemented response['errormsg']['error'] = _('Filetype not supported') else: image = False if 'id' in request.POST and 'image' not in request.FILES: user_image = UserImage.objects.filter(image_id=int( request.POST['id']), owner=request.user).first() if user_image: image = user_image.image status = 200 if image is False: image = Image() image.uploader = request.user user_image = UserImage() user_image.owner = request.user status = 201 if 'checksum' in request.POST: image.checksum = request.POST['checksum'] user_image.title = request.POST['title'] if 'copyright' in request.POST: user_image.copyright = request.POST['copyright'] if 'cats' in request.POST: user_image.image_cat = request.POST['cats'] if 'image' in request.FILES: image.image = request.FILES['image'] if status == 201 and 'image' not in request.FILES: status = 200 response['errormsg']['error'] = _('No file uploaded') else: image.save() user_image.image = image user_image.save() response['values'] = { 'id': image.id, 'title': user_image.title, 'copyright': json.loads(user_image.copyright), 'image': image.image.url, 'file_type': image.file_type, 'added': mktime(image.added.timetuple()) * 1000, 'checksum': image.checksum, 'cats': json.loads(user_image.image_cat) } if image.thumbnail: response['values']['thumbnail'] = image.thumbnail.url response['values']['height'] = image.height response['values']['width'] = image.width return JsonResponse(response, status=status)
def add_images_to_doc_js(request): response = {} status = 405 if request.is_ajax() and request.method == 'POST': status = 201 doc_id = request.POST['doc_id'] doc = Document.objects.get(id=doc_id) # Delete all existing image links DocumentImage.objects.filter( document_id=doc_id ).delete() ids = request.POST.getlist('ids[]') for id in ids: title = 'Deleted' image = Image.objects.filter(id=id).first() if image: user_image = image.userimage_set.all().first() if user_image: title = user_image.title else: image = Image() image.pk = id image.uploader = doc.owner 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=doc, image=image, title=title ) return JsonResponse( response, status=status )
def save_js(request): response = {} response['errormsg'] = {} status = 403 if request.is_ajax() and request.method == 'POST' : the_id = int(request.POST['id']) image = Image.objects.filter(pk = the_id, uploader = request.user) if image.exists(): image = image[0] status = 200 else: image = Image() image.uploader = request.user status = 201 if 'checksum' in request.POST: image.checksum = request.POST['checksum'] image.title = request.POST['title'] if 'imageCat' in request.POST: image.image_cat = request.POST['imageCat'] if 'image' in request.FILES: image.image = request.FILES['image'] image.save() response['values'] = { 'pk': image.id, 'title': image.title, 'image': image.image.url, 'file_type': image.file_type, 'added': mktime(image.added.timetuple())*1000, 'checksum': image.checksum, 'cats': image.image_cat.split(',') } if image.thumbnail: response['values']['thumbnail'] = image.thumbnail.url response['values']['height'] = image.height response['values']['width'] = image.width return HttpResponse( simplejson.dumps(response), content_type = 'application/json; charset=utf8', status=status )
def save_js(request): response = {} response["errormsg"] = {} status = 403 if request.is_ajax() and request.method == "POST": the_id = int(request.POST["id"]) image = Image.objects.filter(pk=the_id, uploader=request.user) if image.exists(): image = image[0] status = 200 else: image = Image() image.uploader = request.user status = 201 if "checksum" in request.POST: image.checksum = request.POST["checksum"] image.title = request.POST["title"] if "imageCat" in request.POST: image.image_cat = request.POST["imageCat"] if "image" in request.FILES: image.image = request.FILES["image"] image.save() response["values"] = { "pk": image.id, "title": image.title, "image": image.image.url, "file_type": image.file_type, "added": mktime(image.added.timetuple()) * 1000, "checksum": image.checksum, "cats": image.image_cat.split(","), } if image.thumbnail: response["values"]["thumbnail"] = image.thumbnail.url response["values"]["height"] = image.height response["values"]["width"] = image.width return HttpResponse(simplejson.dumps(response), content_type="application/json; charset=utf8", status=status)
def save_js(request): response = {} response['errormsg'] = {} status = 403 if request.is_ajax() and request.method == 'POST': if 'image' in request.FILES and \ request.FILES['image'].content_type not in ALLOWED_FILETYPES: status = 200 # Not implemented response['errormsg']['error'] = _('Filetype not supported') else: image = False if 'id' in request.POST and 'image' not in request.FILES: user_image = UserImage.objects.filter( image_id=int(request.POST['id']), owner=request.user ).first() if user_image: image = user_image.image status = 200 if image is False: image = Image() image.uploader = request.user user_image = UserImage() user_image.owner = request.user status = 201 if 'checksum' in request.POST: image.checksum = request.POST['checksum'] user_image.title = request.POST['title'] if 'cats' in request.POST: user_image.image_cat = request.POST['cats'] if 'image' in request.FILES: image.image = request.FILES['image'] if status == 201 and 'image' not in request.FILES: status = 200 response['errormsg']['error'] = _('No file uploaded') else: image.save() user_image.image = image user_image.save() response['values'] = { 'id': image.id, 'title': user_image.title, 'image': image.image.url, 'file_type': image.file_type, 'added': mktime(image.added.timetuple()) * 1000, 'checksum': image.checksum, 'cats': list( map( int, list(filter(bool, user_image.image_cat.split(','))) ) ) } if image.thumbnail: response['values']['thumbnail'] = image.thumbnail.url response['values']['height'] = image.height response['values']['width'] = image.width return JsonResponse( response, status=status )
def save_js(request): response = {} response['errormsg'] = {} status = 403 if request.is_ajax() and request.method == 'POST': if 'image' in request.FILES and \ request.FILES['image'].content_type not in ALLOWED_FILETYPES: status = 200 # Not implemented response['errormsg']['error'] = _('Filetype not supported') else: image = False if 'id' in request.POST and 'image' not in request.FILES: user_image = UserImage.objects.filter(image_id=int( request.POST['id']), owner=request.user) if user_image.exists(): user_image = user_image[0] image = user_image.image status = 200 if image is False: image = Image() image.uploader = request.user user_image = UserImage() user_image.owner = request.user status = 201 if 'checksum' in request.POST: image.checksum = request.POST['checksum'] user_image.title = request.POST['title'] if 'cats' in request.POST: user_image.image_cat = request.POST['cats'] if 'image' in request.FILES: image.image = request.FILES['image'] if status == 201 and 'image' not in request.FILES: status = 200 response['errormsg']['error'] = _('No file uploaded') else: image.save() user_image.image = image user_image.save() response['values'] = { 'id': image.id, 'title': user_image.title, 'image': image.image.url, 'file_type': image.file_type, 'added': mktime(image.added.timetuple()) * 1000, 'checksum': image.checksum, 'cats': list( map(int, filter(bool, user_image.image_cat.split(',')))) } if image.thumbnail: response['values']['thumbnail'] = image.thumbnail.url response['values']['height'] = image.height response['values']['width'] = image.width return JsonResponse(response, status=status)
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)