def generate(payload): # Always first do a layout for the project using the current settings before generation # Especially neded where users do not first do a 'preview' before hitting generate button layout(payload) project = Project.objects.get(pk=payload['project_id']) # Check to see if the number of files retrieved from Dropbox is done yet. # If not, just reset this task to new and return if project.num_files_local < project.num_files_on_dropbox: raise RetryTaskException('Local files < Dropbox files') if payload.get('preview'): filename = os.path.join(project.storage_path, 'preview.jpg') # For Previews, an arbitrary size # We need to add setting preview size to layouter... project.set_status('previewing') else: filename = os.path.join(project.storage_path, 'metabotnik.jpg') project.set_status('generating') error_msgs = planodo.make_bitmap(project, filename) new_task(project.user, { 'action': 'makedeepzoom', 'project_id': project.pk }) if payload.get('sendemail'): send_mail('Your generation task for project %s done' % project, 'It can be viewed at https://metabotnik.com/projects/%s/' % project.pk, '*****@*****.**', [project.user.email], fail_silently=False) project.set_status('layout') if error_msgs: return {'error': error_msgs}
def new_project(request): path = request.GET.get('new_with_folder') if not path: path = '' filecount = request.GET.get('filecount', 0) project = Project.objects.create(path=path, user=request.user, num_files_on_dropbox=filecount) new_task(request.user, { 'action': 'download_dropboxfiles', 'project_id': project.pk }) url = reverse('edit_project', args=[project.pk]) return redirect(url)
def getdropbox_project(request, project_id): project = Project.objects.get(pk=project_id) if project.user != request.user and not request.user.is_superuser: return HttpResponseForbidden('Only the owner can request the fetching of Dropbox data for a project') t = new_task(request.user, { 'action': 'download_dropboxfiles', 'project_id': project_id }) project.set_status('downloading') return HttpResponse(str(t.pk))
def getdropbox_project(request, project_id): project = Project.objects.get(pk=project_id) if project.user != request.user and not request.user.is_superuser: return HttpResponseForbidden( 'Only the owner can request the fetching of Dropbox data for a project' ) t = new_task(request.user, { 'action': 'download_dropboxfiles', 'project_id': project_id }) project.set_status('downloading') return HttpResponse(str(t.pk))
def download_dropboxfiles(payload): # Get the Project project = Project.objects.get(pk=payload['project_id']) project.set_status('downloading') # Check to see what files to download from Dropbox client = Dropbox(project.user.dropboxinfo.access_token) num_files = 0 for x in client.files_list_folder(project.path).entries: if x.path_lower.endswith('.jpg') and x.size > 0: # Download the file from Dropbox to local disk local_filename = os.path.split(x.path_lower)[-1] local_filepath = os.path.join(project.originals_path, local_filename) num_files += 1 if os.path.exists(local_filepath ): # and not payload.get('redownload') == True continue client.files_download_to_file(local_filepath, x.path_lower) # Get the metadata as a separate task new_task(project.user, { 'action': 'extract_metadata', 'project_id': project.pk }) # schedule a thumbnail task new_task(project.user, { 'action': 'makethumbnails', 'project_id': project.pk }) # Downloading files can take a long time # In the meantime this Project could have been changed by other tasks # Reload it before setting the status project = Project.objects.get(pk=payload['project_id']) project.num_files_on_dropbox = num_files project.status = 'layout' project.save() return {'downloaded_files_count': num_files}
def download_dropboxfiles(payload): # Get the Project project = Project.objects.get(pk=payload['project_id']) project.set_status('downloading') # Check to see what files to download from Dropbox client = Dropbox(project.user.dropboxinfo.access_token) num_files = 0 for x in client.files_list_folder(project.path).entries: if x.path_lower.endswith('.jpg') and x.size > 0: # Download the file from Dropbox to local disk local_filename = os.path.split(x.path_lower)[-1] local_filepath = os.path.join(project.originals_path, local_filename) num_files += 1 if os.path.exists(local_filepath): # and not payload.get('redownload') == True continue client.files_download_to_file(local_filepath, x.path_lower) # Get the metadata as a separate task new_task(project.user, { 'action': 'extract_metadata', 'project_id': project.pk }) # schedule a thumbnail task new_task(project.user, { 'action': 'makethumbnails', 'project_id': project.pk }) # Downloading files can take a long time # In the meantime this Project could have been changed by other tasks # Reload it before setting the status project = Project.objects.get(pk=payload['project_id']) project.num_files_on_dropbox = num_files project.status = 'layout' project.save() return {'downloaded_files_count':num_files}
def generate(request, project_id): preview = True if request.POST.get('preview') else False sendemail = True if request.POST.get('sendemail') in ('true', '1') else False t = new_task(request.user, { 'action': 'generate', 'preview': preview, 'sendemail': sendemail, 'project_id': project_id }) project = Project.objects.get(pk=project_id) project.layout = request.POST.get('layout', 'horizontal') project.status = 'generating' project.save() return HttpResponse(str(t.pk))
def generate(request, project_id): preview = True if request.POST.get('preview') else False sendemail = True if request.POST.get('sendemail') in ('true', '1') else False t = new_task( request.user, { 'action': 'generate', 'preview': preview, 'sendemail': sendemail, 'project_id': project_id }) project = Project.objects.get(pk=project_id) project.layout = request.POST.get('layout', 'horizontal') project.status = 'generating' project.save() return HttpResponse(str(t.pk))