Пример #1
0
def constellation_chart(constellation_id):
    """View a constellation findchart."""
    constellation = _find_constellation(constellation_id)
    if constellation is None:
        abort(404)

    form = ChartForm()

    if not common_ra_dec_fsz_from_request(form):
        if form.ra.data is None or form.dec.data is None:
            form.ra.data = constellation.label_ra
            form.dec.data = constellation.label_dec

    chart_control = common_prepare_chart_data(form)

    lang, editor_user = get_lang_and_editor_user_from_request(
        for_constell_descr=True)

    common_name = _get_constellation_common_name(constellation)
    return render_template(
        'main/catalogue/constellation_info.html',
        fchart_form=form,
        type='chart',
        constellation=constellation,
        chart_control=chart_control,
        common_name=common_name,
    )
Пример #2
0
def constellation_edit(constellation_id):
    """Update constellation."""
    if not current_user.is_editor():
        abort(403)
    constellation = Constellation.query.filter_by(id=constellation_id).first()
    if constellation is None:
        abort(404)

    lang, editor_user = get_lang_and_editor_user_from_request(
        for_constell_descr=True)
    user_descr = None
    form = ConstellationEditForm()
    goback = False
    if editor_user:
        user_descr = UserConsDescription.query.filter_by(
            constellation_id=constellation.id,
            user_id=editor_user.id,
            lang_code=lang).first()
        if user_descr is None:
            user_descr = UserConsDescription(
                constellation_id=constellation_id,
                user_id=editor_user.id,
                common_name='',
                text='',
                lang_code=lang,
                create_by=current_user.id,
                update_by=current_user.id,
                create_date=datetime.now(),
                update_date=datetime.now(),
            )
        if request.method == 'GET':
            form.common_name.data = user_descr.common_name
            form.text.data = user_descr.text
        elif form.validate_on_submit():
            user_descr.common_name = form.common_name.data
            user_descr.text = form.text.data
            user_descr.update_by = current_user.id
            user_descr.update_date = datetime.now()
            db.session.add(user_descr)
            db.session.commit()
            flash(gettext('Constellation successfully updated'),
                  'form-success')
            if form.goback.data != 'true':
                return redirect(
                    url_for('main_constellation.constellation_edit',
                            constellation_id=constellation_id))
            goback = True

    if goback:
        return redirect(
            url_for('main_constellation.constellation_info',
                    constellation_id=constellation.iau_code))

    author = _create_author_entry(user_descr.update_by, user_descr.update_date)

    return render_template('main/catalogue/constellation_edit.html',
                           form=form,
                           constellation=constellation,
                           user_descr=user_descr,
                           author=author)
Пример #3
0
def double_star_chart(double_star_id):
    """View a double star findchart."""
    double_star = DoubleStar.query.filter_by(id=double_star_id).first()
    if not double_star:
        abort(404)

    embed = request.args.get('embed')
    if embed:
        session['double_star_embed_seltab'] = 'catalogue_data'

    season = request.args.get('season')

    form = ChartForm()

    if not common_ra_dec_fsz_from_request(form):
        if form.ra.data is None or form.dec.data is None:
            form.ra.data = double_star.ra_first
            form.dec.data = double_star.dec_first

    chart_control = common_prepare_chart_data(form)

    prev_dbl_star, next_dbl_star = _get_prev_next_double_star(double_star)

    lang, editor_user = get_lang_and_editor_user_from_request(for_constell_descr=True)
    user_descr = UserStarDescription.query.filter_by(double_star_id=double_star_id, user_id=editor_user.id, lang_code=lang).first()

    return render_template('main/catalogue/double_star_info.html', fchart_form=form, type='chart', double_star=double_star,
                           chart_control=chart_control, prev_dbl_star=prev_dbl_star, next_dbl_star=next_dbl_star, embed=embed, season=season,
                           user_descr=user_descr)
