Beispiel #1
0
def detail_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)

        matrix_link = get_blog_link_post_url() + matrix.blogpost

        matrix_cells = matrix.get_matrix()
        columns = matrix.get_columns()
        rows = matrix.get_rows()

        data.update({
            'matrix': matrix,
            'matrix_link': matrix_link,
            'rows': rows,
            'columns': columns,
            'matrix_cells': matrix_cells
        })

        return render(request, 'matrices/detail_matrix.html', data)
def maintenance(request):

    if request.user.is_superuser:

        data = get_header_data(request.user)

        type_list = Type.objects.all()
        protocol_list = Protocol.objects.all()
        command_list = Command.objects.all()
        blog_list = Blog.objects.all()
        authority_list = Authority.objects.all()
        collection_authority_list = CollectionAuthority.objects.all()

        data.update({
            'type_list': type_list,
            'protocol_list': protocol_list,
            'command_list': command_list,
            'blog_list': blog_list,
            'authority_list': authority_list,
            'collection_authority_list': collection_authority_list
        })

        return render(request, 'host/maintenance.html', data)

    else:

        return HttpResponseRedirect(reverse('home', args=()))
Beispiel #3
0
def show_project(request, server_id, project_id):
    """
    Show a project
    """

    data = get_header_data(request.user)

    if data["credential_flag"] == NO_CREDENTIALS:

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

    else:

        server = get_object_or_404(Server, pk=server_id)

        if server.is_omero547() or server.is_omero56():

            server_data = server.get_imaging_server_project_json(project_id)

            data.update(server_data)

            return render(request, 'gallery/show_project.html', data)

        else:

            return HttpResponseRedirect(reverse('home', args=()))
Beispiel #4
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)))
Beispiel #5
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)))
Beispiel #6
0
def show_ebi_widget(request, server_id, experiment_id):
    """
    Show the EBI widget
    """

    data = get_header_data(request.user)

    if data["credential_flag"] == NO_CREDENTIALS:

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

    else:

        server = get_object_or_404(Server, pk=server_id)

        if server.is_omero547() or server.is_omero56():

            server_data = server.get_ebi_widget_json()

            gene = ''

            data.update({'experimentAccession': experiment_id, 'geneId': gene})

            data.update(server_data)

            return render(request, 'ebi/show_widget.html', data)
Beispiel #7
0
def show_wordpress(request, server_id, page_id):
    """
    Show the Wordpress Server
    """

    data = get_header_data(request.user)

    if data["credential_flag"] == NO_CREDENTIALS:

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

    else:

        server = get_object_or_404(Server, pk=server_id)

        credential = get_credential_for_user(request.user)

        if server.is_wordpress():

            server_data = server.get_wordpress_json(credential, page_id)

            data.update(server_data)

            return render(request, 'gallery/show_wordpress.html', data)

        else:

            return HttpResponseRedirect(reverse('home', args=()))
Beispiel #8
0
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 new_bench_bench_authorisation(request, matrix_id):

    data = get_header_data(request.user)

    if request.method == HTTP_POST:

        next_page = request.POST.get('next', '/')

        form = AuthorisationForm(request.POST)

        if form.is_valid():

            authorisation = form.save(commit=False)

            if authorisation_exists_for_bench_and_permitted(
                    authorisation.matrix, authorisation.permitted):

                authorisation_old = Authorisation.objects.get(
                    Q(matrix=authorisation.matrix)
                    & Q(permitted=authorisation.permitted))

                if authorisation_old.authority != authorisation.authority:

                    authorisation_old.authority = authorisation.authority

                    authorisation_old.save()

            else:

                authorisation.save()

            return HttpResponseRedirect(next_page)

        else:

            messages.error(request, "Bench Authorisation Form is Invalid!")
            form.add_error(None, "Bench Authorisation Form is Invalid!")

            text_flag = " for Bench CPW:" + format(int(matrix_id), '06d')

            data.update({'text_flag': text_flag, 'form': form})

    else:

        text_flag = " for Bench CPW:" + format(int(matrix_id), '06d')

        form = AuthorisationForm()

        form.fields['matrix'] = forms.ModelChoiceField(
            Matrix.objects.filter(id=matrix_id))
        form.fields['matrix'].initial = matrix_id

        form.fields['permitted'] = forms.ModelChoiceField(
            User.objects.exclude(id=request.user.id).exclude(
                is_superuser=True))

        data.update({'text_flag': text_flag, 'form': form})

    return render(request, 'permissions/new_bench_authorisation.html', data)
