Beispiel #1
0
def afficher_nouvelle_situation_patient():
    form = NewSituationEntry()
    # print("request.form", request.form)
    # print("form.data", form.data)
    # print("form.errors", form.errors)
    if request.method == "POST":
        if form.validate_on_submit():
            situation = dm.Situation()

            situation.from_view_to_data(request.form)
            patient = sm.PatientSess(session["pseudo_patient"])
            patient.enregistrer_entree_situation(situation)
            form.message_succes = lazy_gettext(
                "La situation est correctement enregistrée")
            maintenant = DateHeure()
            maintenant.from_datetime(to_user_timezone(datetime.datetime.now()))
            flash(lazy_gettext("La situation est bien enregistrée"))
            return redirect(url_for("main.afficher_menu_entrees_patient"))
        else:
            flash(
                lazy_gettext("Il y a au moins une erreur dans le formulaire"))
            return redirect(
                url_for("main.afficher_nouvelle_situation_patient"))

    maintenant = DateHeure()
    maintenant.from_datetime(to_user_timezone(datetime.datetime.now()))
    return render_template("patient/entrees/entry_situation_form.html",
                           form=form,
                           maintenant=maintenant)
Beispiel #2
0
def creation_nouvelle_fiche_activite_physique():
    form = NewPhysicalActivity()
    if request.method == "POST":
        if form.validate_on_submit():
            ap = dm.ActivitePhysique()
            ap.from_view_to_data(request.form)
            patient = sm.PatientSess(session["pseudo_patient"])
            patient.enregistrer_entree_activite_physique(ap)
            maintenant = DateHeure()
            maintenant.from_datetime(to_user_timezone(datetime.datetime.now()))
            flash(
                lazy_gettext(
                    "La fiche activité physique a bien été enregistrée."))
            return redirect(url_for("main.afficher_menu_entrees_patient"))
        else:
            flash(
                lazy_gettext("Il y a au moins une erreur dans le formulaire"))
            return redirect(
                url_for("main.creation_nouvelle_fiche_activite_physique"))

    maintenant = DateHeure()
    maintenant.from_datetime(to_user_timezone(datetime.datetime.now()))
    return render_template("patient/entrees/nouvelle_activite_physique.html",
                           form=form,
                           maintenant=maintenant)
Beispiel #3
0
def creation_nouvelle_fiche_poids():
    form = NewWeightEntry()
    if request.method == "POST":
        if form.validate_on_submit():
            masse = dm.Masse()
            masse.from_view_to_data(request.form)
            patient = sm.PatientSess(session["pseudo_patient"])
            patient.enregistrer_poids(masse)
            maintenant = DateHeure()
            maintenant.from_datetime(to_user_timezone(datetime.datetime.now()))
            flash(lazy_gettext("La fiche poids a bien été enregistrée."))
            return redirect(url_for("main.afficher_menu_entrees_patient"))
        else:
            flash(
                lazy_gettext("Il y a au moins une erreur dans le formulaire " +
                             "\n".join([
                                 "\t\n".join(form.errors[kind])
                                 for kind in form.errors
                             ])))
            return redirect(url_for("main.creation_nouvelle_fiche_poids"))

    maintenant = DateHeure()
    maintenant.from_datetime(to_user_timezone(datetime.datetime.now()))
    return render_template("patient/entrees/nouvelle_entree_poids.html",
                           form=form,
                           maintenant=maintenant)