Пример #4
0
def star_descr_info(star_descr_id):
    """View a star description info."""
    lang, editor_user = get_lang_and_editor_user_from_request(
        for_constell_descr=True)
    user_descr = UserStarDescription.query.filter_by(id=star_descr_id,
                                                     user_id=editor_user.id,
                                                     lang_code=lang).first()
    if user_descr is None:
        abort(404)

    embed = request.args.get('embed')
    if embed:
        session['star_embed_seltab'] = 'info'

    season = request.args.get('season')

    editable = current_user.is_editor()

    if user_descr.star is not None:
        prev_star, next_star = _get_prev_next_star(user_descr.star)
    else:
        prev_star, next_star = (None, None)

    return render_template(
        'main/catalogue/star_info.html',
        type='info',
        user_descr=user_descr,
        prev_star=prev_star,
        next_star=next_star,
        editable=editable,
        embed=embed,
        season=season,
    )
Пример #5
0
def _get_constellation_common_name(constellation):
    lang, editor_user = get_lang_and_editor_user_from_request(
        for_constell_descr=True)
    common_name = None
    if editor_user:
        ucd = UserConsDescription.query.filter_by(constellation_id=constellation.id, user_id=editor_user.id, lang_code=lang) \
            .first()
        common_name = ucd.common_name if ucd else None
    return common_name
Пример #6
0
def dso_lists_menu():
    dso_lists = DsoList.query.filter_by(hidden=False).all()
    star_lists = StarList.query.all()
    lang, editor_user = get_lang_and_editor_user_from_request(
        for_constell_descr=False)
    return render_template('main/catalogue/dso_list_menu.html',
                           dso_lists=dso_lists,
                           star_lists=star_lists,
                           lang_code=lang)
Пример #7
0
def dso_list_chart(dso_list_id):
    dso_list = _find_dso_list(dso_list_id)
    if dso_list is None:
        abort(404)

    form = ChartForm()

    dso_id = request.args.get('dso_id')
    dso_list_item = None
    if dso_id and dso_id.isdigit():
        idso_id = int(dso_id)
        dso_list_item = next((x for x in dso_list.dso_list_items
                              if x.deepskyObject.id == idso_id), None)

    if not dso_list_item:
        dso_list_item = DsoListItem.query.filter_by(dso_list_id=dso_list.id,
                                                    item_id=1).first()

    lang, editor_user = get_lang_and_editor_user_from_request(
        for_constell_descr=False)
    dso_list_descr = DsoListDescription.query.filter_by(
        dso_list_id=dso_list.id, lang_code=lang).first()

    if not common_ra_dec_fsz_from_request(form):
        if form.ra.data is None or form.dec.data is None:
            form.ra.data = dso_list_item.deepskyObject.ra if dso_list_item else 0
            form.dec.data = dso_list_item.deepskyObject.dec if dso_list_item else 0

    if dso_list_item:
        default_chart_iframe_url = url_for(
            'main_deepskyobject.deepskyobject_info',
            back='dso_list',
            back_id=dso_list.id,
            dso_id=dso_list_item.deepskyObject.name,
            embed='fc',
            allow_back='true')
    else:
        default_chart_iframe_url = None

    chart_control = common_prepare_chart_data(form)

    return render_template('main/catalogue/dso_list_info.html',
                           fchart_form=form,
                           type='chart',
                           dso_list=dso_list,
                           dso_list_descr=dso_list_descr,
                           chart_control=chart_control,
                           default_chart_iframe_url=default_chart_iframe_url)
Пример #8
0
def star_descr_chart(star_descr_id):
    """View a star findchart."""
    lang, editor_user = get_lang_and_editor_user_from_request(
        for_constell_descr=True)
    user_descr = UserStarDescription.query.filter_by(id=star_descr_id,
                                                     user_id=editor_user.id,
                                                     lang_code=lang).first()
    if user_descr is None:
        abort(404)

    star = user_descr.star
    if not star:
        abort(404)

    embed = request.args.get('embed')
    if embed:
        session['star_embed_seltab'] = 'info'

    season = request.args.get('season')

    form = ChartForm()

    if not common_ra_dec_fsz_from_request(form):
        if form.ra.data is None or form.dec.data is None:
            form.ra.data = star.ra
            form.dec.data = star.dec

    chart_control = common_prepare_chart_data(form)

    if user_descr.star is not None:
        prev_star, next_star = _get_prev_next_star(user_descr.star)
    else:
        prev_star, next_star = (None, None)

    return render_template(
        'main/catalogue/star_info.html',
        fchart_form=form,
        type='chart',
        user_descr=user_descr,
        chart_control=chart_control,
        prev_star=prev_star,
        next_star=next_star,
        embed=embed,
        season=season,
    )