Beispiel #10
0
def edit_collection(request, collection_id):

    data = get_header_data(request.user)

    if data["credential_flag"] == NO_CREDENTIALS:

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

    else:

        collection = get_object_or_404(Collection, pk=collection_id)

        if request.method == HTTP_POST:

            form = CollectionForm(request.POST, instance=collection)

            if form.is_valid():

                collection = form.save(commit=False)

                if exists_title_for_collection_for_user(
                        request.user, collection.title):

                    messages.error(request, "Collection Title NOT Unique!")
                    form.add_error(None, "Collection Title NOT Unique!")

                    data.update({'form': form, 'collection': collection})

                else:

                    if collection.is_active():

                        if exists_active_collection_for_user(request.user):

                            set_inactive_collection_for_user(request.user)

                    collection.set_owner(request.user)

                    collection.save()

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

            else:

                messages.error(request, "Collection Form is Invalid!")
                form.add_error(None, "Collection Form is Invalid!")

                data.update({'form': form, 'collection': collection})

        else:

            form = CollectionForm(instance=collection)

            data.update({'form': form, 'collection': collection})

        return render(request, 'matrices/edit_collection.html', data)
Beispiel #11
0
def view_user(request, user_id):

    data = get_header_data(request.user)

    subject = get_object_or_404(User, pk=user_id)

    data.update({ 'subject': subject })

    return render(request, 'authorisation/detail_user.html', data)
def list_imaging_hosts(request):

    data = get_header_data(request.user)

    form = SearchUrlForm()

    data.update({'form': form, 'search_from': "list_imaging_hosts"})

    return render(request, 'host/list_imaging_hosts.html', data)
def collectivization(request):

    data = get_header_data(request.user)

    if request.user.is_superuser:

        user_list = User.objects.all()

        out_message_list = list()

        for user in user_list:

            imageCount = 0

            out_message = ""

            if exists_image_for_user(user):

                image_list = get_images_for_user(user)

                if exists_active_collection_for_user(user):

                    out_message = "Default Collection ALREADY exists for User {}".format(
                        user.username)

                else:

                    collection = Collection.create("Default Collection",
                                                   "Default Collection", True,
                                                   user)

                    collection.save()

                    for image in image_list:

                        imageCount = imageCount + 1

                        Collection.assign_image(image, collection)

                    out_message = "Default Collection created for {} Images for User {}".format(
                        imageCount, user.username)

            else:

                out_message = "NO Default Collection created for User {}".format(
                    user.username)

            out_message_list.append(out_message)

        data.update({'out_message_list': out_message_list})

        return render(request, 'authorisation/collectivization.html', data)

    else:

        return HttpResponseRedirect(reverse('home', args=()))
Beispiel #14
0
def new_server(request):

    data = get_header_data(request.user)

    if data["credential_flag"] == NO_CREDENTIALS:

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

    else:

        if request.user.is_superuser:

            if request.method == HTTP_POST:

                form = ServerForm(request.POST)

                if form.is_valid():

                    server = form.save(commit=False)

                    server.set_owner(request.user)

                    cipher = AESCipher(config('NOT_EMAIL_HOST_PASSWORD'))

                    encryptedPwd = cipher.encrypt(server.pwd).decode()

                    server.set_pwd(encryptedPwd)

                    server.save()

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

                else:

                    messages.error(request, "Server Form is Invalid!")
                    form.add_error(None, "Server Form is Invalid!")

                    data.update({
                        'form': form,
                    })

            else:

                form = ServerForm()

                data.update({
                    'form': form,
                })

            return render(request, 'host/new_server.html', data)

        else:

            return HttpResponseRedirect(reverse('home', args=()))
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, )))
Beispiel #16
0
def list_bench_authorisation(request):

    data = get_header_data(request.user)

    authorisation_list = Authorisation.objects.all()

    text_flag = ' ALL Permissions, ALL Benches'
    matrix_id = ''

    data.update({ 'matrix_id': matrix_id, 'text_flag': text_flag, 'authorisation_list': authorisation_list })

    return render(request, 'host/list_bench_authorisation.html', data)
