def run(self, *args, **kwargs): self.document = Document.objects.get(pk=args[0]) user = User.objects.get(pk=args[1]) if not self.document.can_manage(user): # TODO: Log this return manager = settings.PLATFORM_MANAGER() manager.delete_document(self.document)
def run(self, *args, **kwargs): self.project = Project.objects.get(pk=args[0]) user = User.objects.get(pk=args[1]) if not self.project.can_manage(user): # TODO: Log this return for document in self.project.document_set.all(): manager = settings.PLATFORM_MANAGER() manager.delete_document(document)
def set_active(self, active): manager = settings.PLATFORM_MANAGER() manager.archive_document( self) if active else manager.retrieve_document(self) self.is_active = active if not self.is_active: self.removed = timezone.now().date() self.save()
def save(self, document, commit=True): self.instance.document = document self.instance.user = self.user manager = settings.PLATFORM_MANAGER() manager.upload_document(self.cleaned_data['file'].read(), str(self.instance.uuid)) # TODO: Remove this when file uploading becomes more civilized. self.file = None return super(NewDocumentVersionForm, self).save(commit)
def run(self, *args, **kwargs): document = Document.objects.get(pk=args[0]) user = User.objects.get(pk=args[1]) manager = settings.PLATFORM_MANAGER() # If the user does not have change or create priviliages, fail. if not document.can_create(user): # TODO: this should be logged return False # Create a temp dir and documents directory inside. path = tempfile.mkdtemp() os.mkdir(path + '/documents') # Save the path on the task for later cleanup self.path = path # TODO: If the file exists, we should append a unique id so that # the files do not overwrite each other. # Download all the documents into the documents dir. for version in document.documentversion_set.all(): response = requests.get(manager.get_document_url(version), stream=True) with open('{0}/{1}/{2}'.format(path, 'documents', version.name), 'wb') as f: for chunk in response.iter_content(chunk_size=1024): if chunk: # filter out keep-alive new chunks f.write(chunk) # Make a zip file from all the documents export_path = shutil.make_archive( '{0}/{1}'.format(path, document.name), 'zip', '{0}/{1}'.format(path, '/documents')) # Upload the document somewhere. export_details = manager.upload_export(export_path) export = Export.objects.create(name=export_path.split('/')[-1], user=user, details=export_details, key=get_random_string(length=78)) # Cleanup the temp files. self.cleanup() # TODO: this will need to be refactored when a notification is in place. # Send a notification to download user.send_invite(settings.EMAIL_APP, 'email/document_export', _('Document Export'), export)
def post(self, request, *args, **kwargs): if self.form.is_valid(): try: avatar_content = request.FILES['avatar'].read() avatar = Image.open(BytesIO(avatar_content)) avatar = avatar.resize(size) avatar_out = BytesIO() avatar.save(avatar_out, format='PNG') avatar_out.seek(0) manager = settings.PLATFORM_MANAGER() manager.upload_avatar(avatar_out, self.user) except Exception as exception: print(exception) return redirect(reverse('users:avatar', args=[self.user.pk])) return self.render_to_response(self.get_context_data())
def run(self, *args, **kwargs): project = Project.objects.get(pk=args[0]) user = User.objects.get(pk=args[1]) manager = settings.PLATFORM_MANAGER() # If the user does not have change or create priviliages, fail. if not project.has_change(user) and not project.has_create(user): # TODO: this should be logged return False # Create a temp dir and documents directory inside. path = tempfile.mkdtemp() os.mkdir(path + '/documents') # Save the path on the task for later cleanup self.path = path # Download all the documents into the documents dir. for document in project.get_documents(user): latest = document.get_latest() response = requests.get(manager.get_document_url(latest), stream=True) with open( '{0}/{1}/{2}'.format(path, 'documents', latest.file.name), 'wb') as f: for chunk in response.iter_content(chunk_size=1024): if chunk: # filter out keep-alive new chunks f.write(chunk) # Make a zip file from all the documents export_path = shutil.make_archive('{0}/{1}'.format(path, project.name), 'zip', '{0}/{1}'.format(path, '/documents')) # Upload the document somewhere. export_details = manager.upload_export(export_path) export = Export.objects.create(name=export_path.split('/')[-1], user=user, details=export_details, key=get_random_string(length=255)) # Cleanup the temp files. self.cleanup()
def http_response(self): manager = settings.PLATFORM_MANAGER() url = manager.get_document_url(self) return redirect(url)
def get(self, request, token, *args, **kwargs): export = get_object_or_404(Export, key=token) manager = settings.PLATFORM_MANAGER() return redirect(manager.get_export_url(export))