Пример #9
0
def double_star_catalogue_data(double_star_id):
    """View a double star catalogue data."""
    double_star = DoubleStar.query.filter_by(id=double_star_id).first()
    if double_star is None:
        abort(404)

    embed = request.args.get('embed')
    if embed:
        session['double_star_embed_seltab'] = 'catalogue_data'

    season = request.args.get('season')

    prev_dbl_star, next_dbl_star = _get_prev_next_double_star(double_star)

    lang, editor_user = get_lang_and_editor_user_from_request(for_constell_descr=True)
    user_descr = UserStarDescription.query.filter_by(double_star_id=double_star_id, user_id=editor_user.id, lang_code=lang).first()

    return render_template('main/catalogue/double_star_info.html', type='catalogue_data', double_star=double_star,
                           embed=embed, prev_dbl_star=prev_dbl_star, next_dbl_star=next_dbl_star, season=season, user_descr=user_descr)
Пример #10
0
def constellation_stars(constellation_id):
    """View a constellation stars."""
    constellation = _find_constellation(constellation_id)
    if constellation is None:
        abort(404)
    star_descriptions = None
    editable = current_user.is_editor()
    lang, editor_user = get_lang_and_editor_user_from_request(
        for_constell_descr=True)

    aster_descriptions = None
    if editor_user:
        star_descriptions = UserStarDescription.query.filter_by(user_id=editor_user.id, lang_code=lang)\
            .filter_by(constellation_id=constellation.id) \
            .all()
        star_descriptions = _sort_star_descr(star_descriptions)

        all_aster_descriptions = UserDsoDescription.query.filter_by(user_id=editor_user.id, lang_code=lang)\
            .join(UserDsoDescription.deepskyObject, aliased=True) \
            .filter(DeepskyObject.constellation_id == constellation.id, DeepskyObject.type == 'AST') \
            .order_by(UserDsoDescription.rating.desc()) \
            .all()

        existing = set()
        aster_descriptions = []
        for dsod in all_aster_descriptions:
            if dsod.dso_id not in existing:
                existing.add(dsod.dso_id)
                aster_descriptions.append(dsod)

    common_name = _get_constellation_common_name(constellation)

    return render_template('main/catalogue/constellation_info.html',
                           constellation=constellation,
                           type='stars',
                           star_descriptions=star_descriptions,
                           aster_descriptions=aster_descriptions,
                           editable=editable,
                           common_name=common_name)
Пример #11
0
def constellations():
    """View all constellations."""

    search_form = SearchConstellationForm()
    if search_form.season.data == 'All':
        search_form.season.data = None

    if not process_session_search([('const_search', search_form.q),
                                   ('const_season', search_form.season)]):
        return redirect(
            url_for('main_constellation.constellations',
                    season=search_form.season.data))

    season = request.args.get('season', None)

    lang, editor_user = get_lang_and_editor_user_from_request(
        for_constell_descr=True)
    constellations = Constellation.query
    if search_form.q.data:
        constellations = constellations.filter(
            Constellation.name.like('%' + search_form.q.data + '%'))

    if editor_user:
        db_common_names = UserConsDescription.query \
                    .with_entities(UserConsDescription.constellation_id, UserConsDescription.common_name) \
                    .filter_by(user_id=editor_user.id, lang_code=lang)
    else:
        db_common_names = []

    if season:
        constellations = constellations.filter(Constellation.season == season)

    cons_names = {i[0]: i[1] for i in db_common_names}

    return render_template('main/catalogue/constellations.html',
                           constellations=constellations,
                           search_form=search_form,
                           cons_names=cons_names)
