Beispiel #1
0
def wish_list_chart_legend_img(ra, dec):
    wish_list = WishList.create_get_wishlist_by_user_id(current_user.id)
    if wish_list is None:
        abort(404)

    img_bytes = common_chart_legend_img(
        None,
        None,
        ra,
        dec,
    )
    return send_file(img_bytes, mimetype='image/png')
Beispiel #2
0
def deepskyobject_switch_wish_list():
    dso_id = request.args.get('dso_id', None, type=int)
    dso, orig_dso = _find_dso(dso_id)
    if dso is None:
        abort(404)
    wish_list = WishList.create_get_wishlist_by_user_id(current_user.id)
    wish_list_item = WishListItem.query.filter_by(wish_list_id=wish_list.id,
                                                  dso_id=dso_id).first()
    if wish_list_item:
        db.session.delete(wish_list_item)
        db.session.commit()
        result = 'off'
    else:
        wish_list.append_new_deepsky_object(dso_id, current_user.id)
        result = 'on'
    return jsonify(result=result)
Beispiel #3
0
def wish_list_chart():
    wish_list = WishList.create_get_wishlist_by_user_id(current_user.id)
    if wish_list is None:
        abort(404)

    form = ChartForm()

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

    wish_list_item = None
    if dso_id and dso_id.isdigit():
        idso_id = int(dso_id)
        wish_list_item = next((x for x in wish_list.wish_list_items
                               if x.deepskyObject.id == idso_id), None)

    if not wish_list_item:
        wish_list_item = wish_list.wish_list_items[
            0] if wish_list.wish_list_items else None

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

    chart_control = common_prepare_chart_data(form)

    if wish_list_item:
        default_chart_iframe_url = url_for(
            'main_deepskyobject.deepskyobject_info',
            back='wishlist',
            dso_id=wish_list_item.deepskyObject.name,
            embed='fc',
            allow_back='true')
    else:
        default_chart_iframe_url = None

    return render_template(
        'main/planner/wish_list.html',
        fchart_form=form,
        type='chart',
        wish_list=wish_list,
        chart_control=chart_control,
        default_chart_iframe_url=default_chart_iframe_url,
    )
Beispiel #4
0
def wish_list_chart_pdf(ra, dec):
    wish_list = WishList.create_get_wishlist_by_user_id(current_user.id)
    if wish_list is None:
        abort(404)

    highlights_dso_list = [
        x.deepskyObject for x in wish_list.wish_list_items
        if wish_list.wish_list_items
    ]

    flags = request.args.get('json')
    visible_objects = [] if flags else None
    img_bytes = common_chart_pdf_img(None,
                                     None,
                                     ra,
                                     dec,
                                     highlights_dso_list=highlights_dso_list)

    return send_file(img_bytes, mimetype='application/pdf')
Beispiel #5
0
def wish_list_item_add():
    """Add item to wish list."""
    form = AddToWishListForm()
    dso_name = normalize_dso_name(form.dso_name.data)
    if request.method == 'POST' and form.validate_on_submit():
        deepsky_object = DeepskyObject.query.filter(
            DeepskyObject.name == dso_name).first()
        if deepsky_object:
            wish_list = WishList.create_get_wishlist_by_user_id(
                current_user.id)
            if wish_list.append_deepsky_object(deepsky_object.id,
                                               current_user.id):
                flash('Object was added to wishlist.', 'form-success')
            else:
                flash('Object is already on wishlist.', 'form-info')
        else:
            flash('Deepsky object not found.', 'form-error')

    return redirect(url_for('main_wishlist.wish_list_info'))
Beispiel #6
0
def wish_list_info():
    """View wish list."""
    add_form = AddToWishListForm()

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

    if not process_session_search([
        ('wish_list_season', search_form.season),
    ]):
        return redirect(
            url_for('main_wishlist.wish_list_info',
                    season=search_form.season.data))

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

    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

    wish_list = WishList.create_get_wishlist_by_user_id(current_user.id)

    wish_list_items = []

    if constell_ids:
        for item in wish_list.wish_list_items:
            if item.deepskyObject and item.deepskyObject.constellation_id in constell_ids:
                wish_list_items.append(item)
    else:
        wish_list_items = wish_list.wish_list_items

    return render_template('main/planner/wish_list.html',
                           type='info',
                           wish_list_items=wish_list_items,
                           season=season,
                           search_form=search_form,
                           add_form=add_form)
Beispiel #7
0
def wish_list_chart_pos_img(ra, dec):
    wish_list = WishList.create_get_wishlist_by_user_id(current_user.id)
    if wish_list is None:
        abort(404)

    highlights_dso_list = [
        x.deepskyObject for x in wish_list.wish_list_items
        if wish_list.wish_list_items
    ]

    flags = request.args.get('json')
    visible_objects = [] if flags else None
    img_bytes = common_chart_pos_img(None,
                                     None,
                                     ra,
                                     dec,
                                     visible_objects=visible_objects,
                                     highlights_dso_list=highlights_dso_list)
    if visible_objects is not None:
        img = base64.b64encode(img_bytes.read()).decode()
        return jsonify(img=img, img_map=visible_objects)
    else:
        return send_file(img_bytes, mimetype='image/png')
