コード例 #1
0
def observed_list_info():
    """View observed list."""
    add_form = AddToObservedListForm()
    search_form = SearchObservedForm()

    ret, page = process_paginated_session_search('observed_search_page', [
        ('observed_search', search_form.q),
        ('items_per_page', search_form.items_per_page)
    ])

    per_page = get_items_per_page(search_form.items_per_page)

    if not ret:
        return redirect(url_for('main_observed.observed_list_info'))

    observed_list = ObservedList.create_get_observed_list_by_user_id(current_user.id)
    observed_list_items = observed_list.observed_list_items

    page_offset = (page - 1) * per_page

    if page_offset < len(observed_list_items):
        page_items = observed_list_items[page_offset:page_offset + per_page]
    else:
        page_items = []

    pagination = Pagination(page=page, per_page=per_page, total=len(observed_list.observed_list_items), search=False, record_name='observed',
                            css_framework='semantic', not_passed_args='back')

    return render_template('main/observation/observed_list.html', observed_list=observed_list, type='info', add_form=add_form,
                           search_form=search_form, observed_list_items=enumerate(page_items), page_offset=page_offset, pagination=pagination)
コード例 #2
0
ファイル: skyquality_views.py プロジェクト: skybber/czsky
def skyquality_locations():
    search_form = SearchForm()

    page = request.args.get(get_page_parameter(), type=int, default=1)
    per_page = get_items_per_page(search_form.items_per_page)
    offset = (page - 1) * per_page

    locations = Location.query.filter(Location.is_for_observation == True)
    search = False
    if search_form.q.data:
        locations = locations.filter(
            Location.name.like('%' + search_form.q.data + '%'))
        search = True

    locations_for_render = locations.limit(per_page).offset(offset).all()

    pagination = Pagination(page=page,
                            per_page=per_page,
                            total=locations.count(),
                            search=search,
                            record_name='locations',
                            css_framework='semantic')
    return render_template('main/skyquality/skyquality_locations.html',
                           locations=locations_for_render,
                           pagination=pagination,
                           search_form=search_form)
コード例 #3
0
def news_list():
    search_form = SearchNewsForm()

    ret, page = process_paginated_session_search('news_search_page', [
        ('news_search', search_form.q),
    ])

    per_page = get_items_per_page(search_form.items_per_page)

    if not ret:
        return redirect(url_for('main_news.news_list'))

    offset = (page - 1) * per_page

    news = News.query.filter(News.lang_code == get_site_lang_code())
    if search_form.q.data:
        news = news.filter(News.name.like('%' + search_form.q.data + '%'))
    news_for_render = news.order_by(
        News.id.desc()).limit(per_page).offset(offset).all()

    pagination = Pagination(page=page,
                            per_page=per_page,
                            total=news.count(),
                            search=False,
                            record_name='news',
                            css_framework='semantic',
                            not_passed_args='back')

    return render_template('main/news/news_list.html',
                           news=news_for_render,
                           pagination=pagination,
                           search_form=search_form)
コード例 #4
0
ファイル: comet_views.py プロジェクト: skybber/czsky
def comets():
    """View comets."""
    search_form = SearchCometForm()

    ret, page = process_paginated_session_search('comet_search_page', [
        ('comet_search', search_form.q),
    ])

    per_page = get_items_per_page(search_form.items_per_page)

    if not ret:
        return redirect(url_for('main_comet.comets'))

    offset = (page - 1) * per_page
    comets = get_all_comets()
    comets = comets[comets['mag'] < 20.0].sort_values(by=['mag'])

    if search_form.q.data:
        search_expr = search_form.q.data.replace('"', '')
        comets = comets.query('designation.str.contains("{}")'.format(search_expr))

    if len(comets) > 0:
        comets_for_render = comets.iloc[offset:offset + per_page]
    else:
        comets_for_render = comets

    pagination = Pagination(page=page, per_page=per_page, total=len(comets), search=False, record_name='comets', css_framework='semantic', not_passed_args='back')
    return render_template('main/solarsystem/comets.html', comets=comets_for_render, pagination=pagination, search_form=search_form)
