Ejemplo n.º 1
0
 def get_locale():
     misc = db_retrieve_table(app.config['MYCODO_DB_PATH'],
                              Misc,
                              entry='first')
     if misc.language != '':
         for key, _ in LANGUAGES.iteritems():
             if key == misc.language:
                 return key
     return request.accept_languages.best_match(LANGUAGES.keys())
 def get_locale():
     misc = Misc.query.first()
     if misc and misc.language != '':
         for key in LANGUAGES:
             if key == misc.language:
                 return key
     return request.accept_languages.best_match(LANGUAGES.keys())
Ejemplo n.º 3
0
 def get_locale():
     try:
         user = User.query.filter(
             User.id == flask_login.current_user.id).first()
         if user and user.language != '':
             for key in LANGUAGES:
                 if key == user.language:
                     return key
     # Bypass endpoint test error "'AnonymousUserMixin' object has no attribute 'id'"
     except AttributeError:
         pass
     return request.accept_languages.best_match(LANGUAGES.keys())
Ejemplo n.º 4
0
 def get_locale():
     try:
         user = User.query.filter(
             User.id == flask_login.current_user.id).first()
         if user and user.language != '':
             for key in LANGUAGES:
                 if key == user.language:
                     return key
     # Bypass endpoint test error "'AnonymousUserMixin' object has no attribute 'id'"
     except AttributeError:
         pass
     return request.accept_languages.best_match(LANGUAGES.keys())
Ejemplo n.º 5
0
def inject_variables():
    """Variables to send with every page request"""
    form_dashboard = forms_dashboard.DashboardConfig(
    )  # Dashboard configuration in layout

    misc = Misc.query.first()

    try:
        if not current_app.config['TESTING']:
            control = DaemonControl()
            daemon_status = control.daemon_status()
        else:
            daemon_status = '0'
    except Exception as e:
        logger.debug("URL for 'inject_variables' raised and error: "
                     "{err}".format(err=e))
        daemon_status = '0'

    dashboards = []
    for each_dash in Dashboard.query.all():
        dashboards.append({
            'dashboard_id': each_dash.unique_id,
            'name': each_dash.name
        })

    languages_sorted = sorted(LANGUAGES.items(), key=operator.itemgetter(1))

    return dict(current_user=flask_login.current_user,
                dark_themes=THEMES_DARK,
                daemon_status=daemon_status,
                dashboards=dashboards,
                form_dashboard=form_dashboard,
                hide_alert_info=misc.hide_alert_info,
                hide_alert_success=misc.hide_alert_success,
                hide_alert_warning=misc.hide_alert_warning,
                hide_tooltips=misc.hide_tooltips,
                host=socket.gethostname(),
                languages=languages_sorted,
                mycodo_version=MYCODO_VERSION,
                permission_view_settings=user_has_permission('view_settings',
                                                             silent=True),
                dict_translation=TRANSLATIONS,
                themes=THEMES,
                upgrade_available=misc.mycodo_upgrade_available)
Ejemplo n.º 6
0
def settings_general():
    """ Display general settings """
    if not utils_general.user_has_permission('view_settings'):
        return redirect(url_for('routes_general.home'))

    misc = Misc.query.first()
    form_settings_general = forms_settings.SettingsGeneral()

    languages_sorted = sorted(LANGUAGES.items(), key=operator.itemgetter(1))

    if request.method == 'POST':
        if not utils_general.user_has_permission('edit_settings'):
            return redirect(url_for('routes_general.home'))

        form_name = request.form['form-name']
        if form_name == 'General':
            utils_settings.settings_general_mod(form_settings_general)
        return redirect(url_for('routes_settings.settings_general'))

    return render_template('settings/general.html',
                           misc=misc,
                           languages=languages_sorted,
                           form_settings_general=form_settings_general)
Ejemplo n.º 7
0
def settings_general():
    """ Display general settings """
    if not utils_general.user_has_permission('view_settings'):
        return redirect(url_for('routes_general.home'))

    misc = Misc.query.first()
    form_settings_general = forms_settings.SettingsGeneral()

    languages_sorted = sorted(LANGUAGES.items(), key=operator.itemgetter(1))

    if request.method == 'POST':
        if not utils_general.user_has_permission('edit_settings'):
            return redirect(url_for('routes_general.home'))

        form_name = request.form['form-name']
        if form_name == 'General':
            utils_settings.settings_general_mod(form_settings_general)
        return redirect(url_for('routes_settings.settings_general'))

    return render_template('settings/general.html',
                           misc=misc,
                           languages=languages_sorted,
                           form_settings_general=form_settings_general)