Beispiel #8
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,
    )
Beispiel #9
0
def wishlist(id):
    f = id
    wishlist = WishList.query.filter_by(owner=id).all()
    if request.method == 'POST' and 'User-Agent' not in request.headers:
        url = request.form['url']
        title = request.form['title']
        description = request.form['description']
        url = request.form['url']
        thumbnail = request.form['thumbnail']
        user = Users.query.filter_by(id=id).first()
        if user:
            new_wish = WishList(id, title, description, url, thumbnail)
            db.session.add(new_wish)
            db.session.commit()
            wlst = []
            wishlist = WishList.query.filter_by(owner=id).all()
            for wish_ in wishlist:
                wlst.append({'title':wish_.title, 'description':wish_.description, 'url':wish_.url, 'thumbnail':wish_.thumbnail})
            resp = ({'error':'null', 'data':{'wishes': wlst}, 'message':'success'})
            return jsonify(resp)
        return jsonify({'error':'1', 'data':'', 'message':'no such wishlist exists'})
    
    if request.method == 'GET' and 'User-Agent' not in request.headers:
        user = Users.query.filter_by(id=id).first()
        if user:
            wishlist = WishList.query.filter_by(owner=id).all()
            wlst = []
            for wish_ in wishlist:
                wlst.append({'title':wish_.title, 'description':wish_.description, 'url':wish_.url, 'thumbnail':wish_.thumbnail})
            resp = ({'error':'null', 'data':{'wishes': wlst}, 'message':'success'})
            return jsonify(resp)
        return jsonify({'error':'1', 'data':'', 'message':'no such wishlist exists'})
    
    form = WishForm()
    e_form = SendEmailForm()
    if request.method == 'POST' and 'User-Agent' in request.headers:
        if len(request.form) == 1:
            # print "hello world  "
            try:
                url = request.form['url']
                choice = process_(url)
                return "{}".format(choice)
            except Exception as e:
                try:
                    wish = request.form['wish']
                    db.session.execute("DELETE FROM wish_list WHERE thumbnail=\'"+ wish + "\'")
                    db.session.commit()
                except Exception as d:
                    print "Unexpected error:", sys.exc_info()[0]
                    raise
        
            return render_template(
                    'wishlist.html',
                    title='Wishlist',
                    year=datetime.datetime.now().year,
                    f=f,
                    form=form,
                    user=g.user
                )

        if len(request.form) == 3:
            # print "2"
            addr = request.form['email']
            toaddr = addr.replace(" ","").split(",")
            fromname = g.user.name
            fromaddr = g.user.email
            subject = g.user.name + "'s Wishlist"
            msg = "Hey! Check out my Wishlist at " + request.url
            
            messagetosend = Message(subject=subject, sender=fromaddr, recipients=toaddr, body=msg)
            mail.send(messagetosend)
            
            return render_template(
                'wishlist.html',
                title='Wishlist',
                year=datetime.datetime.now().year,
                f=f,
                wishlist=wishlist,
                form=form,
                e_form = e_form,
                user=g.user
            )

        if form.validate_on_submit():
            title = request.form['title']
            descr = request.form['description']
            url = request.form['url']
            thumb = request.form['thumbnail']
            user = Users.query.filter_by(id=id).first()
            if user:
                new_wish = WishList(id, title, descr, url, thumb)
                db.session.add(new_wish)
                db.session.commit()
                wishlist_ = WishList.query.filter_by(owner=id).all()
                return render_template(
                    'wishlist.html',
                    title='Wishlist',
                    year=datetime.datetime.now().year,
                    f=f,
                    form=form,
                    wishlist=wishlist_,
                    e_form = e_form,
                    user=g.user
                )
    
    return render_template(
        'wishlist.html',
        title='Wishlist',
        year=datetime.datetime.now().year,
        f=f,
        wishlist=wishlist,
        form=form,
        e_form = e_form,
        user=g.user
    )