コード例 #5
0
def import_history_records():
    search_form = SearchImportHistoryRecsForm()

    ret, page = process_paginated_session_search(
        'import_history_search_page',
        [('import_history_search', search_form.q),
         ('items_per_page', search_form.items_per_page)])

    per_page = get_items_per_page(search_form.items_per_page)

    if not ret:
        return redirect(url_for('main_import_history.import_history_records'))

    offset = (page - 1) * per_page

    import_type_code = request.args.get('type')
    import_type = None

    if import_type_code == 'obs':
        import_type = ImportType.OBSERVATION
    elif import_type_code == 'sess':
        import_type = ImportType.SESSION

    import_history_recs = ImportHistoryRec.query.filter_by(
        create_by=current_user.id)
    if import_type:
        import_history_recs = import_history_recs.filter_by(
            import_type=import_type)

    import_history_recs = import_history_recs.order_by(
        ImportHistoryRec.create_date.desc())
    import_history_recs_for_render = import_history_recs.limit(
        per_page).offset(offset).all()

    pagination = Pagination(page=page,
                            per_page=per_page,
                            total=import_history_recs.count(),
                            search=False,
                            rec_name='import_history_recs',
                            css_framework='semantic',
                            not_passed_args='back')

    return render_template('main/import_history/import_history_records.html',
                           import_history_recs=import_history_recs_for_render,
                           pagination=pagination,
                           search_form=search_form)
コード例 #6
0
def locations():
    search_form = SearchLocationForm()

    ret, page = process_paginated_session_search(
        'location_search_page',
        [('location_search', search_form.q),
         ('items_per_page', search_form.items_per_page)])

    per_page = get_items_per_page(search_form.items_per_page)

    if not ret:
        return redirect(url_for('main_location.locations'))

    offset = (page - 1) * per_page

    locations = Location.query.filter(
        or_(
            and_(Location.is_public == True,
                 Location.is_for_observation == True),
            Location.user_id == current_user.id))
    if search_form.q.data:
        locations = locations.filter(
            Location.name.like('%' + search_form.q.data + '%'))
    locations_for_render = locations.limit(per_page).offset(offset).all()

    pagination = Pagination(page=page,
                            per_page=per_page,
                            total=locations.count(),
                            search=False,
                            record_name='locations',
                            css_framework='semantic',
                            not_passed_args='back')

    return render_template('main/location/locations.html',
                           locations=locations_for_render,
                           pagination=pagination,
                           search_form=search_form)
コード例 #7
0
def standalone_observations():
    """View standalone observations."""
    search_form = SearchStandaloneObservationForm()

    sort_by = request.args.get('sortby')

    ret, page = process_paginated_session_search(
        'stobservation_search_page',
        [('items_per_page', search_form.items_per_page)])

    if not ret:
        return redirect(
            url_for('main_standalone_observation.standalone_observations',
                    page=page,
                    sortby=sort_by))

    per_page = get_items_per_page(search_form.items_per_page)

    offset = (page - 1) * per_page

    observations = Observation.query.filter_by(
        user_id=current_user.id).order_by(Observation.date_from.desc())
    search = False

    observations_for_render = observations.limit(per_page).offset(offset).all()

    pagination = Pagination(page=page,
                            per_page=per_page,
                            total=observations.count(),
                            search=search,
                            record_name='observations',
                            css_framework='semantic')
    return render_template('main/observation/standalone_observations.html',
                           observations=observations_for_render,
                           pagination=pagination,
                           search_form=search_form)
