def destroy(self, request, *args, **kwargs):

        matrix = self.get_object()

        self.check_object_permissions(self.request, matrix)

        cell_list = Cell.objects.filter(Q(matrix=matrix))

        credential = get_credential_for_user(request.user)

        serverWordpress = get_primary_wordpress_server()

        for cell in cell_list:

            if cell.has_blogpost():

                if credential.has_apppwd():

                    response = serverWordpress.delete_wordpress_post(
                        credential, cell.blogpost)

            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

                        cell.image = None

                        cell.save()

                        image.delete()

        if matrix.has_blogpost():

            if credential.has_apppwd():

                response = serverWordpress.delete_wordpress_post(
                    credential, matrix.blogpost)

        matrix.delete()

        return Response(data='Bench Delete Success')
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, )))
Esempio n. 3
0
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,)))
Esempio n. 4
0
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)
Esempio n. 5
0
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)