def forwards(apps, schema_editor):
    """Make sure all required class and relations are existing for all
    projects.  We can't use the regular model classes, but have to get
    them through the migration system.
    """
    from catmaid.control.project import validate_project_setup

    Class = apps.get_model('catmaid', 'Class')
    Project = apps.get_model('catmaid', 'Project')
    Relation = apps.get_model('catmaid', 'Relation')
    User = apps.get_model('auth', 'User')
    ClientDatastore = apps.get_model('catmaid', 'ClientDatastore')
    Volume = apps.get_model('catmaid', 'Volume')

    projects = Project.objects.all()
    # If there are no projects, don't continue, because there is nothing to
    # migrate.
    if 0 == len(projects) or 0 == User.objects.count():
        return

    try:
        system_user = get_system_user(User)
        for p in projects:
            validate_project_setup(p.id, system_user.id, True, Class, Relation, ClientDatastore)
    except ImproperlyConfigured as e:
        if Volume.objects.count() > 0:
            logger.warn("Couldn't find a configured system user and will therefore "
                    "skip a configuration update of all existing projects. This is "
                    "okay during the initial setup of a CATMAID database. In this "
                    "case nothing needs to be done. Otherwise, please run "
                    "`manage.py catmaid_update_project_configuration` manually "
                    "after this migration call is finished and rerun this migration.")
            raise e
Esempio n. 2
0
def on_project_save(sender, instance, created, **kwargs):
    """ Make sure all required classes and relations are set up for all
    projects but the ontology dummy projects.
    """
    is_not_dummy = instance.id != settings.ONTOLOGY_DUMMY_PROJECT_ID
    if created and sender == Project and is_not_dummy:
        from catmaid.control.project import validate_project_setup
        from .apps import get_system_user
        user = get_system_user()
        validate_project_setup(instance.id, user.id, True)
Esempio n. 3
0
def on_project_save(sender, instance, created, **kwargs):
    """ Make sure all required classes and relations are set up for all
    projects but the ontology dummy projects.
    """
    is_not_dummy = instance.id != settings.ONTOLOGY_DUMMY_PROJECT_ID
    if created and sender == Project and is_not_dummy:
        from catmaid.control.project import validate_project_setup
        from .apps import get_system_user
        user = get_system_user()
        validate_project_setup(instance.id, user.id, True)
Esempio n. 4
0
def on_project_save(sender, instance, created, raw, **kwargs):
    """ Make sure all required classes and relations are set up for all
    projects but the ontology dummy projects. Don't do this when fixtures are in
    use (i.e. during testing), because project validation is managed there
    explicityly.
    """
    is_not_dummy = instance.id != settings.ONTOLOGY_DUMMY_PROJECT_ID
    if created and sender == Project and is_not_dummy and not raw:
        from catmaid.control.project import validate_project_setup
        from .apps import get_system_user
        user = get_system_user()
        validate_project_setup(instance.id, user.id, True)
    def handle(self, *args, **options):
        if options['user_id'] is None:
            user = get_system_user(User)
        else:
            user = User.objects.get(pk=options['user_id'])

        if options['project_id'] is None:
            projects = Project.objects.all()
        else:
            projects = Project.objects.filter(pk=options['projects_id'])

        for p in projects:
            validate_project_setup(p.id, user.id, True)
Esempio n. 6
0
def validate_projects(app, **kwargs):
    """Make sure all projects have the relations and classes available they
    expect."""
    has_users = User.objects.all().exists()
    has_projects = Project.objects.exclude(
        pk=catmaid_settings.ONTOLOGY_DUMMY_PROJECT_ID).exists()
    if not (has_users and has_projects):
        # In case there is no user and only no project except thei ontology
        # dummy project, don't do the check. Otherwise, getting a system user
        # will fail.
        return

    user = get_system_user()
    for p in Project.objects.all():
        project.validate_project_setup(p.id, user.id)
Esempio n. 7
0
def validate_projects(app, **kwargs):
    """Make sure all projects have the relations and classes available they
    expect."""
    has_users = User.objects.all().exists()
    has_projects = Project.objects.exclude(
        pk=catmaid_settings.ONTOLOGY_DUMMY_PROJECT_ID).exists()
    if not (has_users and has_projects):
        # In case there is no user and only no project except thei ontology
        # dummy project, don't do the check. Otherwise, getting a system user
        # will fail.
        return

    user = get_system_user()
    for p in Project.objects.all():
        project.validate_project_setup(p.id, user.id)
Esempio n. 8
0
def init_consistent_data():
    """Reset sequence counters and make sure all existing projects have all
    needed classes and relations.
    """
    cursor = connection.cursor()
    # Make sure all counters are set correctly
    cursor.execute("""
        SELECT setval('concept_id_seq', coalesce(max("id"), 1), max("id") IS NOT null) FROM concept;
    """)
    cursor.execute("""
        SELECT setval('location_id_seq', coalesce(max("id"), 1), max("id") IS NOT null) FROM location;
    """)

    user = get_system_user()
    for p in Project.objects.all():
        validate_project_setup(p.id, user.id, True)