Пример #12
0
def get_packed_constell_list():
    lang, editor_user = get_lang_and_editor_user_from_request(
        for_constell_descr=True)

    if editor_user:
        constellation_id_names = UserConsDescription.query \
            .with_entities(UserConsDescription.constellation_id, UserConsDescription.common_name) \
            .filter_by(user_id=editor_user.id, lang_code=lang).all()
    else:
        constellation_id_names = []

    constellation_id_names = sorted(constellation_id_names,
                                    key=lambda x: cs_collator.getSortKey(x[1]))

    packed_constell_list = []
    letter, letter_list = '', []
    l1, l2 = None, None
    for constel in constellation_id_names:
        if constel[1][0] != letter:
            if l2 and letter_list:
                packed_constell_list.append([l1 + ' ... ' + l2, letter_list])
                letter_list = []
                l1, l2 = None, None
            letter = constel[1][0]
            if l1 is None:
                l1 = letter
            else:
                l2 = letter
        letter_list.append(constel)

    if letter_list:
        if l2 is not None:
            packed_constell_list.append([l1 + ' ... ' + l2, letter_list])
        else:
            packed_constell_list.append([l1, letter_list])
    return packed_constell_list
Пример #13
0
def constellation_info(constellation_id):
    """View a constellation info."""
    constellation = _find_constellation(constellation_id)
    if constellation is None:
        abort(404)
    user_descr = None
    common_name = None
    dso_descriptions = None
    star_descriptions = None
    title_images = None
    ug_bl_dsos = None
    lang, editor_user = get_lang_and_editor_user_from_request(
        for_constell_descr=True)
    lang_dso, editor_user_dso = get_lang_and_editor_user_from_request(
        for_constell_descr=False)
    cs_editor_user = get_cs_editor_user()

    if editor_user:
        ucd = UserConsDescription.query.filter_by(constellation_id=constellation.id, user_id=editor_user.id, lang_code=lang)\
                .first()

        user_descr = ucd.text if ucd else None
        common_name = ucd.common_name if ucd else None

        star_descriptions = UserStarDescription.query.filter_by(user_id=editor_user.id, lang_code=lang)\
                                                     .filter_by(constellation_id=constellation.id) \
                                                     .all()
        star_descriptions = _sort_star_descr(star_descriptions)

        all_cs_dso_descriptions = UserDsoDescription.query.filter_by(user_id=cs_editor_user.id, lang_code='cs')\
                                                          .join(UserDsoDescription.deepskyObject, aliased=True) \
                                                          .filter(DeepskyObject.constellation_id == constellation.id, DeepskyObject.type != 'AST') \
                                                          .order_by(UserDsoDescription.rating.desc(), DeepskyObject.mag) \
                                                          .all()

        if lang != 'cs':
            # Show all objects that are in CS version plus UG-BL objects
            existing = set(dsod.dso_id for dsod in all_cs_dso_descriptions)
            all_dso_descriptions = []
            available_dso_descriptions = UserDsoDescription.query.filter_by(user_id=editor_user_dso.id, lang_code=lang)\
                                                                 .join(UserDsoDescription.deepskyObject, aliased=True) \
                                                                 .filter(DeepskyObject.constellation_id == constellation.id, DeepskyObject.type != 'AST') \
                                                                 .order_by(UserDsoDescription.rating.desc(), DeepskyObject.mag) \
                                                                 .all()

            available_dso_descriptions_map = {}

            for dsod in available_dso_descriptions:
                available_dso_descriptions_map[dsod.dso_id] = dsod
                if dsod.dso_id in existing:
                    all_dso_descriptions.append(dsod)
                elif dsod.deepskyObject.mag < 10.0:
                    all_dso_descriptions.append(dsod)
                    existing.add(dsod.dso_id)

            constell_ug_bl_dsos = get_ug_bl_dsos()[constellation.id]
            for dso_id in constell_ug_bl_dsos:
                dso = constell_ug_bl_dsos[dso_id]
                loading_dso_id = dso.master_id if dso.master_id is not None else dso_id
                if not dso_id in existing and loading_dso_id in available_dso_descriptions_map:
                    all_dso_descriptions.append(
                        available_dso_descriptions_map[loading_dso_id])

        else:
            all_dso_descriptions = all_cs_dso_descriptions

        existing = set()
        dso_descriptions = []
        title_images = {}
        for dsod in all_dso_descriptions:
            if dsod.dso_id not in existing:
                existing.add(dsod.dso_id)
                dso_descriptions.append(dsod)
            if not dsod.text or not dsod.text.startswith('![<]($IMG_DIR/'):
                image_info = get_dso_image_info_with_imgdir(
                    dsod.deepskyObject.normalized_name_for_img())
                if image_info is not None:
                    title_images[dsod.dso_id] = image_info[0]

        dso_apert_descriptions = UserDsoApertureDescription.query.filter_by(user_id=editor_user_dso.id, lang_code=lang)\
                                                                 .join(UserDsoApertureDescription.deepskyObject, aliased=True) \
                                                                 .filter_by(constellation_id=constellation.id) \
                                                                 .order_by(UserDsoApertureDescription.aperture_class, UserDsoApertureDescription.lang_code) \
                                                                 .all()

        aperture_descr_map = {}
        for apdescr in dso_apert_descriptions:
            if apdescr.dso_id not in aperture_descr_map:
                aperture_descr_map[apdescr.dso_id] = []
            dsoapd = aperture_descr_map[apdescr.dso_id]
            if apdescr.aperture_class not in [cl[0] for cl in dsoapd
                                              ] and apdescr.text:
                if apdescr.aperture_class == '<100':
                    dsoapd.insert(0, (apdescr.aperture_class, apdescr.text))
                else:
                    dsoapd.append((apdescr.aperture_class, apdescr.text))

        ug_bl_dsos = []
        constell_ug_bl_dsos = get_ug_bl_dsos()[constellation.id]
        for dso_id in constell_ug_bl_dsos:
            if dso_id not in existing:
                dso = constell_ug_bl_dsos[dso_id]
                if dso.master_id not in existing:
                    dso_image_info = get_dso_image_info(
                        dso.normalized_name_for_img())
                    ug_bl_dsos.append({'dso': dso, 'img_info': dso_image_info})

        ug_bl_dsos.sort(key=lambda x: x['dso'].mag)
    editable = current_user.is_editor()

    wish_list = None
    observed_list = None
    if current_user.is_authenticated:
        wish_list = [
            item.dso_id for item in WishList.create_get_wishlist_by_user_id(
                current_user.id).wish_list_items
        ]
        observed_list = [
            item.dso_id
            for item in ObservedList.create_get_observed_list_by_user_id(
                current_user.id).observed_list_items
        ]

    return render_template(
        'main/catalogue/constellation_info.html',
        constellation=constellation,
        type='info',
        user_descr=user_descr,
        common_name=common_name,
        star_descriptions=star_descriptions,
        dso_descriptions=dso_descriptions,
        aperture_descr_map=aperture_descr_map,
        editable=editable,
        ug_bl_dsos=ug_bl_dsos,
        wish_list=wish_list,
        observed_list=observed_list,
        title_images=title_images,
    )