Beispiel #4
0
def creation_nouvelle_fiche_sommeil():
    form = NewSleepEntry()
    if request.method == "POST":
        if form.validate_on_submit():
            sommeil = dm.Sommeil()
            sommeil.from_new_webview(request.form)
            patient = sm.PatientSess(session["pseudo_patient"])
            patient.enregistrer_entree_sommeil(sommeil)

            maintenant = DateHeure()
            maintenant.from_datetime(to_user_timezone(datetime.datetime.now()))

            date_heure_evenement = DateHeure()
            date_heure_evenement.from_datetime(
                to_user_timezone(datetime.datetime.now()))
            flash(lazy_gettext("La fiche sommeil a bien été enregistrée."))
            return redirect(url_for("main.afficher_menu_entrees_patient"))
        else:
            flash(
                lazy_gettext("Il y a au moins une erreur dans le formulaire"))
            return redirect(url_for("main.creation_nouvelle_fiche_sommeil"))

    maintenant = DateHeure()
    maintenant.from_datetime(to_user_timezone(datetime.datetime.now()))
    date_heure_evenement = DateHeure()
    date_heure_evenement.from_datetime(
        to_user_timezone(datetime.datetime.now()))
    return render_template("patient/entrees/nouvelle_entree_sommeil.html",
                           message="",
                           maintenant=maintenant,
                           date_heure_evenement=date_heure_evenement,
                           form=form)
Beispiel #5
0
def creation_nouvelle_fiche_alimentation():
    form = NewFoodEntry()
    if request.method == "POST":
        if form.validate_on_submit():

            alim = dm.Alimentation()
            alim.from_view_to_data(request.form)
            patient = sm.PatientSess(session["pseudo_patient"])
            patient.enregistrer_entree_repas(alim)
            maintenant = DateHeure()
            maintenant.from_datetime(to_user_timezone(datetime.datetime.now()))
            flash("La fiche repas a bien été enregistrée.")
            return redirect(url_for("main.afficher_menu_entrees_patient"))
            # return jsonify({"date_heure": request.form["date_heure"], "enrepas": request.form["enregistrement_repas"],
            #                 "nourriture": request.form["nourriture"], "repas": request.form["repas"]})
        else:
            flash(
                lazy_gettext("Il y a au moins une erreur dans le formulaire"))
            return redirect(
                url_for("main.creation_nouvelle_fiche_alimentation"))

    maintenant = DateHeure()
    maintenant.from_datetime(to_user_timezone(datetime.datetime.now()))
    return render_template("patient/entrees/nouvelle_entree_alimentation.html",
                           form=form,
                           maintenant=maintenant)
Beispiel #6
0
def now_playing():
    try:
        ret = {}
        #gather showinfos
        show = Show.get_active_show()
        if show:
            user = show.get_active_user()
            if show.end:
                end = int(to_user_timezone(show.end).strftime("%s")) * 1000
            else:
                end = None
            ret['show'] = {
                'id': show.show,
                'name': show.name,
                'begin':
                int(to_user_timezone(show.begin).strftime("%s")) * 1000,
                'now': int(to_user_timezone(now()).strftime("%s")) * 1000,
                'end': end,
                'logo': show.get_logo(),
                'type': Show.FLAGS.name(show.flags),
                'user': {
                    'countryball': iso_country_to_countryball(user.country)
                }
            }
            if show.series:
                ret['series'] = {'name': show.series.name}
            link_users = []
            for ushow in show.users:
                link_users.append(make_user_link(ushow.user))
            ret['users'] = {'links': natural_join(link_users)}

        #gather nextshow infos
        if show and show.end:
            filter_begin = show.end
        else:
            filter_begin = now()
        if request.args.get('full') == 'true':
            nextshow = Show.query.filter(Show.begin >= filter_begin).order_by(
                Show.begin.asc()).first()
            if nextshow:
                ret['nextshow'] = {
                    'name':
                    nextshow.name,
                    'begin':
                    int(to_user_timezone(nextshow.begin).strftime("%s")) *
                    1000,
                    'logo':
                    nextshow.get_logo()
                }
                if nextshow.series:
                    ret['nextshow']['series'] = nextshow.series.name
        return jsonify({'success': True, 'data': ret})
    except Exception as e:
        raise e
        return jsonify({'success': False, 'data': unicode(e)})
Beispiel #7
0
def get_date(date):
    babel = Babel(app)
    date = str(date)
    date_format = '%Y-%m-%d %H:%M:%S'
    date = datetime.strptime(date, date_format)
    date = to_user_timezone(date)
    return datetime.strftime(date, '%B %-d, %Y')
Beispiel #8
0
def before_request():
    """ before request """
    g.user = get_user()

    date_time_zone_now = flask_babel.to_user_timezone(datetime.now())
    g.date = format_datetime(date_time_zone_now,
                             locale=str(flask_babel.get_locale()))
