# Path: boardinghouse/exceptions.py
# class SchemaRequiredException(Exception):
#     """
#     An exception raised when an operation requires a schema to be active
#     or supplied, but none was provided.
#     """
# 
# Path: boardinghouse/schema.py
# def activate_schema(schema_name):
#     """
#     Activate the current schema: this will execute, in the database
#     connection, something like:
# 
#     .. code:: sql
# 
#         SET search_path TO "foo",public;
# 
#     It sends signals before and after that the schema will be, and was
#     activated.
# 
#     Must be passed a string: the internal name of the schema to activate.
#     """
#     from .signals import schema_pre_activate, schema_post_activate
# 
#     if schema_name == settings.TEMPLATE_SCHEMA:
#         raise TemplateSchemaActivation()
# 
#     schema_pre_activate.send(sender=None, schema_name=schema_name)
#     _set_search_path(schema_name)
#     found_schema = _get_search_path()
#     if found_schema != schema_name:
#         raise SchemaNotFound('Schema activation failed. Expected "{0}", saw "{1}"'.format(
#             schema_name, found_schema,
#         ))
#     schema_post_activate.send(sender=None, schema_name=schema_name)
#     _thread_locals.schema = schema_name
# 
# def deactivate_schema(schema=None):
#     """
#     Deactivate the provided (or current) schema.
#     """
#     from .signals import schema_pre_activate, schema_post_activate
# 
#     cursor = connection.cursor()
#     schema_pre_activate.send(sender=None, schema_name=None)
#     cursor.execute('SET search_path TO "$user",{0}'.format(settings.PUBLIC_SCHEMA))
#     schema_post_activate.send(sender=None, schema_name=None)
#     _thread_locals.schema = None
#     cursor.close()
# 
# def is_shared_model(model):
#     """
#     Is the model (or instance of a model) one that should be in the
#     public/shared schema?
#     """
#     if model._is_shared_model:
#         return True
# 
#     app_model = '{m.app_label}.{m.model_name}'.format(m=model._meta).lower()
# 
#     # These should be case insensitive!
#     if app_model in REQUIRED_SHARED_MODELS:
#         return True
# 
#     if app_model in [x.lower() for x in settings.SHARED_MODELS]:
#         return True
# 
#     # Sometimes, we want a join table to be private.
#     if app_model in [x.lower() for x in settings.PRIVATE_MODELS]:
#         return False
# 
#     # if all fields are auto or fk, then we are a join model,
#     # and if all related objects are shared, then we must
#     # also be shared, unless we were explicitly marked as private
#     # above.
#     if _is_join_model(model):
#         return all(
#             is_shared_model(field.remote_field.model)
#             for field in model._meta.fields
#             if field.remote_field
#         )
# 
#     return False


from django.apps import apps
from django.core.management.commands import dumpdata
from ...exceptions import SchemaRequiredException
from ...schema import (
    activate_schema,
    deactivate_schema,
    is_shared_model,
)
schema will be used (which will not contain any data).

If any models are supplied as arguments (using the ``app_label.model_name``
notation) that are not shared models, it is an error to fail to pass a schema.
"""




class Command(dumpdata.Command):
    def add_arguments(self, parser):
        super(Command, self).add_arguments(parser)
        parser.add_argument(
            '--schema', action='store', dest='schema',
            help='Specify which schema to dump schema-aware models from')

    def handle(self, *app_labels, **options):
        schema_name = options.get('schema')

        # If we have have any explicit models that are aware, then we should
        # raise an exception if we weren't handed a schema.
        schema_required = []
        for label in app_labels:
            if '.' in label:
                model = apps.get_model(label)
                if not is_shared_model(model):
                    schema_required.append(model)
            else:
                schema_required.extend([
                    model for model in apps.get_app_config(label).get_models()

# Path: boardinghouse/exceptions.py
# class SchemaRequiredException(Exception):
#     """
#     An exception raised when an operation requires a schema to be active
#     or supplied, but none was provided.
#     """
# 
# Path: boardinghouse/schema.py
# def activate_schema(schema_name):
#     """
#     Activate the current schema: this will execute, in the database
#     connection, something like:
# 
#     .. code:: sql
# 
#         SET search_path TO "foo",public;
# 
#     It sends signals before and after that the schema will be, and was
#     activated.
# 
#     Must be passed a string: the internal name of the schema to activate.
#     """
#     from .signals import schema_pre_activate, schema_post_activate
# 
#     if schema_name == settings.TEMPLATE_SCHEMA:
#         raise TemplateSchemaActivation()
# 
#     schema_pre_activate.send(sender=None, schema_name=schema_name)
#     _set_search_path(schema_name)
#     found_schema = _get_search_path()
#     if found_schema != schema_name:
#         raise SchemaNotFound('Schema activation failed. Expected "{0}", saw "{1}"'.format(
#             schema_name, found_schema,
#         ))
#     schema_post_activate.send(sender=None, schema_name=schema_name)
#     _thread_locals.schema = schema_name
# 
# def deactivate_schema(schema=None):
#     """
#     Deactivate the provided (or current) schema.
#     """
#     from .signals import schema_pre_activate, schema_post_activate
# 
#     cursor = connection.cursor()
#     schema_pre_activate.send(sender=None, schema_name=None)
#     cursor.execute('SET search_path TO "$user",{0}'.format(settings.PUBLIC_SCHEMA))
#     schema_post_activate.send(sender=None, schema_name=None)
#     _thread_locals.schema = None
#     cursor.close()
# 
# def is_shared_model(model):
#     """
#     Is the model (or instance of a model) one that should be in the
#     public/shared schema?
#     """
#     if model._is_shared_model:
#         return True
# 
#     app_model = '{m.app_label}.{m.model_name}'.format(m=model._meta).lower()
# 
#     # These should be case insensitive!
#     if app_model in REQUIRED_SHARED_MODELS:
#         return True
# 
#     if app_model in [x.lower() for x in settings.SHARED_MODELS]:
#         return True
# 
#     # Sometimes, we want a join table to be private.
#     if app_model in [x.lower() for x in settings.PRIVATE_MODELS]:
#         return False
# 
#     # if all fields are auto or fk, then we are a join model,
#     # and if all related objects are shared, then we must
#     # also be shared, unless we were explicitly marked as private
#     # above.
#     if _is_join_model(model):
#         return all(
#             is_shared_model(field.remote_field.model)
#             for field in model._meta.fields
#             if field.remote_field
#         )
# 
#     return False


# Path: boardinghouse/management/commands/dumpdata.py
from django.apps import apps
from django.core.management.commands import dumpdata
from ...exceptions import SchemaRequiredException
from ...schema import (
    activate_schema,
    deactivate_schema,
    is_shared_model,
)

schema will be used (which will not contain any data).

If any models are supplied as arguments (using the ``app_label.model_name``
notation) that are not shared models, it is an error to fail to pass a schema.
"""




class Command(dumpdata.Command):
    def add_arguments(self, parser):
        super(Command, self).add_arguments(parser)
        parser.add_argument(
            '--schema', action='store', dest='schema',
            help='Specify which schema to dump schema-aware models from')

    def handle(self, *app_labels, **options):
        schema_name = options.get('schema')

        # If we have have any explicit models that are aware, then we should
        # raise an exception if we weren't handed a schema.
        schema_required = []
        for label in app_labels:
            if '.' in label:
                model = apps.get_model(label)
                if not is_shared_model(model):
                    schema_required.append(model)
            else:
                schema_required.extend([
                    model for model in apps.get_app_config(label).get_models()

                    if not is_shared_model(model)