Пример #14
0
def deepskyobject_edit(dso_id):
    """Update deepsky object."""
    if not current_user.is_editor():
        abort(403)
    dso = DeepskyObject.query.filter_by(id=dso_id).first()
    if dso is None:
        abort(404)
    lang, editor_user = get_lang_and_editor_user_from_request(
        for_constell_descr=False)
    user_descr = None
    form = DeepskyObjectEditForm()
    if editor_user:
        user_descr = UserDsoDescription.query.filter_by(
            dso_id=dso.id, user_id=editor_user.id, lang_code=lang).first()
        authors = {}

        is_new = False
        if not user_descr:
            user_descr = UserDsoDescription(
                dso_id=dso_id,
                user_id=editor_user.id,
                rating=form.rating.data,
                lang_code=lang,
                common_name='',
                text='',
                references='',
                cons_order=1,
                create_by=current_user.id,
                create_date=datetime.now(),
            )
            is_new = True

        all_user_apert_descrs = UserDsoApertureDescription.query.filter_by(dso_id=dso.id, user_id=editor_user.id, lang_code=lang) \
                                                                           .order_by(UserDsoApertureDescription.aperture_class)

        user_apert_descriptions = []
        # create missing UserDsoApertureDescription
        for aperture_class in SHOWN_APERTURE_DESCRIPTIONS:
            for ad in all_user_apert_descrs:
                if ad.aperture_class == aperture_class:
                    user_apert_descriptions.append(ad)
                    break
            else:
                ad = UserDsoApertureDescription(
                    dso_id=dso_id,
                    user_id=editor_user.id,
                    rating=1,
                    lang_code=lang,
                    aperture_class=aperture_class,
                    text='',
                    create_by=current_user.id,
                    create_date=datetime.now(),
                )
                user_apert_descriptions.append(ad)

        if request.method == 'GET':
            form.common_name.data = user_descr.common_name
            form.text.data = user_descr.text
            form.references.data = user_descr.references
            form.rating.data = user_descr.rating
            for ad in user_apert_descriptions:
                adi = form.aperture_descr_items.append_entry()
                adi.aperture_class.data = ad.aperture_class
                adi.text.data = ad.text
                adi.is_public.data = ad.is_public
                adi.text.label = ad.aperture_class
        elif form.validate_on_submit():
            was_text_changed = user_descr.text != form.text.data
            has_descr = False
            for adi in form.aperture_descr_items:
                for ad in user_apert_descriptions:
                    if ad.aperture_class == adi.aperture_class.data:
                        if adi.text.data:
                            ad.text = adi.text.data
                            ad.is_public = adi.is_public.data
                            ad.update_by = current_user.id
                            ad.update_date = datetime.now()
                            db.session.add(ad)
                            has_descr = True
                        elif ad.id is not None:
                            db.session.delete(ad)
            if is_new or was_text_changed or user_descr.common_name != form.common_name.data or \
                    user_descr.references != form.references.data or user_descr.rating != form.rating.data:
                user_descr.common_name = form.common_name.data
                user_descr.references = form.references.data
                user_descr.text = form.text.data
                user_descr.rating = form.rating.data
                if was_text_changed:
                    user_descr.update_by = current_user.id
                    user_descr.update_date = datetime.now()
                if has_descr or user_descr.text:
                    db.session.add(user_descr)
                else:
                    db.session.delete(user_descr)
            db.session.commit()

            flash('Deepsky object successfully updated', 'form-success')

            if form.goback.data != 'true':
                return redirect(
                    url_for('main_deepskyobject.deepskyobject_edit',
                            dso_id=dso_id))

            back = request.args.get('back')
            back_id = request.args.get('back_id')
            if back == 'constell':
                return redirect(
                    url_for('main_constellation.constellation_info',
                            constellation_id=back_id,
                            _anchor='dso' + str(dso.id)))
            return redirect(
                url_for('main_deepskyobject.deepskyobject_info',
                        dso_id=dso.name,
                        back=back,
                        back_id=back_id))

    authors['dso'] = _create_author_entry(user_descr.update_by,
                                          user_descr.update_date)
    for ad in user_apert_descriptions:
        authors[ad.aperture_class] = _create_author_entry(
            ad.update_by, ad.update_date)

    return render_template('main/catalogue/deepskyobject_edit.html',
                           form=form,
                           dso=dso,
                           authors=authors,
                           is_new=False)