Beispiel #10
0
def _get_prev_next_dso(dso):
    back = request.args.get('back')
    back_id = request.args.get('back_id')

    has_item = False
    next_item = None

    if back == 'observation':
        observing_session = ObservingSession.query.filter_by(
            id=back_id).first()
        if observing_session and (observing_session.is_public
                                  or observing_session.user_id
                                  == current_user.id):
            prev_item, next_item = observing_session.get_prev_next_item(dso.id)
            return (
                prev_item,
                prev_item.denormalized_name() if prev_item else None,
                next_item,
                next_item.denormalized_name() if next_item else None,
            )
    elif back == 'stobservation':
        pass
    elif back == 'constell_dso':
        constell_dsos = DeepskyObject.query.filter_by(constellation_id=dso.constellation_id, master_id=None) \
                                           .order_by(DeepskyObject.mag) \
                                           .all()
        num_dsos = len(constell_dsos)
        for dso_idx in range(num_dsos):
            constell_dso = constell_dsos[dso_idx]
            if constell_dso.id == dso.id:
                prev_item, next_item = None, None
                if dso_idx > 0:
                    prev_item = constell_dsos[dso_idx - 1]
                if dso_idx < num_dsos - 1:
                    next_item = constell_dsos[dso_idx + 1]
                return (
                    prev_item,
                    prev_item.denormalized_name() if prev_item else None,
                    next_item,
                    next_item.denormalized_name() if next_item else None,
                )
    elif back == 'wishlist':
        if current_user.is_authenticated:
            wish_list = WishList.create_get_wishlist_by_user_id(
                current_user.id)
            prev_item, next_item = wish_list.get_prev_next_item(
                dso.id, _get_season_constell_ids())
            has_item = True
    elif back == 'observed_list':
        if current_user.is_authenticated:
            observed_list = ObservedList.create_get_observed_list_by_user_id(
                current_user.id)
            prev_item, next_item = observed_list.get_prev_next_item(
                dso.id, _get_season_constell_ids())
            has_item = True
    elif back == 'session_plan':
        session_plan = SessionPlan.query.filter_by(id=back_id).first()
        if _allow_view_session_plan(session_plan):
            prev_item, next_item = session_plan.get_prev_next_item(
                dso.id, _get_season_constell_ids())
            has_item = True
    elif back == 'dso_list' and not (back_id is None):
        dso_list = DsoList.query.filter_by(id=back_id).first()
        if dso_list:
            prev_item, next_item = dso_list.get_prev_next_item(
                dso.id, _get_season_constell_ids())
            return (
                prev_item.deepskyObject if prev_item else None,
                prev_item.item_id if prev_item else None,
                next_item.deepskyObject if next_item else None,
                next_item.item_id if next_item else None,
            )
    elif back == 'running_plan':
        observation_plan_run = ObsSessionPlanRun.query.filter_by(
            id=back_id).first()
        if observation_plan_run and _allow_view_session_plan(
                observation_plan_run.session_plan):
            prev_item, next_item = observation_plan_run.session_plan.get_prev_next_item(
                dso.id, _get_season_constell_ids())
            has_item = True

    if has_item:
        return (
            prev_item.deepskyObject if prev_item else None,
            prev_item.deepskyObject.denormalized_name() if prev_item else None,
            next_item.deepskyObject if next_item else None,
            next_item.deepskyObject.denormalized_name() if next_item else None,
        )

    prev_dso, next_dso = dso.get_prev_next_dso()
    return (prev_dso, prev_dso.catalog_number() if prev_dso else None,
            next_dso, next_dso.catalog_number() if next_dso else None)
Beispiel #11
0
def deepskyobject_chart_pos_img(dso_id, ra, dec):
    dso, orig_dso = _find_dso(dso_id)
    if dso is None:
        abort(404)

    flags = request.args.get('json')
    visible_objects = [] if flags else None

    highlights_dso_list = None

    back = request.args.get('back')
    back_id = request.args.get('back_id')

    if back == 'dso_list' and back_id is not None:
        dso_list = DsoList.query.filter_by(id=back_id).first()
        if dso_list:
            highlights_dso_list = [
                x.deepskyObject for x in dso_list.dso_list_items if dso_list
            ]
    elif back == 'wishlist' and current_user.is_authenticated:
        wish_list = WishList.create_get_wishlist_by_user_id(current_user.id)
        highlights_dso_list = [
            x.deepskyObject for x in wish_list.wish_list_items
            if wish_list.wish_list_items
        ]
    elif back == 'session_plan':
        session_plan = SessionPlan.query.filter_by(id=back_id).first()
        if _allow_view_session_plan(session_plan):
            highlights_dso_list = [
                x.deepskyObject for x in session_plan.session_plan_items
                if session_plan
            ]
    elif back == 'observation':
        observing_session = ObservingSession.query.filter_by(
            id=back_id).first()
        if observing_session and (observing_session.is_public
                                  or observing_session.user_id
                                  == current_user.id):
            highlights_dso_list = []
            for observation in observing_session.observations:
                highlights_dso_list.extend(observation.deepsky_objects)
    elif back == 'observed_list' and current_user.is_authenticated:
        observed_list = ObservedList.create_get_observed_list_by_user_id(
            current_user.id)
        highlights_dso_list = [
            x.deepskyObject for x in observed_list.observed_list_items
            if observed_list.observed_list_items
        ]
    elif back == 'running_plan' and back_id is not None:
        observation_plan_run = ObsSessionPlanRun.query.filter_by(
            id=back_id).first()
        if observation_plan_run and _allow_view_session_plan(
                observation_plan_run.session_plan):
            highlights_dso_list = [
                x.deepskyObject
                for x in observation_plan_run.session_plan.session_plan_items
            ]

    img_bytes = common_chart_pos_img(dso.ra,
                                     dso.dec,
                                     ra,
                                     dec,
                                     dso_names=(dso.name, ),
                                     visible_objects=visible_objects,
                                     highlights_dso_list=highlights_dso_list)

    if visible_objects is not None:
        img = base64.b64encode(img_bytes.read()).decode()
        return jsonify(img=img, img_map=visible_objects)
    else:
        return send_file(img_bytes, mimetype='image/png')