Пример #1
0
def table(species_list):
    dataset_id = int(config.get_config_value('CONSULTATION_DATASET', '1'))

    prefilter_query = (models.db.session.query(
        models.DataSpecies.id,
        models.LuHdSpecies.speciesname,
    ).join(models.DataSpecies.lu))
    species_id_list = []
    for species_id, name in prefilter_query:
        if name in species_names[species_list]['data']:
            species_id_list.append(species_id)

    species_query = (models.db.session.query(
        models.LuHdSpecies.speciesname,
        models.DataSpeciesRegion,
    ).join(models.DataSpeciesRegion.species).join(
        models.DataSpecies.lu).filter(
            models.DataSpeciesRegion.cons_dataset_id == dataset_id).filter(
                models.DataSpeciesRegion.cons_role == 'assessment').filter(
                    models.DataSpecies.id.in_(species_id_list)).order_by(
                        models.LuHdSpecies.speciesname,
                        models.DataSpeciesRegion.region,
                    ))

    return flask.render_template(
        'reportviews_table.html', **{
            'title':
            species_names[species_list]['title'],
            'species_list': [(name, schemas.parse_species(record))
                             for name, record in species_query],
        })
Пример #2
0
def table(species_list):
    dataset_id = int(config.get_config_value('CONSULTATION_DATASET', '1'))

    prefilter_query = (
        models.db.session.query(
            models.DataSpecies.id,
            models.LuHdSpecies.speciesname,
        )
        .join(models.DataSpecies.lu)
    )
    species_id_list = []
    for species_id, name in prefilter_query:
        if name in species_names[species_list]['data']:
            species_id_list.append(species_id)

    species_query = (
        models.db.session.query(
            models.LuHdSpecies.speciesname,
            models.DataSpeciesRegion,
        )
        .join(models.DataSpeciesRegion.species)
        .join(models.DataSpecies.lu)
        .filter(models.DataSpeciesRegion.cons_dataset_id == dataset_id)
        .filter(models.DataSpeciesRegion.cons_role == 'assessment')
        .filter(models.DataSpecies.id.in_(species_id_list))
        .order_by(
            models.LuHdSpecies.speciesname,
            models.DataSpeciesRegion.region,
        )
    )

    return flask.render_template('reportviews_table.html', **{
        'title': species_names[species_list]['title'],
        'species_list': [
            (name, schemas.parse_species(record))
            for name, record in species_query
        ],
    })
Пример #3
0
def get_current_dataset():
    from art17 import config
    dataset_id = config.get_config_value('CONSULTATION_DATASET')
    return Dataset.query.get(dataset_id) or None
Пример #4
0
 def primary_data_url_template(self):
     return config.get_config_value('HABITAT_PRIMARY_DATA_URL')
Пример #5
0
 def map_url_template(self):
     return config.get_config_value('HABITAT_MAP_URL')
Пример #6
0
def get_dal(dataset_id=None):
    dataset_id = dataset_id or config.get_config_value('CONSULTATION_DATASET')
    if not dataset_id:
        return None
    return dal.HabitatDal(int(dataset_id))
Пример #7
0
def index(dataset_id=None):
    if dataset_id:
        # Aggregation
        base_url = flask.url_for('.index', dataset_id=dataset_id)
        item_url = get_history_aggregation_record_url
        history_items = (models.History.query.filter_by(
            dataset_id=dataset_id).filter(
                models.History.table.startswith('data_habitattype_regions')
                | models.History.table.startswith('data_species_regions')).
                         order_by(models.History.date.desc()))
        TRANS = ACTIONS_TRANSLATION_AGG
    else:
        # Consultation
        base_url = flask.url_for('.index')
        item_url = get_history_object_url
        dataset_id = config.get_config_value('CONSULTATION_DATASET', '1')
        history_items = (models.History.query.filter_by(
            dataset_id=dataset_id).order_by(models.History.date.desc()))
        TRANS = ACTIONS_TRANSLATION
    page = int(flask.request.args.get('page', 1))
    start_date = flask.request.args.get('start_date', '')
    end_date = flask.request.args.get('end_date', '')
    user_id = flask.request.args.get('user_id', '')

    form = ActivityFilterForm(start_date=start_date,
                              end_date=end_date,
                              user_id=user_id)
    form.set_user_choices(dataset_id)

    if start_date:
        start_date = datetime.strptime(start_date, DATE_FORMAT_HISTORY)
        history_items = history_items.filter(models.History.date >= start_date)
    if end_date:
        end_date = datetime.strptime(end_date, DATE_FORMAT_HISTORY)
        history_items = history_items.filter(models.History.date <= end_date)
    if user_id:
        history_items = history_items.filter_by(user_id=user_id)

    count = history_items.count()
    history_items = history_items.paginate(page, PER_PAGE, False).items
    paginator = Paginator(per_page=PER_PAGE, page=page, count=count)

    for item in history_items:
        result = item_url(item)
        if result:
            item.url, title, region = result
            item.title = u'{0} - {1}'.format(title, region)
        else:
            item.url = result
        item.action = TRANS.get((item.table.strip(), item.action), item.action)

    get_params = flask.request.args.to_dict()
    get_params.pop('page', None)
    query_string = urllib.urlencode(get_params)

    return flask.render_template(
        'history/index.html', **{
            'history_items': history_items,
            'dataset_id': dataset_id,
            'paginator': paginator,
            'base_url': base_url,
            'query_string': query_string,
            'form': form,
        })
