def application_translations(): from models.translation import Translation from helpers.account import AccountHelper language = AccountHelper.getPreference('language') data = dict([(translation.name, translation.value) for translation in Translation.query.filter_by(language=language).all()]) return Response(json.dumps({'status':200, 'description':'OK', 'data':data, 'errors':[]}), mimetype='application/json')
def profile_preferences(account_id): from models.account import Account, Preference from helpers.account import AccountHelper account_id = urllib.unquote_plus(account_id) account = Account.query.filter_by(id=account_id).first() if not account: abort(404) elif not app.access('profile', action='update', account=account): abort(403) preferences = { 'language': None, 'floats_format': None, 'report_time_format': None, 'show_deleted_reports': None, 'datepicker_multiple_days': None, 'show_chinese_cookie': None } for key in preferences.keys(): preference = Preference.query.filter_by(account_id=account.id, name=key).first() if not preference: preference = Preference() preference.account_id = account.id preference.name = key preference.value = AccountHelper.getPreference(key) preferences[key] = preference title = g._t('profile preferences') breadcrumbs = ( (((not app.access('authenticated', account=account)) and g._t('employees') or ''), url_for('profile_employees')), ((app.access('authenticated', account=account) and g._t('me') or account.__str__()), url_for('profile_view', account_id=account_id)), (title, "#") ) validationErrors = [] if request.method == 'POST' and request.form.get('csrf_token'): for key, preference in preferences.items(): preference.raw_value = request.form.get('preference_'+key, None) errors = preference.validate() validationErrors.extend(errors) if not errors: preference.save() if not validationErrors: flash( g._t('preference update success')) else: flash( g._t('preference update error'), 'error') return redirect(url_for('profile_preferences', account_id=urllib.quote_plus(account_id))) return render_template('profile/preferences.html', account_id=account_id, account=account, preferences=preferences, title=title, breadcrumbs=breadcrumbs, errors=validationErrors)
def _t(name, language=None, nodefault=False): from models.translation import Translation from helpers.account import AccountHelper if not language: language = AccountHelper.getPreference('language') translation = Translation.query.filter_by(name=name, language=language).first() if translation: return translation.value else: return (nodefault == False) and ':'+name or None
def _get_preference(name): from helpers.account import AccountHelper return AccountHelper.getPreference(name)