Beispiel #17
0
def view_bench_authorisation(request, bench_authorisation_id):

    data = get_header_data(request.user)

    authorisation = get_object_or_404(Authorisation, pk=bench_authorisation_id)

    data.update({
        'authorisation_id': bench_authorisation_id,
        'authorisation': authorisation
    })

    return render(request, 'permissions/detail_bench_authorisation.html', data)
Beispiel #18
0
def list_my_collection_authorisation(request):

    data = get_header_data(request.user)

    collection_authorisation_list = CollectionAuthorisation.objects.filter(collection__owner=request.user)

    text_flag = ' YOUR Collection Permissions'
    collection_id = ''

    data.update({ 'collection_id': collection_id, 'text_flag': text_flag, 'collection_authorisation_list': collection_authorisation_list })

    return render(request, 'host/list_collection_authorisation.html', data)
def list_my_collection_collection_authorisation(request, collection_id, user_id):

    data = get_header_data(request.user)

    collection_authorisation_list = CollectionAuthorisation.objects.filter(collection__owner=user_id).filter(collection__id=collection_id)

    user = get_object_or_404(User, pk=user_id)

    text_flag = "Permissions for Collection:" + format(int(collection_id), '06d') + " for User " + user.username

    data.update({ 'collection_id': collection_id, 'user_id': user_id, 'text_flag': text_flag, 'collection_authorisation_list': collection_authorisation_list })

    return render(request, 'host/list_collection_authorisation.html', data)
Beispiel #20
0
def delete_collection(request, collection_id):

    data = get_header_data(request.user)

    if data["credential_flag"] == NO_CREDENTIALS:

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

    else:

        collection = get_object_or_404(Collection, pk=collection_id)

        images = get_images_for_collection(collection)

        for image in images:

            collection_list = get_collections_for_image(image)

            delete_flag = False

            for collection_other in collection_list:

                if collection != collection_other:

                    delete_flag = True

            if delete_flag == False:

                if not exists_image_in_cells(image):

                    Collection.unassign_image(image, collection)

                    image.delete()

        if exists_bench_for_last_used_collection(collection):

            matrix_list = get_benches_for_last_used_collection(collection)

            for matrix in matrix_list:

                matrix.set_no_last_used_collection()

                matrix.save()

        if collection.is_active():

            set_first_active_collection_for_user(request.user)

        collection.delete()

        return HttpResponseRedirect(reverse('list_collections', args=()))
Beispiel #21
0
def view_collection_authorisation(request, collection_authorisation_id):

    data = get_header_data(request.user)

    collection_authorisation = get_object_or_404(
        CollectionAuthorisation, pk=collection_authorisation_id)

    data.update({
        'collection_authorisation_id': collection_authorisation_id,
        'collection_authorisation': collection_authorisation
    })

    return render(request, 'permissions/detail_collection_authorisation.html',
                  data)
def list_user_collection_collection_authorisation(request, user_id):

    data = get_header_data(request.user)

    collection_authorisation_list = CollectionAuthorisation.objects.filter(matrix__owner=user_id)

    user = get_object_or_404(User, pk=user_id)

    text_flag = " ALL Collection Permissions for " + user.username
    collection_id = ''

    data.update({ 'collection_id': collection_id, 'user_id': user_id, 'text_flag': text_flag, 'collection_authorisation_list': collection_authorisation_list })

    return render(request, 'host/list_collection_authorisation.html', data)