Пример #8
0
def index(dataset_id=None):
    if dataset_id:
        # Aggregation
        base_url = flask.url_for('.index', dataset_id=dataset_id)
        item_url = get_history_aggregation_record_url
        history_items = (
            models.History.query
            .filter_by(dataset_id=dataset_id)
            .filter(
                models.History.table.startswith('data_habitattype_regions') |
                models.History.table.startswith('data_species_regions')
            )
            .order_by(models.History.date.desc())
        )
        TRANS = ACTIONS_TRANSLATION_AGG
    else:
        # Consultation
        base_url = flask.url_for('.index')
        item_url = get_history_object_url
        dataset_id = config.get_config_value('CONSULTATION_DATASET', '1')
        history_items = (
            models.History.query
            .filter_by(dataset_id=dataset_id)
            .order_by(models.History.date.desc())
        )
        TRANS = ACTIONS_TRANSLATION
    page = int(flask.request.args.get('page', 1))
    start_date = flask.request.args.get('start_date', '')
    end_date = flask.request.args.get('end_date', '')
    user_id = flask.request.args.get('user_id', '')

    form = ActivityFilterForm(start_date=start_date, end_date=end_date,
                              user_id=user_id)
    form.set_user_choices(dataset_id)

    if start_date:
        start_date = datetime.strptime(start_date, DATE_FORMAT_HISTORY)
        history_items = history_items.filter(models.History.date >= start_date)
    if end_date:
        end_date = datetime.strptime(end_date, DATE_FORMAT_HISTORY)
        history_items = history_items.filter(models.History.date <= end_date)
    if user_id:
        history_items = history_items.filter_by(user_id=user_id)

    count = history_items.count()
    history_items = history_items.paginate(page, PER_PAGE, False).items
    paginator = Paginator(per_page=PER_PAGE, page=page, count=count)

    for item in history_items:
        result = item_url(item)
        if result:
            item.url, title, region = result
            item.title = u'{0} - {1}'.format(title, region)
        else:
            item.url = result
        item.action = TRANS.get(
            (item.table.strip(), item.action), item.action)


    get_params = flask.request.args.to_dict()
    get_params.pop('page', None)
    query_string = urllib.urlencode(get_params)

    return flask.render_template('history/index.html', **{
        'history_items': history_items,
        'dataset_id': dataset_id,
        'paginator': paginator,
        'base_url': base_url,
        'query_string': query_string,
        'form': form,
    })
Пример #9
0
 def map_url_template(self):
     return config.get_config_value('SPECIES_MAP_URL')
Пример #10
0
 def primary_data_url_template(self):
     return config.get_config_value('SPECIES_PRIMARY_DATA_URL')
Пример #11
0
 def map_url_template(self):
     return config.get_config_value('SPECIES_MAP_URL')
Пример #12
0
def get_dal(dataset_id=None):
    dataset_id = dataset_id or config.get_config_value('CONSULTATION_DATASET')
    if not dataset_id:
        return None
    return dal.SpeciesDal(int(dataset_id))
Пример #13
0
 def map_url_template(self):
     return config.get_config_value('HABITAT_MAP_URL')
Пример #14
0
def get_current_dataset():
    from art17 import config
    dataset_id = config.get_config_value('CONSULTATION_DATASET')
    return Dataset.query.get(dataset_id) or None