コード例 #8
0
ファイル: double_star_views.py プロジェクト: skybber/czsky
def double_stars():
    """View double stars."""
    search_form = SearchDoubleStarForm()

    sort_by = request.args.get('sortby')

    ret, page = process_paginated_session_search('dbl_star_search_page', [
        ('dbl_star_search', search_form.q),
        ('constellation_id', search_form.constellation_id),
        ('dbl_mag_max', search_form.mag_max),
        ('dbl_delta_mag_min', search_form.delta_mag_min),
        ('dbl_separation_min', search_form.separation_min),
        ('dbl_separation_max', search_form.separation_max),
        ('dec_min', search_form.dec_min),
        ('items_per_page', search_form.items_per_page)
    ])

    if not ret:
        return redirect(url_for('main_double_star.double_stars', page=page, sortby=sort_by))

    per_page = get_items_per_page(search_form.items_per_page)

    offset = (page - 1) * per_page

    dbl_star_query = DoubleStar.query
    if search_form.q.data:
        dbl_star_query = dbl_star_query.filter(or_(DoubleStar.common_cat_id == search_form.q.data,
                                               DoubleStar.wds_number == search_form.q.data,
                                               DoubleStar.norm_other_designation.like('%;' + search_form.q.data + ';%')
                                               ))
    else:
        if search_form.constellation_id.data is not None:
            dbl_star_query = dbl_star_query.filter(DoubleStar.constellation_id == search_form.constellation_id.data)
        if search_form.mag_max.data:
            dbl_star_query = dbl_star_query.filter(DoubleStar.mag_first < search_form.mag_max.data, DoubleStar.mag_second < search_form.mag_max.data)
        if search_form.delta_mag_min.data:
            dbl_star_query = dbl_star_query.filter(DoubleStar.delta_mag > search_form.delta_mag_min.data)
        if search_form.separation_min.data:
            dbl_star_query = dbl_star_query.filter(DoubleStar.separation > search_form.separation_min.data)
        if search_form.separation_max.data:
            dbl_star_query = dbl_star_query.filter(DoubleStar.separation < search_form.separation_max.data)
        if search_form.dec_min.data:
            dbl_star_query = dbl_star_query.filter(DoubleStar.dec_first > (np.pi * search_form.dec_min.data / 180.0))

    sort_def = { 'wds_number': DoubleStar.wds_number,
                 'common_cat_id': DoubleStar.common_cat_id,
                 'components': DoubleStar.components,
                 'other_designation': DoubleStar.other_designation,
                 'ra': DoubleStar.ra_first,
                 'dec': DoubleStar.dec_first,
                 'mag_first': DoubleStar.mag_first,
                 'mag_second': DoubleStar.mag_second,
                 'separation': DoubleStar.separation,
                 'spectral_type': DoubleStar.spectral_type,
                 'constellation': DoubleStar.constellation_id,
                 }

    table_sort = create_table_sort(sort_by, sort_def.keys())

    order_by_field = None
    if sort_by:
        desc = sort_by[0] == '-'
        sort_by_name = sort_by[1:] if desc else sort_by
        order_by_field = sort_def.get(sort_by_name)
        if order_by_field and desc:
            order_by_field = order_by_field.desc()

    if order_by_field is None:
        order_by_field = DoubleStar.id

    shown_double_stars = dbl_star_query.order_by(order_by_field).limit(per_page).offset(offset).all()

    pagination = Pagination(page=page, per_page=per_page, total=dbl_star_query.count(), search=False, record_name='double_stars',
                            css_framework='semantic', not_passed_args='back')

    packed_constell_list = get_packed_constell_list()

    return render_template('main/catalogue/double_stars.html', double_stars=shown_double_stars, pagination=pagination,
                           search_form=search_form, table_sort=table_sort, packed_constell_list=packed_constell_list)
コード例 #9
0
ファイル: deepskyobject_views.py プロジェクト: skybber/czsky
def deepskyobjects():
    """View deepsky objects."""
    search_form = SearchDsoForm()

    sort_by = request.args.get('sortby')

    ret, page = process_paginated_session_search(
        'dso_search_page', [('dso_search', search_form.q),
                            ('dso_type', search_form.dso_type),
                            ('dso_catal', search_form.catalogue),
                            ('dso_maglim', search_form.maglim),
                            ('items_per_page', search_form.items_per_page)])

    if not ret:
        return redirect(
            url_for('main_deepskyobject.deepskyobjects',
                    page=page,
                    sortby=sort_by))

    per_page = get_items_per_page(search_form.items_per_page)

    offset = (page - 1) * per_page

    dso_query = DeepskyObject.query
    if search_form.q.data:
        dso_query = dso_query.filter(
            DeepskyObject.name.like('%' +
                                    normalize_dso_name(search_form.q.data) +
                                    '%'))

    mag_scale = (8, 16)

    if search_form.dso_type.data and search_form.dso_type.data != 'All':
        dso_query = dso_query.filter(
            DeepskyObject.type == search_form.dso_type.data)

    if search_form.catalogue.data and search_form.catalogue.data != 'All':
        cat_id = Catalogue.get_catalogue_id_by_cat_code(
            search_form.catalogue.data)
        if cat_id:
            dso_query = dso_query.filter_by(catalogue_id=cat_id)

    if not search_form.q.data and search_form.maglim.data is not None and search_form.maglim.data < mag_scale[
            1]:
        dso_query = dso_query.filter(
            DeepskyObject.mag < search_form.maglim.data)

    sort_def = {
        'name': DeepskyObject.name,
        'type': DeepskyObject.type,
        'ra': DeepskyObject.ra,
        'dec': DeepskyObject.dec,
        'constellation': DeepskyObject.constellation_id,
        'mag': DeepskyObject.mag,
    }

    table_sort = create_table_sort(sort_by, sort_def.keys())

    order_by_field = None
    if sort_by:
        desc = sort_by[0] == '-'
        sort_by_name = sort_by[1:] if desc else sort_by
        order_by_field = sort_def.get(sort_by_name)
        if order_by_field and desc:
            order_by_field = order_by_field.desc()

    if order_by_field is None:
        order_by_field = DeepskyObject.id

    shown_dsos = dso_query.order_by(order_by_field).limit(per_page).offset(
        offset).all()

    observed = set()
    if not current_user.is_anonymous:
        for dso in ObservedList.get_observed_dsos_by_user_id(current_user.id):
            observed.add(dso.id)

    pagination = Pagination(page=page,
                            per_page=per_page,
                            total=dso_query.count(),
                            search=False,
                            record_name='deepskyobjects',
                            css_framework='semantic',
                            not_passed_args='back')

    return render_template('main/catalogue/deepskyobjects.html',
                           deepskyobjects=shown_dsos,
                           mag_scale=mag_scale,
                           pagination=pagination,
                           search_form=search_form,
                           table_sort=table_sort,
                           observed=observed)