Esempio n. 9
0
    def handle(self, *args, **options):
        if options['user_id'] is None:
            user = get_system_user(User)
        else:
            user = User.objects.get(pk=options['user_id'])

        if options['project_id'] is None:
            projects = Project.objects.all()
        else:
            projects = Project.objects.filter(pk=options['projects_id'])

        for p in projects:
            try:
                validate_project_setup(p.id, user.id, True)
                logger.info("Validated project {} (ID: {})".format(p, p.id))
            except Exception as e:
                logger.error("Could not validate project setup of project " +
                             "{} (ID: {}): {}".format(p, p.id, e))
    def handle(self, *args, **options):
        if options['user_id'] is None:
            user = get_system_user(User)
        else:
            user = User.objects.get(pk=options['user_id'])

        if options['project_id'] is None:
            projects = Project.objects.all()
        else:
            projects = Project.objects.filter(pk=options['projects_id'])

        for p in projects:
            try:
                validate_project_setup(p.id, user.id, True)
                logger.info("Validated project {} (ID: {})".format(p, p.id))
            except Exception as e:
                logger.error("Could not validate project setup of project " +
                        "{} (ID: {}): {}".format(p, p.id, e))
Esempio n. 11
0
    def handle(self, *args, **options):
        set_log_level(logger, options.get('verbosity', 1))
        if options['user_id'] is None:
            user = get_system_user(User)
        else:
            user = User.objects.get(pk=options['user_id'])

        if options['project_id'] is None:
            projects = Project.objects.all()
        else:
            projects = Project.objects.filter(pk=options['projects_id'])

        for p in projects:
            try:
                validate_project_setup(p.id, user.id, True)
                logger.info(f"Validated project {p} (ID: {p.id})")
            except Exception as e:
                logger.error("Could not validate project setup of project " + \
                             f"{p} (ID: {p.id}): {e}")
Esempio n. 12
0
    def validate_projects(self):
        """Make sure all projects have the relations and classes available they
        expect."""
        from catmaid.control.project import validate_project_setup
        User = auth.get_user_model()
        Project = self.get_model("Project")
        has_users = User.objects.all().exists()
        has_projects = Project.objects.exclude(
            pk=settings.ONTOLOGY_DUMMY_PROJECT_ID).exists()
        if not (has_users and has_projects):
            # In case there is no user and only no project except thei ontology
            # dummy project, don't do the check. Otherwise, getting a system user
            # will fail.
            return

        Class = self.get_model("Class")
        Relation = self.get_model("Relation")
        user = get_system_user(User)
        for p in Project.objects.all():
            validate_project_setup(p.id, user.id, True, Class, Relation)
Esempio n. 13
0
    def validate_projects(self):
        """Make sure all projects have the relations and classes available they
        expect."""
        from catmaid.control.project import validate_project_setup
        User = auth.get_user_model()
        Project = self.get_model("Project")
        has_users = User.objects.all().exists()
        has_projects = Project.objects.exclude(
            pk=settings.ONTOLOGY_DUMMY_PROJECT_ID).exists()
        if not (has_users and has_projects):
            # In case there is no user and only no project except thei ontology
            # dummy project, don't do the check. Otherwise, getting a system user
            # will fail.
            return

        Class = self.get_model("Class")
        Relation = self.get_model("Relation")
        user = get_system_user(User)
        for p in Project.objects.all():
            validate_project_setup(p.id, user.id, True, Class, Relation)
def forwards(apps, schema_editor):
    """Make sure all required class and relations are existing for all
    projects.  We can't use the regular model classes, but have to get
    them through the migration system.
    """
    from catmaid.control.project import validate_project_setup

    Class = apps.get_model('catmaid', 'Class')
    Project = apps.get_model('catmaid', 'Project')
    Relation = apps.get_model('catmaid', 'Relation')
    User = apps.get_model('auth', 'User')

    projects = Project.objects.all()
    # If there are no projects, don't continue, because there is nothing to
    # migrate.
    if 0 == len(projects) or 0 == User.objects.count():
        return

    system_user = get_system_user(User)
    for p in projects:
        validate_project_setup(p.id, system_user.id, True, Class, Relation)
Esempio n. 15
0
def forwards(apps, schema_editor):
    """Make sure all required class and relations are existing for all
    projects.  We can't use the regular model classes, but have to get
    them through the migration system.
    """
    from catmaid.control.project import validate_project_setup

    Class = apps.get_model('catmaid', 'Class')
    Project = apps.get_model('catmaid', 'Project')
    Relation = apps.get_model('catmaid', 'Relation')
    User = apps.get_model('auth', 'User')

    projects = Project.objects.all()
    # If there are no projects, don't continue, because there is nothing to
    # migrate.
    if 0 == len(projects) or 0 == User.objects.count():
        return

    system_user = get_system_user(User)
    for p in projects:
        validate_project_setup(p.id, system_user.id, True, Class, Relation)
Esempio n. 16
0
def forwards(apps, schema_editor):
    """Make sure all required class and relations are existing for all
    projects.  We can't use the regular model classes, but have to get
    them through the migration system.
    """
    from catmaid.control.project import validate_project_setup

    Class = apps.get_model('catmaid', 'Class')
    Project = apps.get_model('catmaid', 'Project')
    Relation = apps.get_model('catmaid', 'Relation')
    User = apps.get_model('auth', 'User')
    ClientDatastore = apps.get_model('catmaid', 'ClientDatastore')
    Volume = apps.get_model('catmaid', 'Volume')

    projects = Project.objects.all()
    # If there are no projects, don't continue, because there is nothing to
    # migrate.
    if 0 == len(projects) or 0 == User.objects.count():
        return

    try:
        system_user = get_system_user(User)
        for p in projects:
            validate_project_setup(p.id, system_user.id, True, Class, Relation,
                                   ClientDatastore)
    except ImproperlyConfigured as e:
        if Volume.objects.count() > 0:
            logger.warn(
                "Couldn't find a configured system user and will therefore "
                "skip a configuration update of all existing projects. This is "
                "okay during the initial setup of a CATMAID database. In this "
                "case nothing needs to be done. Otherwise, please run "
                "`manage.py catmaid_update_project_configuration` manually "
                "after this migration call is finished and rerun this migration."
            )
            raise e