def add_cell(request, matrix_id): data = get_header_data(request.user) if data["credential_flag"] == NO_CREDENTIALS: return HttpResponseRedirect(reverse('home', args=())) else: matrix = Matrix.objects.get(id=matrix_id) authority = get_authority_for_bench_and_user_and_requester( matrix, request.user) if authority.is_viewer() == True or authority.is_none() == True: return HttpResponseRedirect(reverse('home', args=())) else: cell_list = Cell.objects.filter(matrix=matrix) if not cell_list: cell1 = Cell.create(matrix, "", "", 0, 0, "", None) cell2 = Cell.create(matrix, "", "", 0, 1, "", None) cell3 = Cell.create(matrix, "", "", 0, 2, "", None) cell4 = Cell.create(matrix, "", "", 1, 0, "", None) cell5 = Cell.create(matrix, "", "", 1, 1, "", None) cell6 = Cell.create(matrix, "", "", 1, 2, "", None) cell7 = Cell.create(matrix, "", "", 2, 0, "", None) cell8 = Cell.create(matrix, "", "", 2, 1, "", None) cell9 = Cell.create(matrix, "", "", 2, 2, "", None) cell1.save() cell2.save() cell3.save() cell4.save() cell5.save() cell6.save() cell7.save() cell8.save() cell9.save() matrix.save() matrix_cells = matrix.get_matrix() columns = matrix.get_columns() rows = matrix.get_rows() data.update({ 'matrix': matrix, 'rows': rows, 'columns': columns, 'matrix_cells': matrix_cells }) return HttpResponseRedirect(reverse('matrix', args=(matrix_id, )))
def add_row_below(request, matrix_id, row_id): data = get_header_data(request.user) if data["credential_flag"] == NO_CREDENTIALS: return HttpResponseRedirect(reverse('home', args=())) else: matrix = get_object_or_404(Matrix, pk=matrix_id) authority = get_authority_for_bench_and_user_and_requester( matrix, request.user) if authority.is_viewer() == True or authority.is_none() == True: return HttpResponseRedirect(reverse('home', args=())) else: matrix = Matrix.objects.get(id=matrix_id) oldCells = Cell.objects.filter(matrix=matrix_id).filter( ycoordinate__gt=row_id) columns = matrix.get_columns() new_row_id = int(row_id) + 1 for oldcell in oldCells: oldcell.increment_y() oldcell.save() for i, column in enumerate(columns): cell = Cell.create(matrix, "", "", i, new_row_id, "", None) cell.save() matrix.save() matrix_cells = matrix.get_matrix() columns = matrix.get_columns() rows = matrix.get_rows() data.update({ 'matrix': matrix, 'rows': rows, 'columns': columns, 'matrix_cells': matrix_cells }) return HttpResponseRedirect(reverse('matrix', args=(matrix_id, )))
def has_object_permission(self, request, view, obj): return_flag = False authority = get_authority_for_bench_and_user_and_requester( obj, request.user) # Read permissions are allowed to any request, # Write permissions are allowed if the user is a SuperUser. if request.method in permissions.SAFE_METHODS: # A Users Authority must either be Editor, Owner or Admin for Write permission. if authority.is_viewer() == True or authority.is_editor( ) == True or authority.is_owner() == True or authority.is_admin( ) == True: return_flag = True else: if request.user.is_superuser == True: return_flag = True else: # Write permissions are allowed for the owner of the bench/image. if obj.owner == request.user: # A Users must have a Credential record and a Password to write to WordPress. if credential_exists( request.user) == True and credential_apppwd( request.user) != '': return_flag = True else: # A Users Authority must either be Editor, Owner or Admin for Write permission. if authority.is_editor() == True or authority.is_owner( ) == True or authority.is_admin() == True: # A Users must have a Credential record and a Password to write to WordPress. if credential_exists( request.user) == True and credential_apppwd( request.user) != '': return_flag = True return return_flag
def choose_collection(request, matrix_id, cell_id, collection_id, path_from): data = get_header_data(request.user) collection_image_list = list() if data["credential_flag"] == NO_CREDENTIALS: return HttpResponseRedirect(reverse('home', args=())) else: matrix = get_object_or_404(Matrix, pk=matrix_id) owner = get_object_or_404(User, pk=matrix.owner_id) user = get_object_or_404(User, pk=request.user.id) authority = get_authority_for_bench_and_user_and_requester( matrix, user) if authority.is_none(): return HttpResponseRedirect(reverse('home', args=())) collection = get_object_or_404(Collection, pk=collection_id) if collection.is_inactive(): collection.set_active() if exists_active_collection_for_user(request.user): set_inactive_collection_for_user(request.user) collection.save() matrix.set_last_used_collection(collection) matrix.save() if path_from == VIEW_MATRIX: return redirect('matrix', matrix_id=matrix_id) if path_from == AMEND_CELL: return redirect('amend_cell', matrix_id=matrix_id, cell_id=cell_id) return redirect('matrix', matrix_id=matrix_id)
def append_column(request, matrix_id): data = get_header_data(request.user) if data["credential_flag"] == NO_CREDENTIALS: return HttpResponseRedirect(reverse('home', args=())) else: matrix = get_object_or_404(Matrix, pk=matrix_id) authority = get_authority_for_bench_and_user_and_requester( matrix, request.user) if authority.is_viewer() == True or authority.is_none() == True: return HttpResponseRedirect(reverse('home', args=())) else: matrix = Matrix.objects.get(id=matrix_id) nextColumn = matrix.get_column_count() rows = matrix.get_rows() for i, row in enumerate(rows): cell = Cell.create(matrix, "", "", nextColumn, i, "", None) cell.save() matrix.save() matrix_cells = matrix.get_matrix() columns = matrix.get_columns() rows = matrix.get_rows() data.update({ 'matrix': matrix, 'rows': rows, 'columns': columns, 'matrix_cells': matrix_cells }) return HttpResponseRedirect(reverse('matrix', args=(matrix_id, )))
def shuffle_rows(request): """ AJAX - Shuffle the Rows """ source = request.POST['source'] target = request.POST['target'] in_source_cell = get_object_or_404(Cell, pk=source) in_target_cell = get_object_or_404(Cell, pk=target) source_ycoordinate = in_source_cell.ycoordinate target_ycoordinate = in_target_cell.ycoordinate matrix = in_source_cell.matrix owner = get_object_or_404(User, pk=matrix.owner_id) user = get_object_or_404(User, pk=request.user.id) if credential_exists(user): authority = get_authority_for_bench_and_user_and_requester( matrix, request.user) if authority.is_viewer() or authority.is_none(): data = { 'failure': True, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: source_row_cells = matrix.get_row(source_ycoordinate) if source_ycoordinate < target_ycoordinate: oldCells = Cell.objects.filter(matrix=matrix.id).filter( ycoordinate__gt=source_ycoordinate).filter( ycoordinate__lte=target_ycoordinate) output_cells = list() for oldcell in oldCells: oldcell.decrement_y() output_cells.append(oldcell) for source_cell in source_row_cells: source_cell.set_ycoordinate(target_ycoordinate) output_cells.append(source_cell) for output_cell in output_cells: output_cell.save() if source_ycoordinate > target_ycoordinate: oldCells = Cell.objects.filter(matrix=matrix.id).filter( ycoordinate__gte=target_ycoordinate).filter( ycoordinate__lt=source_ycoordinate) output_cells = list() for oldcell in oldCells: oldcell.increment_y() output_cells.append(oldcell) for source_cell in source_row_cells: source_cell.set_ycoordinate(target_ycoordinate) output_cells.append(source_cell) for output_cell in output_cells: output_cell.save() if matrix.get_max_row() == target_ycoordinate: nextRow = matrix.get_row_count() columns = matrix.get_columns() for i, column in enumerate(columns): cell = Cell.create(matrix, "", "", i, nextRow, "", None) cell.save() matrix.save() data = { 'failure': False, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: data = {'failure': True, 'source': str(source), 'target': str(target)} return JsonResponse(data)
def delete_this_row(request, matrix_id, row_id): serverWordpress = get_primary_wordpress_server() data = get_header_data(request.user) if data["credential_flag"] == NO_CREDENTIALS: return HttpResponseRedirect(reverse('home', args=())) else: matrix = get_object_or_404(Matrix, pk=matrix_id) authority = get_authority_for_bench_and_user_and_requester( matrix, request.user) if authority.is_viewer() == True or authority.is_none() == True: return HttpResponseRedirect(reverse('home', args=())) else: matrix = Matrix.objects.get(id=matrix_id) deleteRow = int(row_id) oldCells = Cell.objects.filter(matrix=matrix_id, ycoordinate=deleteRow) for oldCell in oldCells: if oldCell.has_blogpost() == True: credential = get_credential_for_user(request.user) if credential.has_apppwd(): response = serverWordpress.delete_wordpress_post( credential, oldCell.blogpost) if oldCell.has_image(): if not exists_collections_for_image(oldCell.image): cell_list = get_cells_for_image(oldCell.image) delete_flag = True for otherCell in cell_list: if otherCell.matrix.id != matrix_id: delete_flag = False if delete_flag == True: image = oldCell.image oldCell.image = None oldCell.save() image.delete() Cell.objects.filter(matrix=matrix_id, ycoordinate=deleteRow).delete() matrix.save() moveCells = Cell.objects.filter(matrix=matrix_id, ycoordinate__gt=deleteRow) for moveCell in moveCells: moveCell.decrement_y() moveCell.save() matrix_cells = matrix.get_matrix() columns = matrix.get_columns() rows = matrix.get_rows() data.update({ 'matrix': matrix, 'rows': rows, 'columns': columns, 'matrix_cells': matrix_cells }) return HttpResponseRedirect(reverse('matrix', args=(matrix_id, )))
def amend_cell(request, matrix_id, cell_id): serverWordpress = get_primary_wordpress_server() data = get_header_data(request.user) if data["credential_flag"] == NO_CREDENTIALS: return HttpResponseRedirect(reverse('home', args=())) else: cell = get_object_or_404(Cell, pk=cell_id) matrix = get_object_or_404(Matrix, pk=matrix_id) authority = get_authority_for_bench_and_user_and_requester(matrix, request.user) if authority.is_viewer() == True or authority.is_none() == True: matrix_cells = matrix.get_matrix() columns = matrix.get_columns() rows = matrix.get_rows() data.update({ 'matrix': matrix, 'rows': rows, 'columns': columns, 'matrix_cells': matrix_cells }) return HttpResponseRedirect(reverse('matrix', args=(matrix_id,))) else: cell_link = get_blog_link_post_url() + cell.blogpost matrix_link = 'matrix_link' amend_cell = 'amend_cell' credential = get_credential_for_user(request.user) if not credential.has_apppwd(): matrix_link = '' collection_image_list = list() if matrix.has_last_used_collection(): collection_image_list = get_images_for_collection(matrix.last_used_collection) else: if exists_active_collection_for_user(request.user): collection_image_list = get_active_collection_images_for_user(request.user) collection_list = get_active_collection_for_user(request.user) collection = collection_list[0] matrix.set_last_used_collection(collection) matrix.save() if request.method == HTTP_POST: form = SearchUrlForm(request.POST) image = None if form.is_valid(): cd = form.cleaned_data url_string = cd.get('url_string') url_string_ebi_sca_out = convert_url_ebi_sca_to_json(url_string) url_string_omero_out = convert_url_omero_image_to_cpw(request, url_string) if url_string_omero_out != '' and url_string_ebi_sca_out != '': messages.error(request, "URL not found!") form.add_error(None, "URL not found!") data.update({ 'form': form, 'collection_image_list': collection_image_list, 'amend_cell': amend_cell, 'matrix_link': matrix_link, 'cell': cell, 'cell_link': cell_link, 'matrix': matrix }) return render(request, 'matrices/amend_cell.html', data) if url_string_omero_out == '' and url_string_ebi_sca_out == '': messages.error(request, "URL not found!") form.add_error(None, "URL not found!") data.update({ 'form': form, 'collection_image_list': collection_image_list, 'amend_cell': amend_cell, 'matrix_link': matrix_link, 'cell': cell, 'cell_link': cell_link, 'matrix': matrix }) return render(request, 'matrices/amend_cell.html', data) if url_string_omero_out != '' and url_string_ebi_sca_out == '': server = get_server_from_omero_url(url_string_omero_out) image_id = get_id_from_omero_url(url_string_omero_out) if exists_active_collection_for_user(request.user): image = add_image_to_collection(request.user, server, image_id, 0) queryset = get_active_collection_for_user(request.user) for collection in queryset: matrix.set_last_used_collection(collection) else: messages.error(request, "ERROR: You have no Active Image Collection; Please create a Collection!") form.add_error(None, "ERROR: You have no Active Image Collection; Please create a Collection!") data.update({ 'form': form, 'collection_image_list': collection_image_list, 'amend_cell': amend_cell, 'matrix_link': matrix_link, 'cell': cell, 'cell_link': cell_link, 'matrix': matrix }) return render(request, 'matrices/amend_cell.html', data) if url_string_omero_out == '' and url_string_ebi_sca_out != '': temp_dir = config('HIGHCHARTS_TEMP_DIR') output_dir = config('HIGHCHARTS_OUTPUT_DIR') highcharts_host = config('HIGHCHARTS_HOST') highcharts_web = config('HIGHCHARTS_OUTPUT_WEB') experiment_id = get_an_ebi_sca_experiment_id(url_string) image_id = convert_url_ebi_sca_to_chart_id(url_string) shell_command = create_an_ebi_sca_chart(url_string_ebi_sca_out, experiment_id, image_id, highcharts_host, temp_dir, output_dir) success = call(str(shell_command), shell=True) if success == 0: server = get_server_from_ebi_sca_url(url_string_ebi_sca_out) if exists_active_collection_for_user(request.user): image = add_image_to_collection(request.user, server, image_id, 0) queryset = get_active_collection_for_user(request.user) for collection in queryset: matrix.set_last_used_collection(collection) else: messages.error(request, "ERROR: You have no Active Image Collection; Please create a Collection!") form.add_error(None, "ERROR: You have no Active Image Collection; Please create a Collection!") data.update({ 'form': form, 'collection_image_list': collection_image_list, 'amend_cell': amend_cell, 'matrix_link': matrix_link, 'cell': cell, 'cell_link': cell_link, 'matrix': matrix }) return render(request, 'matrices/amend_cell.html', data) else: messages.error(request, "Unable to generate Chart - shell_command : FAILED!") form.add_error(None, "Unable to generate Chart - shell_command : FAILED!") data.update({ 'form': form, 'collection_image_list': collection_image_list, 'amend_cell': amend_cell, 'matrix_link': matrix_link, 'cell': cell, 'cell_link': cell_link, 'matrix': matrix }) return render(request, 'matrices/amend_cell.html', data) cell.set_title(image.name) cell.set_description(image.name) cell.set_image(image) cell.set_matrix(matrix) post_id = '' if cell.has_no_blogpost() == True: credential = get_credential_for_user(request.user) if credential.has_apppwd(): returned_blogpost = serverWordpress.post_wordpress_post(credential, cell.title, cell.description) if returned_blogpost['status'] == WORDPRESS_SUCCESS: post_id = returned_blogpost['id'] else: messages.error(request, "ERROR: WordPress Error - Contact System Administrator!") form.add_error(None, "ERROR: WordPress Error - Contact System Administrator!") data.update({ 'form': form, 'collection_image_list': collection_image_list, 'amend_cell': amend_cell, 'matrix_link': matrix_link, 'cell': cell, 'cell_link': cell_link, 'matrix': matrix }) return render(request, 'matrices/amend_cell.html', data) else: cell.set_blogpost(post_id) cell.save() matrix.save() else: messages.error(request, "ERROR: Form is Invalid!") form.add_error(None, "ERROR: Form is Invalid!") data.update({ 'form': form, 'collection_image_list': collection_image_list, 'amend_cell': amend_cell, 'matrix_link': matrix_link, 'cell': cell, 'cell_link': cell_link, 'matrix': matrix }) return render(request, 'matrices/amend_cell.html', data) form = SearchUrlForm() data.update({ 'form': form, 'collection_image_list': collection_image_list, 'amend_cell': amend_cell, 'matrix_link': matrix_link, 'cell': cell, 'cell_link': cell_link, 'matrix': matrix }) return render(request, 'matrices/amend_cell.html', data)
def clear_cell(request, matrix_id, cell_id, path_from): serverWordpress = get_primary_wordpress_server() data = get_header_data(request.user) if data["credential_flag"] == NO_CREDENTIALS: return HttpResponseRedirect(reverse('home', args=())) else: cell = get_object_or_404(Cell, pk=cell_id) matrix = get_object_or_404(Matrix, pk=matrix_id) authority = get_authority_for_bench_and_user_and_requester(matrix, request.user) if authority.is_viewer() == True or authority.is_none() == True: matrix_cells = matrix.get_matrix() columns = matrix.get_columns() rows = matrix.get_rows() data.update({ 'matrix': matrix, 'rows': rows, 'columns': columns, 'matrix_cells': matrix_cells }) return HttpResponseRedirect(reverse('matrix', args=(matrix_id,))) else: if cell.has_blogpost() == True: credential = get_credential_for_user(request.user) if credential.has_apppwd(): response = serverWordpress.delete_wordpress_post(credential, cell.blogpost) if response != WORDPRESS_SUCCESS: matrix_cells = matrix.get_matrix() columns = matrix.get_columns() rows = matrix.get_rows() data.update({ 'matrix': matrix, 'rows': rows, 'columns': columns, 'matrix_cells': matrix_cells }) return HttpResponseRedirect(reverse('matrix', args=(matrix_id,))) if cell.has_image(): if not exists_collections_for_image(cell.image): cell_list = get_cells_for_image(cell.image) delete_flag = True for otherCell in cell_list: if otherCell.matrix.id != matrix_id: delete_flag = False if delete_flag == True: image = cell.image image.delete() cell.set_blogpost('') cell.set_title('') cell.set_description('') cell.image = None cell.save() matrix_cells = matrix.get_matrix() columns = matrix.get_columns() rows = matrix.get_rows() if path_from == AMEND_CELL: collection_image_list = get_images_for_collection(matrix.last_used_collection) form = SearchUrlForm() cell_link = get_blog_link_post_url() + cell.blogpost matrix_link = 'matrix_link' amend_cell = 'amend_cell' credential = get_credential_for_user(request.user) if not credential.has_apppwd(): matrix_link = '' return_page = 'matrices/amend_cell.html' data.update({ 'form': form, 'collection_image_list': collection_image_list, 'amend_cell': amend_cell, 'matrix_link': matrix_link, 'cell': cell, 'cell_link': cell_link, 'matrix': matrix }) return HttpResponseRedirect(reverse('amend_cell', args=(matrix_id, cell_id, ))) #return render(request, return_page, data) else: if path_from == VIEW_MATRIX: data.update({ 'matrix': matrix, 'rows': rows, 'columns': columns, 'matrix_cells': matrix_cells }) return HttpResponseRedirect(reverse('matrix', args=(matrix_id,))) data.update({ 'matrix': matrix, 'rows': rows, 'columns': columns, 'matrix_cells': matrix_cells }) return HttpResponseRedirect(reverse('matrix', args=(matrix_id,)))
def overwrite_cell(request): """ AJAX - Overwrite Cell - MOVE """ source = request.POST['source'] target = request.POST['target'] source_type = request.POST['source_type'] source_cell = get_object_or_404(Cell, pk=source) target_cell = get_object_or_404(Cell, pk=target) matrix = source_cell.matrix owner = get_object_or_404(User, pk=matrix.owner_id) user = get_object_or_404(User, pk=request.user.id) serverWordpress = get_primary_wordpress_server() if credential_exists(user): authority = get_authority_for_bench_and_user_and_requester( matrix, request.user) if authority.is_viewer() or authority.is_none(): data = { 'failure': True, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: if matrix.get_max_row() == target_cell.ycoordinate: nextRow = matrix.get_row_count() columns = matrix.get_columns() for i, column in enumerate(columns): cell = Cell.create(matrix, "", "", i, nextRow, "", None) cell.save() matrix.save() if matrix.get_max_column() == target_cell.xcoordinate: nextColumn = matrix.get_column_count() rows = matrix.get_rows() for i, row in enumerate(rows): cell = Cell.create(matrix, "", "", nextColumn, i, "", None) cell.save() matrix.save() if target_cell.has_blogpost(): credential = get_credential_for_user(request.user) if credential.has_apppwd(): response = serverWordpress.delete_wordpress_post( credential, target_cell.blogpost) if target_cell.has_image(): if not exists_collections_for_image(target_cell.image): cell_list = get_cells_for_image(target_cell.image) delete_flag = True for otherCell in cell_list: if otherCell.matrix.id != matrix.id: delete_flag = False if delete_flag == True: image = target_cell.image target_cell.image = None target_cell.save() image.delete() source_xcoordinate = source_cell.xcoordinate source_ycoordinate = source_cell.ycoordinate target_xcoordinate = target_cell.xcoordinate target_ycoordinate = target_cell.ycoordinate source_cell.xcoordinate = target_xcoordinate source_cell.ycoordinate = target_ycoordinate target_cell.xcoordinate = source_xcoordinate target_cell.ycoordinate = source_ycoordinate target_cell.title = "" target_cell.description = "" target_cell.blogpost = "" target_cell.image = None source_cell.save() target_cell.save() data = { 'failure': False, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: data = {'failure': True, 'source': str(source), 'target': str(target)} return JsonResponse(data)
def import_image(request): """ AJAX - Import Image """ source = request.POST['source'] target = request.POST['target'] source_type = request.POST['source_type'] source_image = get_object_or_404(Image, pk=source) target_cell = get_object_or_404(Cell, pk=target) matrix = target_cell.matrix owner = get_object_or_404(User, pk=matrix.owner_id) user = get_object_or_404(User, pk=request.user.id) serverWordpress = get_primary_wordpress_server() if credential_exists(user): authority = get_authority_for_bench_and_user_and_requester( matrix, request.user) if authority.is_viewer() or authority.is_none(): data = { 'failure': True, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: if matrix.get_max_row() == target_cell.ycoordinate: nextRow = matrix.get_row_count() columns = matrix.get_columns() for i, column in enumerate(columns): cell = Cell.create(matrix, "", "", i, nextRow, "", None) cell.save() matrix.save() if matrix.get_max_column() == target_cell.xcoordinate: nextColumn = matrix.get_column_count() rows = matrix.get_rows() for i, row in enumerate(rows): cell = Cell.create(matrix, "", "", nextColumn, i, "", None) cell.save() matrix.save() post_id = '' target_cell.title = source_image.name target_cell.description = source_image.name target_cell.image = source_image if target_cell.has_no_blogpost(): credential = get_credential_for_user(request.user) if credential.has_apppwd(): returned_blogpost = serverWordpress.post_wordpress_post( credential, target_cell.title, target_cell.description) if returned_blogpost['status'] == WORDPRESS_SUCCESS: post_id = returned_blogpost['id'] target_cell.set_blogpost(post_id) target_cell.save() data = { 'failure': False, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: data = {'failure': True, 'source': str(source), 'target': str(target)} return JsonResponse(data)
def edit_matrix(request, matrix_id): serverWordpress = get_primary_wordpress_server() data = get_header_data(request.user) if data["credential_flag"] == NO_CREDENTIALS: return HttpResponseRedirect(reverse('home', args=())) else: matrix = get_object_or_404(Matrix, pk=matrix_id) authority = get_authority_for_bench_and_user_and_requester( matrix, request.user) if authority.is_viewer() == True or authority.is_none() == True: matrix_cells = matrix.get_matrix() columns = matrix.get_columns() rows = matrix.get_rows() data.update({ 'matrix': matrix, 'rows': rows, 'columns': columns, 'matrix_cells': matrix_cells }) return HttpResponseRedirect(reverse('matrix', args=(matrix_id, ))) else: if request.method == HTTP_POST: form = MatrixForm(request.POST, instance=matrix) if form.is_valid(): matrix = form.save(commit=False) if matrix.is_not_high_enough() == True: matrix.set_minimum_height() if matrix.is_not_wide_enough() == True: matrix.set_minimum_width() if matrix.is_too_high() == True: matrix.set_maximum_height() if matrix.is_too_wide() == True: matrix.set_maximum_width() post_id = '' if matrix.has_no_blogpost() == True: credential = get_credential_for_user(request.user) if credential.has_apppwd(): returned_blogpost = serverWordpress.post_wordpress_post( credential, matrix.title, matrix.description) if returned_blogpost[ 'status'] == WORDPRESS_SUCCESS: post_id = returned_blogpost['id'] else: messages.error( request, "ERROR: WordPress Error - Contact System Administrator!" ) form.add_error( None, "ERROR: WordPress Error - Contact System Administrator!" ) data.update({'form': form, 'matrix': matrix}) return render(request, 'matrices/edit_matrix.html', data) matrix.set_blogpost(post_id) matrix.save() matrix_cells = matrix.get_matrix() columns = matrix.get_columns() rows = matrix.get_rows() data.update({ 'matrix': matrix, 'rows': rows, 'columns': columns, 'matrix_cells': matrix_cells }) return HttpResponseRedirect( reverse('matrix', args=(matrix_id, ))) else: messages.error(request, "Matrix Form is Invalid!") form.add_error(None, "Matrix Form is Invalid!") data.update({'form': form, 'matrix': matrix}) else: form = MatrixForm(instance=matrix) data.update({'form': form, 'matrix': matrix}) return render(request, 'matrices/edit_matrix.html', data)
def edit_cell(request, matrix_id, cell_id): serverWordpress = get_primary_wordpress_server() data = get_header_data(request.user) if data["credential_flag"] == NO_CREDENTIALS: return HttpResponseRedirect(reverse('home', args=())) else: cell = get_object_or_404(Cell, pk=cell_id) matrix = get_object_or_404(Matrix, pk=matrix_id) authority = get_authority_for_bench_and_user_and_requester( matrix, request.user) if authority.is_viewer() == True or authority.is_none() == True: matrix_cells = matrix.get_matrix() columns = matrix.get_columns() rows = matrix.get_rows() data.update({ 'matrix': matrix, 'rows': rows, 'columns': columns, 'matrix_cells': matrix_cells }) return HttpResponseRedirect(reverse('matrix', args=(matrix_id, ))) else: if request.method == HTTP_POST: if cell.is_header() == True: form = HeaderForm(request.POST) if form.is_valid(): new_cell = form.save(commit=False) cell.set_title(new_cell.title) cell.set_description(new_cell.description) cell.set_matrix(matrix) cell.save() matrix.save() else: messages.error(request, "ERROR: Form is Invalid!") form.add_error(None, "ERROR: Form is Invalid!") data.update({ 'form': form, 'matrix': matrix, 'cell': cell }) return render(request, 'matrices/edit_cell.html', data) else: imageOld = Image.objects.none imageNew = Image.objects.none if cell.has_no_image() == True: form = CellForm(request.user.id, None, matrix.id, request.POST, instance=cell) else: form = CellForm(request.user.id, cell.image.id, matrix.id, request.POST, instance=cell) if form.is_valid(): cell = form.save(commit=False) cell.set_matrix(matrix) post_id = '' if cell.has_no_blogpost() == True: credential = get_credential_for_user(request.user) if credential.has_apppwd(): returned_blogpost = serverWordpress.post_wordpress_post( credential, cell.title, cell.description) if returned_blogpost[ 'status'] == WORDPRESS_SUCCESS: post_id = returned_blogpost['id'] else: messages.error( request, "ERROR: WordPress Error - Contact System Administrator!" ) form.add_error( None, "ERROR: WordPress Error - Contact System Administrator!" ) data.update({ 'form': form, 'matrix': matrix, 'cell': cell }) return render(request, 'matrices/edit_cell.html', data) cell.set_blogpost(post_id) cell.save() matrix.save() else: messages.error(request, "ERROR: Form is Invalid!") form.add_error(None, "ERROR: Form is Invalid!") data.update({ 'form': form, 'matrix': matrix, 'cell': cell }) return render(request, 'matrices/edit_cell.html', data) matrix_cells = matrix.get_matrix() columns = matrix.get_columns() rows = matrix.get_rows() data.update({ 'matrix': matrix, 'rows': rows, 'columns': columns, 'matrix_cells': matrix_cells }) return HttpResponseRedirect( reverse('matrix', args=(matrix_id, ))) else: if cell.is_header() == True: form = HeaderForm(instance=cell) else: if cell.has_no_image() == True: form = CellForm(request.user.id, None, matrix.id, instance=cell) else: form = CellForm(request.user.id, cell.image.id, matrix.id, instance=cell) data.update({'form': form, 'matrix': matrix, 'cell': cell}) return render(request, 'matrices/edit_cell.html', data)
def overwrite_cell_leave(request): """ AJAX - Overwrite Cell """ source = request.POST['source'] target = request.POST['target'] source_type = request.POST['source_type'] source_cell = get_object_or_404(Cell, pk=source) target_cell = get_object_or_404(Cell, pk=target) matrix = source_cell.matrix owner = get_object_or_404(User, pk=matrix.owner_id) user = get_object_or_404(User, pk=request.user.id) serverWordpress = get_primary_wordpress_server() if credential_exists(user): authority = get_authority_for_bench_and_user_and_requester( matrix, request.user) if authority.is_viewer() or authority.is_none(): data = { 'failure': True, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: if matrix.get_max_row() == target_cell.ycoordinate: nextRow = matrix.get_row_count() columns = matrix.get_columns() for i, column in enumerate(columns): cell = Cell.create(matrix, "", "", i, nextRow, "", None) cell.save() matrix.save() if matrix.get_max_column() == target_cell.xcoordinate: nextColumn = matrix.get_column_count() rows = matrix.get_rows() for i, row in enumerate(rows): cell = Cell.create(matrix, "", "", nextColumn, i, "", None) cell.save() matrix.save() if target_cell.has_blogpost(): credential = get_credential_for_user(request.user) if credential.has_apppwd(): response = serverWordpress.delete_wordpress_post( credential, target_cell.blogpost) if target_cell.has_image(): if not exists_collections_for_image(target_cell.image): cell_list = get_cells_for_image(target_cell.image) delete_flag = True for otherCell in cell_list: if otherCell.matrix.id != matrix.id: delete_flag = False if delete_flag == True: image = target_cell.image target_cell.image = None target_cell.save() image.delete() target_cell.title = source_cell.title target_cell.description = source_cell.description if source_cell.has_image(): imageOld = Image.objects.get(pk=source_cell.image.id) imageNew = Image.create(imageOld.identifier, imageOld.name, imageOld.server, imageOld.viewer_url, imageOld.birdseye_url, imageOld.roi, imageOld.owner) imageNew.save() target_cell.image = imageNew target_cell.blogpost = source_cell.blogpost if source_cell.has_blogpost(): credential = get_credential_for_user(request.user) post_id = '' if credential.has_apppwd(): returned_blogpost = serverWordpress.post_wordpress_post( credential, source_cell.title, source_cell.description) if returned_blogpost['status'] == WORDPRESS_SUCCESS: post_id = returned_blogpost['id'] source_cell.set_blogpost(post_id) source_cell.save() target_cell.save() data = { 'failure': False, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: data = {'failure': True, 'source': str(source), 'target': str(target)} return JsonResponse(data)
def view_matrix_blog(request, matrix_id): serverWordpress = get_primary_wordpress_server() data = get_header_data(request.user) if data["credential_flag"] == NO_CREDENTIALS: return HttpResponseRedirect(reverse('home', args=())) else: matrix = get_object_or_404(Matrix, pk=matrix_id) matrix_cells = matrix.get_matrix() columns = matrix.get_columns() rows = matrix.get_rows() blogpost = '' comment_list = list() authority = get_authority_for_bench_and_user_and_requester( matrix, request.user) if authority.is_viewer() == True or authority.is_editor( ) == True or authority.is_owner() == True or authority.is_admin( ) == True: if matrix.blogpost == '': credential = get_credential_for_user(request.user) post_id = '' if credential.has_apppwd(): returned_blogpost = serverWordpress.post_wordpress_post( credential, matrix.title, matrix.description) if returned_blogpost['status'] == WORDPRESS_SUCCESS: post_id = returned_blogpost['id'] matrix.set_blogpost(post_id) matrix.save() blogpost = serverWordpress.get_wordpress_post(matrix.blogpost) if matrix.blogpost != '': blogpost = serverWordpress.get_wordpress_post(matrix.blogpost) if blogpost['status'] != WORDPRESS_SUCCESS: credential = get_credential_for_user(request.user) post_id = '' if credential.has_apppwd(): returned_blogpost = serverWordpress.post_wordpress_post( credential, matrix.title, matrix.description) if returned_blogpost['status'] == WORDPRESS_SUCCESS: post_id = returned_blogpost['id'] matrix.set_blogpost(post_id) matrix.save() blogpost = serverWordpress.get_wordpress_post( matrix.blogpost) comment_list = serverWordpress.get_wordpress_post_comments( matrix.blogpost) if request.method == HTTP_POST: form = CommentForm(request.POST) if form.is_valid(): cd = form.cleaned_data comment = cd.get('comment') if comment != '': credential = get_credential_for_user(request.user) returned_comment = serverWordpress.post_wordpress_comment( credential, matrix.blogpost, comment) return HttpResponseRedirect( reverse('detail_matrix_blog', args=(matrix_id, ))) else: messages.error(request, "Error") else: form = CommentForm() data.update({ 'form': form, 'matrix': matrix, 'blogpost': blogpost, 'rows': rows, 'columns': columns, 'matrix_cells': matrix_cells, 'comment_list': comment_list }) return render(request, 'matrices/detail_matrix_blog.html', data)
def view_matrix(request, matrix_id): data = get_header_data(request.user) if data["credential_flag"] == NO_CREDENTIALS: return HttpResponseRedirect(reverse('home', args=())) else: matrix = get_object_or_404(Matrix, pk=matrix_id) owner = get_object_or_404(User, pk=matrix.owner_id) user = get_object_or_404(User, pk=request.user.id) authority = get_authority_for_bench_and_user_and_requester( matrix, user) if authority.is_none(): return HttpResponseRedirect(reverse('home', args=())) else: matrix_link = 'matrix_link' view_matrix = 'view_matrix' credential = get_credential_for_user(request.user) if not credential.has_apppwd(): matrix_link = '' collection_image_list = list() if exists_active_collection_for_user(request.user): collection_image_list = get_active_collection_images_for_user( request.user) collection_list = get_active_collection_for_user(request.user) collection = collection_list[0] matrix.set_last_used_collection(collection) matrix.save() else: if matrix.has_last_used_collection(): collection_image_list = get_images_for_collection( matrix.last_used_collection) matrix_cells = matrix.get_matrix() matrix_comments = matrix.get_matrix_comments() matrix_cells_comments = matrix.get_matrix_cell_comments() columns = matrix.get_columns() rows = matrix.get_rows() data.update({ 'collection_image_list': collection_image_list, 'view_matrix': view_matrix, 'matrix_link': matrix_link, 'authority': authority, 'matrix': matrix, 'rows': rows, 'columns': columns, 'matrix_cells': matrix_cells, 'matrix_cells_comments': matrix_cells_comments, 'matrix_comments': matrix_comments }) return render(request, 'matrices/view_matrix.html', data)
def swap_columns(request): """ AJAX - Swap Columns """ source = request.POST['source'] target = request.POST['target'] in_source_cell = get_object_or_404(Cell, pk=source) in_target_cell = get_object_or_404(Cell, pk=target) matrix = in_source_cell.matrix owner = get_object_or_404(User, pk=matrix.owner_id) user = get_object_or_404(User, pk=request.user.id) if credential_exists(user): authority = get_authority_for_bench_and_user_and_requester( matrix, request.user) if authority.is_viewer() or authority.is_none(): data = { 'failure': True, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: source_column_cells = matrix.get_column(in_source_cell.xcoordinate) target_column_cells = matrix.get_column(in_target_cell.xcoordinate) source_xcoordinate = in_source_cell.xcoordinate target_xcoordinate = in_target_cell.xcoordinate output_cells = list() for target_cell in target_column_cells: target_cell.set_xcoordinate(source_xcoordinate) output_cells.append(target_cell) for source_cell in source_column_cells: source_cell.set_xcoordinate(target_xcoordinate) output_cells.append(source_cell) for output_cell in output_cells: output_cell.save() if matrix.get_max_column() == in_target_cell.xcoordinate: nextColumn = matrix.get_column_count() rows = matrix.get_rows() for i, row in enumerate(rows): cell = Cell.create(matrix, "", "", nextColumn, i, "", None) cell.save() matrix.save() data = { 'failure': False, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: data = {'failure': True, 'source': str(source), 'target': str(target)} return JsonResponse(data)