Пример #15
0
def deepskyobject_info(dso_id):
    """View a deepsky object info."""
    dso, orig_dso = _find_dso(dso_id)
    if dso is None:
        abort(404)

    embed = request.args.get('embed')
    if embed:
        session['dso_embed_seltab'] = 'info'

    lang, editor_user = get_lang_and_editor_user_from_request(
        for_constell_descr=False)
    user_descr = None
    apert_descriptions = []
    title_img = None
    if editor_user:
        user_descr = UserDsoDescription.query.filter_by(
            dso_id=dso.id, user_id=editor_user.id, lang_code=lang).first()
        user_apert_descrs = UserDsoApertureDescription.query.filter_by(dso_id=dso.id, user_id=editor_user.id, lang_code=lang) \
                        .filter(func.coalesce(UserDsoApertureDescription.text, '') != '') \
                        .order_by(UserDsoApertureDescription.aperture_class, UserDsoApertureDescription.lang_code)
        for apdescr in user_apert_descrs:
            if apdescr.aperture_class not in [
                    cl[0] for cl in apert_descriptions
            ] and apdescr.text:
                if apdescr.aperture_class == '<100':
                    apert_descriptions.insert(
                        0, (apdescr.aperture_class, apdescr.text))
                else:
                    apert_descriptions.append(
                        (apdescr.aperture_class, apdescr.text))

        if user_descr and (not user_descr.text or
                           not user_descr.text.startswith('![<]($IMG_DIR/')):
            image_info = get_dso_image_info_with_imgdir(
                dso.normalized_name_for_img())
            if image_info is not None:
                title_img = image_info[0]

    prev_dso, prev_dso_title, next_dso, next_dso_title = _get_prev_next_dso(
        orig_dso)

    editable = current_user.is_editor()
    descr_available = user_descr and user_descr.text or any(
        [adescr for adescr in apert_descriptions])
    dso_image_info = get_dso_image_info(dso.normalized_name_for_img())

    other_names = _get_other_names(dso)

    wish_list = None
    observed_list = None
    if current_user.is_authenticated:
        wish_item = WishListItem.query.filter(WishListItem.dso_id.in_((dso.id, orig_dso.id))) \
            .join(WishList) \
            .filter(WishList.user_id == current_user.id) \
            .first()
        wish_list = [wish_item.dso_id] if wish_item is not None else []

        observed_item = ObservedListItem.query.filter(ObservedListItem.dso_id.in_((dso.id, orig_dso.id))) \
            .join(ObservedList) \
            .filter(ObservedList.user_id == current_user.id) \
            .first()
        observed_list = [observed_item.dso_id
                         ] if observed_item is not None else []

    has_observations = _has_dso_observations(dso, orig_dso)
    season = request.args.get('season')

    return render_template(
        'main/catalogue/deepskyobject_info.html',
        type='info',
        dso=dso,
        user_descr=user_descr,
        apert_descriptions=apert_descriptions,
        prev_dso=prev_dso,
        next_dso=next_dso,
        prev_dso_title=prev_dso_title,
        next_dso_title=next_dso_title,
        editable=editable,
        descr_available=descr_available,
        dso_image_info=dso_image_info,
        other_names=other_names,
        wish_list=wish_list,
        observed_list=observed_list,
        title_img=title_img,
        season=season,
        embed=embed,
        has_observations=has_observations,
    )