コード例 #10
0
ファイル: sessionplan_views.py プロジェクト: skybber/czsky
def session_plan_schedule(session_plan_id):
    """View a session plan schedule."""
    session_plan = SessionPlan.query.filter_by(id=session_plan_id).first()
    is_mine_session_plan = _check_session_plan(session_plan, allow_public=True)
    if not is_mine_session_plan:
        return redirect(
            url_for('main_sessionplan.session_plan_info',
                    session_plan_id=session_plan.id))

    schedule_form = SessionPlanScheduleFilterForm()

    src_sort_by = request.args.get('src_sortby')

    str_per_page = request.args.get('per_page', None)
    if str_per_page is not None:
        session['items_per_page'] = int(str_per_page)

    ret, page = process_paginated_session_search(
        'planner_page',
        [('planner_dso_type', schedule_form.dso_type),
         ('planner_dso_obj_source', schedule_form.obj_source),
         ('planner_dso_maglim', schedule_form.maglim),
         ('planner_constellation_id', schedule_form.constellation_id),
         ('planner_min_altitude', schedule_form.min_altitude),
         ('planner_time_from', schedule_form.time_from),
         ('planner_time_to', schedule_form.time_to),
         ('planner_not_observed', schedule_form.not_observed),
         ('planner_selected_dso_name', schedule_form.selected_dso_name),
         ('items_per_page', schedule_form.items_per_page)])

    if not ret:
        return redirect(
            url_for('main_sessionplan.session_plan_schedule',
                    session_plan_id=session_plan_id,
                    page=page,
                    sortby=src_sort_by))

    add_form = AddToSessionPlanForm()
    add_form.session_plan_id.data = session_plan.id

    per_page = get_items_per_page(schedule_form.items_per_page)

    offset = (page - 1) * per_page

    mag_scale = (8, 16)

    sort_def = {
        'name': DeepskyObject.name,
        'type': DeepskyObject.type,
        'constellation': DeepskyObject.constellation_id,
        'mag': DeepskyObject.mag,
    }

    src_table_sort = create_table_sort(src_sort_by, sort_def.keys())

    observer, tz_info = _get_observer_tzinfo(session_plan)

    observation_time = Time(session_plan.for_date)

    # try astronomical twilight
    default_t1, default_t2 = _get_twighligh_component(session_plan, 1)
    if not default_t2 and not default_t2:
        # try nautical twilight
        default_t1, default_t2 = _get_twighligh_component(session_plan, 1)

    time_from = _setup_search_from(schedule_form, observer, observation_time,
                                   tz_info, default_t1)
    time_to = _setup_search_to(schedule_form, observer, observation_time,
                               time_from, tz_info, default_t2)

    selection_compound_list, page, all_count = create_selection_coumpound_list(
        session_plan, schedule_form, observer, observation_time, time_from,
        time_to, tz_info, page, offset, per_page, src_sort_by, mag_scale,
        sort_def)

    src_pagination = Pagination(page=page,
                                per_page=per_page,
                                total=all_count,
                                search=False,
                                record_name='deepskyobjects',
                                css_framework='semantic',
                                not_passed_args='back')

    session_plan_compound_list = create_session_plan_compound_list(
        session_plan, observer, observation_time, tz_info, sort_def)

    dst_page = request.args.get('dst_page',
                                type=int,
                                default=session.get('planner_dst_page', 1))

    last_dst_page = (len(session_plan_compound_list) - 1) // per_page + 1
    if dst_page >= last_dst_page:
        dst_page = last_dst_page
    if dst_page < 1:
        dst_page = 1

    session['planner_dst_page'] = dst_page

    dst_offset = (dst_page - 1) * per_page

    session_plan_compound_list_for_render = session_plan_compound_list[
        dst_offset:dst_offset + per_page]

    dst_pagination = Pagination(dst_page=dst_page,
                                page_parameter='dst_page',
                                total=len(session_plan_compound_list),
                                search=False,
                                per_page=per_page,
                                record_name='deepskyobjects',
                                css_framework='semantic',
                                not_passed_args='back')

    selected_dso_name = None

    srow_index = request.args.get('srow_index', type=int, default=-1)
    drow_index = request.args.get('drow_index', type=int, default=-1)

    if drow_index == -1 and srow_index == -1:
        srow_index = 1

    if srow_index > len(selection_compound_list):
        srow_index = len(selection_compound_list)
    if srow_index > 0:
        selected_dso_name = selection_compound_list[srow_index - 1][0].name

    if drow_index > len(session_plan_compound_list_for_render):
        drow_index = len(session_plan_compound_list_for_render)
    if drow_index > 0:
        selected_dso_name = session_plan_compound_list_for_render[
            drow_index - 1][0].deepskyObject.name

    if not schedule_form.selected_dso_name.data:
        schedule_form.selected_dso_name.data = 'M1'
    if not selected_dso_name:
        selected_dso_name = schedule_form.selected_dso_name.data

    packed_constell_list = get_packed_constell_list()

    return render_template(
        'main/planner/session_plan_info.html',
        type='schedule',
        session_plan=session_plan,
        selection_compound_list=selection_compound_list,
        session_plan_compound_list=session_plan_compound_list_for_render,
        dso_lists=DsoList.query.all(),
        catalogues_menu_items=get_catalogues_menu_items(),
        mag_scale=mag_scale,
        add_form=add_form,
        schedule_form=schedule_form,
        min_alt_item_list=min_alt_item_list,
        src_pagination=src_pagination,
        src_table_sort=src_table_sort,
        dst_pagination=dst_pagination,
        selected_dso_name=selected_dso_name,
        srow_index=srow_index,
        drow_index=drow_index,
        is_mine_session_plan=is_mine_session_plan,
        packed_constell_list=packed_constell_list)
