示例#1
0
    def _populate_session(self):

        with self._service.transaction_scope() as session:

            user = User()
            user.username = "******"
            user.name = "Test User"
            user.email = "*****@*****.**"
            user.access_level = "CEH"

            session.add(user)

            pointDst = DatasetType()
            pointDst.type = "Point"

            coverDst = DatasetType()
            coverDst.type = "Coverage"

            resultDst = DatasetType()
            resultDst.type = "Result"

            session.add(pointDst)
            session.add(coverDst)
            session.add(resultDst)

            dataset_a = Dataset()
            dataset_a.dataset_type = pointDst
            dataset_a.viewable_by_user_id = self._user_id
            dataset_a.name = "Dataset1"

            session.add(dataset_a)

            dataset_b = Dataset()
            dataset_b.dataset_type = pointDst
            dataset_b.name = "Dataset2"

            session.add(dataset_b)

            dataset_c = Dataset()
            dataset_c.dataset_type = pointDst
            dataset_c.viewable_by_user_id = self._another_user_id
            dataset_c.name = "Dataset3"

            session.add(dataset_c)

            dataset_d = Dataset()
            dataset_d.dataset_type = resultDst
            dataset_d.name = "Results Dataset 1"
            dataset_d.viewable_by_user_id = 1

            session.add(dataset_d)

            analysis_a = Analysis()
            analysis_a.point_dataset = dataset_a
            analysis_a.coverage_datasets.append(AnalysisCoverageDataset(dataset_b))
            analysis_a.viewable_by = self._user_id
            analysis_a.result_dataset = dataset_d
            analysis_a.deleted = False

            analysis_b = Analysis()
            analysis_b.point_dataset = dataset_a
            analysis_b.coverage_datasets.append(AnalysisCoverageDataset(dataset_b))
            analysis_b.run_by = self._user_id
            analysis_b.result_dataset = dataset_d
            analysis_b.deleted = False

            analysis_c = Analysis()
            analysis_c.point_dataset = dataset_a
            analysis_c.coverage_datasets.append(AnalysisCoverageDataset(dataset_b))
            analysis_c.viewable_by = self._another_user_id
            analysis_c.result_dataset = dataset_d
            analysis_c.deleted = False

            session.add(analysis_a)
            session.add(analysis_b)
            session.add(analysis_c)
示例#2
0
def setup_app(command, conf, vars):
    """Place any commands to setup ecomaps here - currently creating db tables"""

    # Don't reload the app if it was loaded under the testing environment
    if not pylons.test.pylonsapp:
        load_environment(conf.global_conf, conf.local_conf)

    # Create the tables if they don't already exist
    Base.metadata.drop_all(bind=Session.bind)
    Base.metadata.create_all(bind=Session.bind)

    with session_scope(Session) as session:

        user = User()
        user.name = "Phil Jenkins"
        user.first_name = "Phil"
        user.last_name = "Jenkins"
        user.username = "******"
        user.email = "*****@*****.**"
        user.access_level = "Admin"

        session.add(user)

        user2 = User()
        user2.name = "Mike Wilson"
        user2.first_name = "Mike"
        user2.last_name = "Wilson"
        user2.username = "******"
        user2.email = "*****@*****.**"
        user2.access_level = "Admin"

        session.add(user2)

        # Model that provides the interface to the R code
        model = Model()
        model.name = "LCM Thredds Model"
        model.id = 1
        model.description = "LCM Thredds model written in R"
        model.code_path = "code_root"

        session.add(model)

        pointDst = DatasetType()
        pointDst.type = "Point"

        coverDst = DatasetType()
        coverDst.type = "Coverage"

        resultDst = DatasetType()
        resultDst.type = "Result"

        session.add(pointDst)
        session.add(coverDst)
        session.add(resultDst)

        # Define a datasetType lookup. This will conver the possible thredds
        # datasets into their EcoMaps equivalents.
        datasetTypes = {"GRID": coverDst, "POINT": pointDst}

        # Populate from thredds
        registerThreddsDatasets("http://thredds.ceh.ac.uk/thredds/ecomaps.xml", datasetTypes, session)