Beispiel #1
0
    def done(self, form_list, **kwargs):
        dvid_server = self.get_cleaned_data_for_step('server')['server']
        dvid_repo = self.get_cleaned_data_for_step('stack')['repository']
        dvid_instance = self.get_cleaned_data_for_step('stack')['instance']
        title = self.get_cleaned_data_for_step('confirm')['title']
        comment = self.get_cleaned_data_for_step('confirm')['comment']
        description = self.get_cleaned_data_for_step('confirm')['description']
        dc = dvid.DVIDClient(dvid_server)
        stack_data = dc.get_instance_properties(dvid_repo, dvid_instance)
        dimension = (stack_data['dimension']['x'],
                     stack_data['dimension']['y'],
                     stack_data['dimension']['z'])
        resolution = (stack_data['resolution']['x'],
                      stack_data['resolution']['y'],
                      stack_data['resolution']['z'])

        ortho_stacks = self.get_cleaned_data_for_step(
            'confirm')['ortho_stacks']
        new_project = self.get_cleaned_data_for_step('confirm')['new_project']

        # Create DVID stacks and return to admin home
        views = ((0, 'XY'), (1, 'XZ'), (2, 'ZY'))
        new_stacks = []
        for view, label in views:
            suffix = ' ' + label if ortho_stacks else ''
            stack = Stack(title=title + suffix,
                          comment=comment,
                          dimension=dimension,
                          resolution=resolution,
                          num_zoom_levels=stack_data['zoom_levels'],
                          description=description)
            stack.save()
            mirror = StackMirror.objects.create(
                stack=stack,
                image_base=stack_data['image_base'],
                file_extension=stack_data['file_extension'],
                tile_width=stack_data['tile_width'],
                tile_height=stack_data['tile_height'],
                tile_source_type=stack_data['tile_source_type'])
            new_stacks.append((view, stack))

        if new_project:
            project = Project(title=title, comment=None)
            project.save()
            # Create three links, each with a different orientation, if an
            # ortho project should be created. Link only one XY view otherwise.
            views = (0, 1, 2) if ortho_stacks else (0, )
            for view, stack in new_stacks:
                ps = ProjectStack(project=project,
                                  stack=stack,
                                  orientation=view)
                ps.save()

            # Create a stack group if there are more than one views
            if len(views) > 1:
                view_relation = StackGroupRelation.objects.get(name='view')
                sg = StackGroup.objects.create(title=project.title)

                for view, stack in new_stacks:
                    StackStackGroup.objects.create(
                        group_relation=view_relation,
                        stack=stack,
                        stack_group=sg,
                        position=view)

        if new_project:
            if ortho_stacks:
                msg = ('Three new DVID based stacks have been created and '
                       'linked to a projcet named "%s" with orientations XY, '
                       'XZ and ZY' % title)
            else:
                msg = ('A new DVID based stack was successfully created and '
                       'linked to a new project named "%s".' % title)
        else:
            msg = 'A new DVID based stack was successfully created.'

        messages.add_message(self.request, messages.SUCCESS, msg)
        return redirect('admin:index')
Beispiel #2
0
    def done(self, form_list, **kwargs):
        dvid_server = self.get_cleaned_data_for_step('server')['server']
        dvid_repo = self.get_cleaned_data_for_step('stack')['repository']
        dvid_instance = self.get_cleaned_data_for_step('stack')['instance']
        title = self.get_cleaned_data_for_step('confirm')['title']
        comment = self.get_cleaned_data_for_step('confirm')['comment']
        metadata = self.get_cleaned_data_for_step('confirm')['metadata']
        dc = dvid.DVIDClient(dvid_server)
        stack_data = dc.get_instance_properties(dvid_repo, dvid_instance)
        dimension = (stack_data['dimension']['x'], stack_data['dimension']['y'],
                     stack_data['dimension']['z'])
        resolution = (stack_data['resolution']['x'], stack_data['resolution']['y'],
                     stack_data['resolution']['z'])

        ortho_stacks = self.get_cleaned_data_for_step('confirm')['ortho_stacks']
        new_project = self.get_cleaned_data_for_step('confirm')['new_project']

        # Create DVID stacks and return to admin home
        views = (
            (0, 'XY'),
            (1, 'XZ'),
            (2, 'ZY'))
        new_stacks = []
        for view, label in views:
            suffix = ' ' + label if ortho_stacks else ''
            stack = Stack(
                title=title + suffix,
                comment=comment,
                dimension=dimension,
                resolution=resolution,
                image_base=stack_data['image_base'],
                trakem2_project=False,
                num_zoom_levels=stack_data['zoom_levels'],
                file_extension=stack_data['file_extension'],
                tile_width=stack_data['tile_width'],
                tile_height=stack_data['tile_height'],
                tile_source_type=stack_data['tile_source_type'],
                metadata=metadata)
            stack.save()
            new_stacks.append((view, stack))

        if new_project:
            project = Project(title=title, comment=None)
            project.save()
            # Create three links, each with a different orientation, if an
            # ortho project should be created. Link only one XY view otherwise.
            views = (0, 1, 2) if ortho_stacks else (0,)
            for view, stack in new_stacks:
                ps = ProjectStack(project=project,
                                  stack=stack,
                                  orientation=view)
                ps.save()

            # Create a stack group if there are more than one views
            if len(views) > 1:
                has_view = Relation.objects.get(project=project,
                                                relation_name='has_view')
                stack_group = Class.objects.get(project=project,
                                                class_name='stackgroup')
                sg = ClassInstance.objects.create(
                    user=self.request.user,
                    project=project,
                    class_column=stack_group,
                    name=project.title)

                for view, stack in new_stacks:
                    StackClassInstance.objects.create(
                        user=self.request.user,
                        project=project,
                        relation=has_view,
                        stack=stack,
                        class_instance=sg)

        if new_project:
            if ortho_stacks:
                msg = ('Three new DVID based stacks have been created and '
                      'linked to a projcet named "%s" with orientations XY, '
                      'XZ and ZY' % title)
            else:
                msg = ('A new DVID based stack was successfully created and '
                      'linked to a new project named "%s".' % title)
        else:
            msg = 'A new DVID based stack was successfully created.'

        messages.add_message(self.request, messages.SUCCESS, msg)
        return HttpResponseRedirect('/admin/')
 def insert_project(self):
     p = Project()
     p.title = "Example Project"
     p.comment = "This is an example project for the Django tests"
     p.save()
     return p
