def trionyx(request): """Add trionyx context data""" if not hasattr(request, 'trionyx_context'): locale, *_ = utils.get_current_locale().split('_') setattr( request, 'trionyx_context', { 'DEBUG': settings.DEBUG, 'TX_APP_NAME': tx_settings.APP_NAME, 'TX_LOGO_NAME_START': tx_settings.LOGO_NAME_START, 'TX_LOGO_NAME_END': tx_settings.LOGO_NAME_END, 'TX_LOGO_NAME_SMALL_START': tx_settings.LOGO_NAME_SMALL_START, 'TX_LOGO_NAME_SMALL_END': tx_settings.LOGO_NAME_SMALL_END, 'TX_THEME_COLOR': tx_settings.THEME_COLOR, 'tx_base64_icon': tx_base64_icon, 'tx_tasks_url': model_url(get_class('trionyx.Task'), 'list'), 'tx_version': __version__, 'tx_show_changelog': (tx_settings.SHOW_CHANGELOG_NEW_VERSION and request.user.is_authenticated and request.user.get_attribute('trionyx_last_shown_version') != utils.get_app_version()), 'trionyx_menu_items': app_menu.get_menu_items(request.user), 'trionyx_menu_collapse': request.COOKIES.get('menu.state') == 'collapsed', 'tx_custom_skin_css': 'css/skins/skin-{}.min.css'.format(tx_settings.THEME_COLOR) if settings.TX_THEME_COLOR != tx_settings.THEME_COLOR else '', 'app_version': utils.get_app_version(), 'datetime_input_format': utils.datetime_format_to_momentjs( utils.get_datetime_input_format()), 'date_input_format': utils.datetime_format_to_momentjs( utils.get_datetime_input_format(date_only=True)), 'current_locale': utils.get_current_locale(), 'summernote_language': '{}-{}'.format(locale, locale.upper()), 'summernote_language_js': 'plugins/summernote/lang/summernote-{}-{}.min.js'.format( locale, locale.upper()) if locale != 'en' and utils.get_current_language() != settings.LANGUAGE_CODE else '', **offline_context()[0] }) return getattr(request, 'trionyx_context')
def __init__(self, field, **kwargs): """Init DateTimePicker""" if not self.format: self.format = get_datetime_input_format() if 'format' in kwargs: self.format = kwargs.get('format') if not self.locale: self.locale = get_current_locale() for key in self.valid_options: value = kwargs.pop(key, getattr(self, key)) if isinstance(value, bool): value = str(value).lower() kwargs['data-{}'.format(key)] = str( value if key != 'format' else datetime_format_to_momentjs(value )) # Disable autocomplete default if 'autocomplete' not in kwargs: kwargs['autocomplete'] = 'off' kwargs[ 'css_class'] = '{} datetimepicker datetimeinput form-control'.format( kwargs.get('css_class', '')).strip() super().__init__(field, **kwargs)
def offline_context(): """Offline context used by compress""" locale, *_ = utils.get_current_locale().split('_') context = { 'STATIC_URL': settings.STATIC_URL, 'tx_offline_skin_css': 'css/skins/skin-{}.min.css'.format(settings.TX_THEME_COLOR), 'apps_css_files': [], 'apps_js_files': [], 'offline_summernote_language_js': 'plugins/summernote/lang/summernote-{}-{}.min.js'.format( locale, locale.upper()) if locale != 'en' else '', } for app in apps.get_app_configs(): context['apps_css_files'].extend(getattr(app, 'css_files', [])) context['apps_js_files'].extend(getattr(app, 'js_files', [])) return [context]
def test_get_local(self): translation.activate('nl-nl') self.assertEqual('nl_NL', utils.get_current_locale())
def price_value_renderer(value, currency=None, **options): """Format price value, with current locale and CURRENCY in settings""" if not currency: currency = getattr(settings, 'CURRENCY', 'USD') return format_currency(value if value else 0.0, currency, locale=utils.get_current_locale())
def number_value_renderer(value, **options): """Format decimal value, with current locale""" return format_decimal(value if value else 0.0, locale=utils.get_current_locale())