Beispiel #9
0
def get_date(date):
    babel = Babel(app)
    date = str(date)
    date_format = '%Y-%m-%d %H:%M:%S'
    date = datetime.strptime(date, date_format)
    date = to_user_timezone(date)
    return datetime.strftime(date, '%B %-d, %Y')
Beispiel #10
0
def now_playing():
    try:
        ret = {}
        #gather showinfos
        show = Show.get_active_show()
        if show:
            user = show.get_active_user()
            if show.end:
                end = int(to_user_timezone(show.end).strftime("%s")) * 1000
            else:
                end = None
            ret['show'] = {'id': show.show,
                           'name': show.name,
                           'begin': int(to_user_timezone(show.begin).strftime("%s")) * 1000,
                           'now': int(to_user_timezone(now()).strftime("%s")) * 1000,
                           'end': end,
                           'logo': show.get_logo(),
                           'type': Show.FLAGS.name(show.flags),
                           'user': {'countryball': iso_country_to_countryball(user.country)}
            }
            if show.series:
                ret['series'] = {'name': show.series.name}
            link_users = []
            for ushow in show.users:
                link_users.append(make_user_link(ushow.user))
            ret['users'] = {'links': natural_join(link_users)}


        #gather nextshow infos
        if show and show.end:
            filter_begin = show.end
        else:
            filter_begin = now()
        if request.args.get('full') == 'true':
            nextshow = Show.query.filter(Show.begin >= filter_begin).order_by(Show.begin.asc()).first();
            if nextshow:
                ret['nextshow'] = {'name': nextshow.name,
                                   'begin': int(to_user_timezone(nextshow.begin).strftime("%s")) * 1000,
                                   'logo': nextshow.get_logo()}
                if nextshow.series:
                    ret['nextshow']['series'] = nextshow.series.name
        return jsonify({'success': True, 'data': ret})
    except Exception as e:
        raise e
        return jsonify({'success': False, 'data': unicode(e)})
Beispiel #11
0
def get_local_datetime(date_time):
    babel = Babel(app)
    date_time = str(date_time)
    date_time_format = '%Y-%m-%d %H:%M:%S'
    try:
        date_time = datetime.strptime(date_time, date_time_format)
        date_time = to_user_timezone(date_time)
        return datetime.strftime(date_time, '%B %-d, %Y - %I:%M:%S %p')
    except:
        return 'None'
Beispiel #12
0
def get_local_datetime(date_time):
    babel = Babel(app)
    date_time = str(date_time)
    date_time_format = '%Y-%m-%d %H:%M:%S'
    try:
        date_time = datetime.strptime(date_time, date_time_format)
        date_time = to_user_timezone(date_time)
        return datetime.strftime(date_time, '%B %-d, %Y - %I:%M:%S %p')
    except:
        return 'None'
Beispiel #13
0
def timesince(dt, reverse=False):
    """Convert a timestamp to a textual string describing "how much time ago".

    The parameter `dt` is a :class:`datetime.datetime` instance without
    timezone info (e.g. `tzinfo=None`).

    Original author: Dan Jacob
    URL: http://flask.pocoo.org/snippets/33/
    License: Public Domain
    """

    default = _(u'now')

    user_dt = to_user_timezone(dt)
    now_dt = to_user_timezone(datetime.utcnow())

    if reverse:
        diff = user_dt - now_dt
    else:
        diff = now_dt - user_dt

    periods = (
        (diff.days / 365, _(u'year'), _(u'years')),
        (diff.days / 30, _(u'month'), _(u'months')),
        (diff.days / 7, _(u'week'), _(u'weeks')),
        (diff.days, _(u'day'), _(u'days')),
        (diff.seconds / 3600, _(u'hour'), _(u'hours')),
        (diff.seconds / 60, _(u'minute'), _(u'minutes')),
        (diff.seconds, _(u'second'), _(u'seconds')),
    )

    for period, singular, plural in periods:
        if period:
            if period == 1:
                timestr = singular
            else:
                timestr = plural
            if reverse:
                return _("%(num)s %(time)s", num=period, time=timestr)
            else:
                return _("%(num)s %(time)s ago", num=period, time=timestr)

    return default