Пример #16
0
def dso_list_info(dso_list_id):
    """View a dso list info."""
    dso_list = _find_dso_list(dso_list_id)
    if dso_list is None:
        abort(404)

    search_form = SearchDsoListForm()
    if search_form.season.data == 'All':
        search_form.season.data = None

    if not process_session_search([
        ('dso_list_season', search_form.season),
    ]):
        return redirect(
            url_for('main_dso_list.dso_list_info',
                    dso_list_id=dso_list_id,
                    season=search_form.season.data))

    season = request.args.get('season', None)

    lang, editor_user = get_lang_and_editor_user_from_request(
        for_constell_descr=False)

    if season:
        constell_ids = set()
        for constell_id in db.session.query(
                Constellation.id).filter(Constellation.season == season):
            constell_ids.add(constell_id[0])
    else:
        constell_ids = None

    dso_list_descr = DsoListDescription.query.filter_by(
        dso_list_id=dso_list.id, lang_code=lang).first()

    observed = {
        dso.id
        for dso in ObservedList.get_observed_dsos_by_user_id(current_user.id)
    } if not current_user.is_anonymous else None

    user_descrs = {} if dso_list.show_descr_name else None
    dso_list_items = []
    for dso_list_item in dso_list.dso_list_items:
        if constell_ids is None or dso_list_item.deepskyObject.constellation_id in constell_ids:
            dso_list_items.append(dso_list_item)
            if user_descrs is not None:
                udd = UserDsoDescription.query.filter_by(
                    dso_id=dso_list_item.dso_id,
                    user_id=editor_user.id,
                    lang_code=lang).first()
                if udd and udd.common_name:
                    user_descrs[dso_list_item.dso_id] = udd.common_name
                else:
                    user_descrs[dso_list_item.
                                dso_id] = dso_list_item.deepskyObject.name

    theme = request.args.get('theme', '')
    inverted_accordion = theme in ['dark', 'night']

    return render_template('main/catalogue/dso_list_info.html',
                           dso_list=dso_list,
                           type='info',
                           dso_list_descr=dso_list_descr,
                           dso_list_items=dso_list_items,
                           user_descrs=user_descrs,
                           season=season,
                           search_form=search_form,
                           inverted_accordion=inverted_accordion,
                           observed=observed)