Exemple #1
0
def add_dataset(request, server_id, dataset_id):

    data = get_header_data(request.user)

    if not exists_active_collection_for_user(request.user):

        return HttpResponseRedirect(reverse('home', args=()))

    if data["credential_flag"] == NO_CREDENTIALS:

        return HttpResponseRedirect(reverse('home', args=()))

    else:

        server = get_object_or_404(Server, pk=server_id)

        if exists_active_collection_for_user(request.user):

            image_ids = request.POST.getlist('checks[]')

            for image_id in image_ids:

                image = add_image_to_collection(request.user, server, image_id,
                                                0)

        else:

            messages.error(
                request,
                "You have no Active Image Collection; Please create a Collection!"
            )

        return HttpResponseRedirect(
            reverse('webgallery_show_dataset', args=(server_id, dataset_id)))
Exemple #2
0
def add_ebi_sca_image(request, server_id, image_id, path_from):

    data = get_header_data(request.user)

    if not exists_active_collection_for_user(request.user):

        return HttpResponseRedirect(reverse('home', args=()))

    if data["credential_flag"] == NO_CREDENTIALS:

        return HttpResponseRedirect(reverse('home', args=()))

    else:

        server = get_object_or_404(Server, pk=server_id)

        if exists_active_collection_for_user(request.user):

            image = add_image_to_collection(request.user, server, image_id, 0)

        else:

            messages.error(
                request,
                "You have no Active Image Collection; Please create a Collection!"
            )

        if server.is_ebi_sca():

            if path_from == "show_ebi_sca_image":

                return HttpResponseRedirect(
                    reverse('webgallery_show_ebi_sca_image',
                            args=(server_id, image_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)