コード例 #11
0
ファイル: minor_planet_views.py プロジェクト: skybber/czsky
def minor_planets():
    """View minor_planets."""
    search_form = SearchMinorPlanetForm()

    ret, page = process_paginated_session_search('minor_planet_search_page', [
        ('minor_planet_search', search_form.q),
    ])

    per_page = get_items_per_page(search_form.items_per_page)

    if not ret:
        return redirect(url_for('main_minor_planet.minor_planets'))

    offset = (page - 1) * per_page
    minor_planet_query = MinorPlanet.query

    if search_form.q.data:
        search_expr = search_form.q.data.replace('"', '')
        minor_planet_query = minor_planet_query.filter(
            MinorPlanet.designation.like('%' + search_expr + '%'))

    magnitudes = {}

    minor_planets_for_render = minor_planet_query.order_by(
        MinorPlanet.int_designation).limit(per_page).offset(offset).all()

    ts = load.timescale(builtin=True)
    eph = load('de421.bsp')
    sun, earth = eph['sun'], eph['earth']
    t = ts.now()

    ra, dec, earth_sun_distance = earth.at(t).observe(sun).apparent().radec()

    mpc_minor_planets = _get_mpc_minor_planets()

    for minor_planet in minor_planets_for_render:
        mpc_minor_planet = mpc_minor_planets.iloc[minor_planet.int_designation]
        body = sun + mpc.mpcorb_orbit(mpc_minor_planet, ts, GM_SUN)
        ra, dec, sun_body_distance = sun.at(t).observe(body).radec()
        ra, dec, earth_body_distance = earth.at(t).observe(
            body).apparent().radec()

        apparent_magnitude = _get_apparent_magnitude_hg(
            minor_planet.magnitude_H, minor_planet.magnitude_G,
            earth_body_distance.au, sun_body_distance.au,
            earth_sun_distance.au)
        if apparent_magnitude:
            magnitudes[minor_planet.int_designation] = '{:.2f}'.format(
                apparent_magnitude)

    pagination = Pagination(page=page,
                            per_page=per_page,
                            total=minor_planet_query.count(),
                            search=False,
                            record_name='minor_planets',
                            css_framework='semantic',
                            not_passed_args='back')
    return render_template('main/solarsystem/minor_planets.html',
                           minor_planets=minor_planets_for_render,
                           pagination=pagination,
                           search_form=search_form,
                           magnitudes=magnitudes)