Beispiel #14
0
def timesince(dt, default=None):
    """Convert a timestamp to a textual string describing "how much time ago".

    The parameter `dt` is a :class:`datetime.datetime` instance without
    timezone info (e.g. `tzinfo=None`).

    Original author: Dan Jacob
    URL: http://flask.pocoo.org/snippets/33/
    License: Public Domain
    """

    if default is None:
        default = _("now")

    user_dt = to_user_timezone(dt)
    now_dt = to_user_timezone(datetime.utcnow())

    diff = now_dt - user_dt

    periods = (
        (diff.days // 365, _("year"), _("years")),
        (diff.days // 30, _("month"), _("months")),
        (diff.days // 7, _("week"), _("weeks")),
        (diff.days, _("day"), _("days")),
        (diff.seconds // 3600, _("hour"), _("hours")),
        (diff.seconds // 60, _("minute"), _("minutes")),
        (diff.seconds, _("second"), _("seconds")),
    )

    for period, singular, plural in periods:
        if period:
            if period == 1:
                timestr = singular
            else:
                timestr = plural
            return _("%(num)s %(time)s ago", num=period, time=timestr)

    return default
Beispiel #15
0
def creation_nouvelle_fiche_pm():
    form = NewTakenPill()
    if request.method == "POST":
        if form.validate_on_submit():
            pm = dm.PriseMedicament()
            pm.from_view_to_data(request.form)
            patient = sm.PatientSess(session["pseudo_patient"])
            patient.enregistrer_entree_prise_medicament(pm)
            maintenant = DateHeure()
            maintenant.from_datetime(to_user_timezone(datetime.datetime.now()))
            flash(
                lazy_gettext("La prise de médicament a bien été enregistrée."))
            return redirect(url_for("main.afficher_menu_entrees_patient"))
        else:
            flash(
                lazy_gettext("Il y a au moins une erreur dans le formulaire"))
            return redirect(url_for("main.creation_nouvelle_fiche_pm"))

    maintenant = DateHeure()
    maintenant.from_datetime(to_user_timezone(datetime.datetime.now()))
    return render_template(
        "patient/entrees/nouvelle_entree_prise_medicament.html",
        form=form,
        maintenant=maintenant)
Beispiel #16
0
def filter_to_user_timezone(dt):
    """Convert a datetime object to the user’s timezone."""
    return to_user_timezone(dt)
Beispiel #17
0
def api_legacy():
    '''lazy people...'''

    apikey = request.args.get("apikey")
    if apikey != '86c6c5162aa6845906cff55320ea8608991358c3':
        return ''

    #ltid=0&w=track%2Clistener%2Cdj%2Cshow%2Cnextshows,
    ret = {}
    listeners = Listener.query.filter(Listener.disconnect == None).all()
    tmp = {}
    for listener in listeners:
        if listener.stream_relay.stream.code in tmp:
            tmp[listener.stream_relay.stream.code]['c'] += 1
        else:
            tmp[listener.stream_relay.stream.code] = {
                'c': 1,
                'name': listener.stream_relay.stream.code,
                'description': listener.stream_relay.stream.name
            }
    ret['listener'] = tmp.values()

    currtrack = Track.current_track()
    ltid = request.args.get("apikey")
    if currtrack and ltid != currtrack.track:
        ret['trackid'] = currtrack.track
        ret['title'] = currtrack.title.name
        ret['artist'] = currtrack.title.artist.name

    show = Show.get_active_show()
    if show:
        user = show.get_active_user()
        ret['dj'] = user.username
        ret['djid'] = user.user
        ret['status'] = 'STREAMING'
        ret['showbegin'] = int(to_user_timezone(show.begin).strftime("%s"))
        if show.end:
            ret['showend'] = int(to_user_timezone(show.end).strftime("%s"))
        else:
            ret['showend'] = None
        ret['showtype'] = 'PLANNED'
        ret['showname'] = show.name
        ret['showdescription'] = show.description
        ret['showid'] = show.show
        ret['showthread'] = None
        ret['showdj'] = user.username
        ret['showdjid'] = user.user

    ret['shows'] = []
    if show and show.end:
        filter_begin = show.end
    else:
        filter_begin = now()
    nextshow = Show.query.filter(Show.begin >= filter_begin).order_by(
        Show.begin.asc()).first()
    if nextshow:
        arr = {}
        arr['showbegin'] = int(to_user_timezone(nextshow.begin).strftime("%s"))
        if nextshow.end:
            arr['showend'] = int(to_user_timezone(nextshow.end).strftime("%s"))
        else:
            arr['showend'] = None
        arr['showtype'] = 'PLANNED'
        arr['showname'] = nextshow.name
        arr['showdescription'] = nextshow.description
        arr['showid'] = nextshow.show
        arr['showdj'] = nextshow.users[0].user.username
        arr['showdjid'] = nextshow.users[0].user.user
        arr['showthread'] = None
        ret['shows'].append(arr)

    return jsonify(ret)
Beispiel #18
0
def api_legacy():
    '''lazy people...'''

    apikey = request.args.get("apikey")
    if apikey != '86c6c5162aa6845906cff55320ea8608991358c3':
        return ''

    #ltid=0&w=track%2Clistener%2Cdj%2Cshow%2Cnextshows,
    ret = {}
    listeners = Listener.query.filter(Listener.disconnect == None).all()
    tmp = {}
    for listener in listeners:
        if listener.stream_relay.stream.code in tmp:
            tmp[listener.stream_relay.stream.code]['c'] += 1
        else:
            tmp[listener.stream_relay.stream.code] = {'c': 1,
                                                      'name': listener.stream_relay.stream.code,
                                                      'description': listener.stream_relay.stream.name}
    ret['listener'] = tmp.values()

    currtrack = Track.current_track()
    ltid = request.args.get("apikey")
    if currtrack and ltid != currtrack.track:
        ret['trackid'] = currtrack.track
        ret['title'] = currtrack.title.name
        ret['artist'] = currtrack.title.artist.name

    show = Show.get_active_show()
    if show:
        user = show.get_active_user()
        ret['dj'] = user.username
        ret['djid'] = user.user
        ret['status'] = 'STREAMING'
        ret['showbegin'] = int(to_user_timezone(show.begin).strftime("%s"))
        if show.end:
            ret['showend'] = int(to_user_timezone(show.end).strftime("%s"))
        else:
            ret['showend'] = None
        ret['showtype'] = 'PLANNED';
        ret['showname'] = show.name
        ret['showdescription'] = show.description
        ret['showid'] = show.show
        ret['showthread'] = None;
        ret['showdj'] = user.username
        ret['showdjid'] = user.user

    ret['shows'] = []
    if show and show.end:
        filter_begin = show.end
    else:
        filter_begin = now()
    nextshow = Show.query.filter(Show.begin >= filter_begin).order_by(Show.begin.asc()).first()
    if nextshow:
        arr = {}
        arr['showbegin'] = int(to_user_timezone(nextshow.begin).strftime("%s"))
        if nextshow.end:
            arr['showend'] = int(to_user_timezone(nextshow.end).strftime("%s"))
        else:
            arr['showend'] = None
        arr['showtype'] = 'PLANNED';
        arr['showname'] = nextshow.name;
        arr['showdescription'] = nextshow.description;
        arr['showid'] = nextshow.show;
        arr['showdj'] = nextshow.users[0].user.username;
        arr['showdjid'] = nextshow.users[0].user.user;
        arr['showthread'] = None;
        ret['shows'].append(arr)

    return jsonify(ret)
Beispiel #19
0
def filter_to_user_timezone(dt):
    """Convert a datetime object to the user's timezone."""
    return to_user_timezone(dt)
def before_request():
    """Uses get_user to find a user if any"""
    g.user = get_user()
    time = to_user_timezone(datetime.now())
    g.time = format_datetime(time, locale=str(get_locale()))
Beispiel #21
0
def to_local_time(t):
    return to_user_timezone(t).replace(tzinfo=None)