Beispiel #4
0
    def done(self, form_list, **kwargs):
        dvid_server = self.get_cleaned_data_for_step('server')['server']
        dvid_repo = self.get_cleaned_data_for_step('stack')['repository']
        dvid_instance = self.get_cleaned_data_for_step('stack')['instance']
        title = self.get_cleaned_data_for_step('confirm')['title']
        comment = self.get_cleaned_data_for_step('confirm')['comment']
        description = self.get_cleaned_data_for_step('confirm')['description']
        dc = dvid.DVIDClient(dvid_server)
        stack_data = dc.get_instance_properties(dvid_repo, dvid_instance)
        dimension = (stack_data['dimension']['x'], stack_data['dimension']['y'],
                     stack_data['dimension']['z'])
        resolution = (stack_data['resolution']['x'], stack_data['resolution']['y'],
                     stack_data['resolution']['z'])
        downsample_factors = DownsampleFactorsField.planar_default(stack_data['num_zoom_levels'])

        ortho_stacks = self.get_cleaned_data_for_step('confirm')['ortho_stacks']
        new_project = self.get_cleaned_data_for_step('confirm')['new_project']

        # Create DVID stacks and return to admin home
        views = (
            (0, 'XY'),
            (1, 'XZ'),
            (2, 'ZY'))
        new_stacks = []
        for view, label in views:
            suffix = ' ' + label if ortho_stacks else ''
            stack = Stack(
                title=title + suffix,
                comment=comment,
                dimension=dimension,
                resolution=resolution,
                downsample_factors=downsample_factors,
                description=description)
            stack.save()
            mirror = StackMirror.objects.create(
                stack=stack,
                image_base=stack_data['image_base'],
                file_extension=stack_data['file_extension'],
                tile_width=stack_data['tile_width'],
                tile_height=stack_data['tile_height'],
                tile_source_type=stack_data['tile_source_type'])
            new_stacks.append((view, stack))

        if new_project:
            project = Project(title=title, comment=None)
            project.save()
            # Create three links, each with a different orientation, if an
            # ortho project should be created. Link only one XY view otherwise.
            views = (0, 1, 2) if ortho_stacks else (0,)
            for view, stack in new_stacks:
                ps = ProjectStack(project=project,
                                  stack=stack,
                                  orientation=view)
                ps.save()

            # Create a stack group if there are more than one views
            if len(views) > 1:
                view_relation = StackGroupRelation.objects.get(name='view')
                sg = StackGroup.objects.create(title=project.title)

                for view, stack in new_stacks:
                    StackStackGroup.objects.create(
                        group_relation=view_relation,
                        stack=stack,
                        stack_group=sg,
                        position=view)

        if new_project:
            if ortho_stacks:
                msg = ('Three new DVID based stacks have been created and '
                      'linked to a projcet named "%s" with orientations XY, '
                      'XZ and ZY' % title)
            else:
                msg = ('A new DVID based stack was successfully created and '
                      'linked to a new project named "%s".' % title)
        else:
            msg = 'A new DVID based stack was successfully created.'

        messages.add_message(self.request, messages.SUCCESS, msg)
        return redirect('admin:index')
Beispiel #5
0
 def insert_project(self):
     p = Project()
     p.title = "Example Project"
     p.comment = "This is an example project for the Django tests"
     p.save()
     return p