def get_options(optionset_label, current_only=True, as_stored=False): """ Return all options for this app_label as dictionary with the option name being the key. """ #Hit the cache cached = {} if ls.ADMIN_CACHE_DB_OPTIONS: cached = cache.get(get_option_cache_key(optionset_label), {}) if cached: options = cached else: options = AppOption.objects.filter(optionset_label=optionset_label) if ls.ADMIN_CACHE_DB_OPTIONS: cache.set(get_option_cache_key(optionset_label), options, ls.ADMIN_CACHE_DB_OPTIONS) optionset_admin = admin_site.get_optionset_admin(optionset_label) option_dict = {} for option in options: option_dict[force_str(option.name)] = get_option_value(optionset_admin, option, current_only, as_stored) return option_dict
def get_context_data(self, **kwargs): from yawdadmin import admin_site context = super(AppOptionView, self).get_context_data(**kwargs) context['optionset_admin'] = admin_site.get_optionset_admin( self.kwargs['optionset_label'])(**self.get_form_kwargs()) context['title'] = '%s' % (unicode( context['optionset_admin'].verbose_name)) return context
def get_option(optionset_label, name, current_only=True): """ Return the value of an option. """ try: option = AppOption.objects.get(optionset_label=optionset_label, name=name) except AppOption.DoesNotExist: return None optionset_admin = admin_site.get_optionset_admin(optionset_label) return get_option_value(optionset_admin, option, current_only)
def get_option(optionset_label, name, current_only=True): """ Return the value of an option. The ``current only`` kwarg affects only language-dependant options and decides whether to return its value for all languages or only the current language. """ try: option = AppOption.objects.get(optionset_label=optionset_label, name=name) except AppOption.DoesNotExist: return None optionset_admin = admin_site.get_optionset_admin(optionset_label) return get_option_value(optionset_admin, option, current_only)
def get_options(optionset_label, current_only=True): """ Return all options for this app_label as dictionary with the option name being the key. """ try: options = AppOption.objects.filter(optionset_label=optionset_label) except: return {} optionset_admin = admin_site.get_optionset_admin(optionset_label) option_dict = {} for option in options: option_dict[smart_str(option.name)] = get_option_value(optionset_admin, option, current_only) return option_dict
def get_options(optionset_label, current_only=True): """ Return all options for this app_label as dictionary with the option name being the key. """ try: options = AppOption.objects.filter(optionset_label=optionset_label) except: return {} optionset_admin = admin_site.get_optionset_admin(optionset_label) option_dict = {} for option in options: option_dict[smart_str(option.name)] = get_option_value( optionset_admin, option, current_only) return option_dict
def get_context_data(self, **kwargs): from yawdadmin import admin_site context = super(AppOptionView, self).get_context_data(**kwargs) context['optionset_admin'] = admin_site.get_optionset_admin(self.kwargs['optionset_label'])(**self.get_form_kwargs()) context['title'] = '%s' % (unicode(context['optionset_admin'].verbose_name)) return context