def edit_collection_authority(request, collection_authority_id):

    if request.user.is_superuser:

        data = get_header_data(request.user)

        collection_authority = get_object_or_404(CollectionAuthority,
                                                 pk=collection_authority_id)

        if request.method == HTTP_POST:

            form = CollectionAuthorityForm(request.POST,
                                           instance=collection_authority)

            if form.is_valid():

                collection_authority = form.save(commit=False)

                collection_authority.set_owner(request.user)

                collection_authority.save()

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

            else:

                messages.error(request,
                               "Collection Authority Form is Invalid!")
                form.add_error(None, "Collection Authority Form is Invalid!")

                data.update({
                    'form': form,
                    'collection_authority': collection_authority
                })

        else:

            form = CollectionAuthorityForm(instance=collection_authority)

            data.update({
                'form': form,
                'collection_authority': collection_authority
            })

        return render(request, 'maintenance/edit_collection_authority.html',
                      data)

    else:

        return HttpResponseRedirect(reverse('home', args=()))
Beispiel #24
0
def show_ebi_sca_image(request, server_id, image_id):
    """
    Show a chart from an EBI SCA Server
    """

    data = get_header_data(request.user)

    if data["credential_flag"] == NO_CREDENTIALS:

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

    else:

        server = get_object_or_404(Server, pk=server_id)

        if server.is_ebi_sca():

            image_flag = ''

            if exists_active_collection_for_user(request.user):

                image_flag = 'ALLOW'

            else:

                image_flag = 'DISALLOW'

            experiment_id = get_an_ebi_sca_experiment_id_from_chart_id(
                image_id)

            metadata = server.get_ebi_server_experiment_metadata(experiment_id)

            chart = get_an_ebi_sca_parameters_from_chart_id(
                server.url_server, image_id)

            data.update({
                'image_flag': image_flag,
                'add_from': "show_image",
                'server': server,
                'chart': chart,
                'metadata': metadata,
                'add_from': "show_ebi_sca_image"
            })

            return render(request, 'gallery/show_ebi_sca_image.html', data)

        else:

            return HttpResponseRedirect(reverse('home', args=()))
    def get_context_data(self, **kwargs):

        context = super().get_context_data(**kwargs)

        data = get_header_data(self.request.user)

        data_dict = {'title': self.query_title, 'description': self.query_description, 'created_before': self.query_created_before, 'created_after': self.query_created_after, 'modified_before': self.query_modified_before, 'modified_after': self.query_modified_after, 'owner': self.query_owner, 'authority': self.query_authority, 'paginate_by': self.query_paginate_by  }

        form = MatrixSummarySearchForm(data_dict)

        data.update({ 'form': form,  })

        context.update(data)

        return context
def view_blog_command(request, blog_id):

    data = get_header_data(request.user)

    blog = get_object_or_404(Blog, pk=blog_id)

    if request.user.is_superuser:

        data.update({'blog_id': blog_id, 'blog': blog})

        return render(request, 'maintenance/detail_blog_command.html', data)

    else:

        return HttpResponseRedirect(reverse('home', args=()))
Beispiel #27
0
def view_protocol(request, protocol_id):

    if request.user.is_superuser:

        data = get_header_data(request.user)

        protocol = get_object_or_404(Protocol, pk=protocol_id)

        data.update({'protocol_id': protocol_id, 'protocol': protocol})

        return render(request, 'maintenance/detail_protocol.html', data)

    else:

        return HttpResponseRedirect(reverse('home', args=()))
Beispiel #28
0
def list_bench_bench_authorisation(request, matrix_id):

    data = get_header_data(request.user)

    authorisation_list = Authorisation.objects.filter(matrix__id=matrix_id)

    text_flag = "Permissions for Bench CPW:" + format(int(matrix_id), '06d')

    data.update({
        'matrix_id': matrix_id,
        'text_flag': text_flag,
        'authorisation_list': authorisation_list
    })

    return render(request, 'host/list_bench_authorisation.html', data)
def view_command(request, command_id):

    if request.user.is_superuser:

        data = get_header_data(request.user)

        command = get_object_or_404(Command, pk=command_id)

        data.update({ 'command_id': command_id, 'command': command })

        return render(request, 'maintenance/detail_command.html', data)

    else:

        return HttpResponseRedirect(reverse('home', args=()))
def view_type(request, type_id):

    if request.user.is_superuser:

        data = get_header_data(request.user)

        type = get_object_or_404(Type, pk=type_id)

        data.update({'type_id': type_id, 'type': type})

        return render(request, 'maintenance/detail_type.html', data)

    else:

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