diff --git a/idioticon/config.py b/idioticon/config.py deleted file mode 100644 index 759352f..0000000 --- a/idioticon/config.py +++ /dev/null @@ -1,79 +0,0 @@ -import sys -from xml.etree.ElementTree import Element -from django.core.exceptions import ImproperlyConfigured - - -PY3 = sys.version_info[0] == 3 - -if PY3: - string_types = str, - unicode = str -else: - string_types = basestring, - -# Setup default configurations -IDIOTICON_DEFAULTS = { - 'TEXT_FIELD': 'django.db.models.TextField', - 'KEY_LENGTH': 255, - 'TITLE_LENGTH': 255, - 'CACHE': 'default', - 'CACHE_KEY_PREFIX': 'term-', - 'THEME': 'plain', - 'CONTEXT_LOADER': '', -} - -class Theme(object): - - icon = None - symbol = '' - wrapper = 'span' - - def render(self, symbol=None, wrapper=None, icon=None): - wrapper = self.wrapper if wrapper is None else wrapper - if isinstance(wrapper, string_types): - wrapper = Element(wrapper) - symbol = self.symbol if symbol is None else symbol - if symbol: - wrapper.text = symbol - icon = self.icon if icon is None else icon - if icon: - wrapper.append(icon) - return unicode(wrapper) - - -# plain theme configuration (default) -IDIOTICON_PLAIN = { - 'ICON_TAG': 'abbr', - 'ICON_CLASS': '', - 'SYMBOL': '*', -} - -# bootstrap theme configuration -IDIOTICON_BOOTSTRAP = { - 'ICON_TAG': 'span', - 'ICON_CLASS': 'fa fa-fw fa-question-circle', - 'SYMBOL': '', -} - -# all themes -THEMES = { - 'plain': IDIOTICON_PLAIN, - 'bootstrap': IDIOTICON_BOOTSTRAP, -} - -def get_config(values): - - config = IDIOTICON_DEFAULTS.copy() - - # Merge defaults with settings - config.update(values) - - # Check the theme - try: - theme = values['THEME'] - config['THEME'] = THEMES[values['THEME']].copy() - config['THEME']['NAME'] = theme - except KeyError: - raise ImproperlyConfigured("The IDIOTICON theme is not valid: %s" % values['THEME']) - - return config diff --git a/idioticon/templatetags/idioticon.py b/idioticon/templatetags/idioticon.py index 92a8c6e..ded6901 100644 --- a/idioticon/templatetags/idioticon.py +++ b/idioticon/templatetags/idioticon.py @@ -24,11 +24,10 @@ def do_term_tag(term_key, **kwargs): theme = kwargs.pop('theme', settings.IDIOTICON_THEME) - context = Context() - context.update(kwargs) + context = Context(kwargs) try: - context['term'] = shortcuts.get_term(term_key) + context['term'] = shortcuts.get_term(term_key, soft_error=False) template_name = 'idioticon/term_%s.html' % theme template = get_template(template_name) return template.render(context) @@ -46,7 +45,7 @@ def do_load_terms(parser, token): Usage:: {% load_terms 'my-term' 'other-term' as my_term other_term %} - {{ my_term.get_title }}: {{ my_term.get_definition }} + {{ my_term.get_name }}: {{ my_term.get_definition }} """ # token.split_contents() isn't useful here because this tag doesn't accept variable as arguments @@ -55,10 +54,10 @@ def do_load_terms(parser, token): try: as_index = args.index('as') except ValueError: - raise TemplateSyntaxError("'load_terms' requires '*terms as *variable' (got %r)" % args) + raise TemplateSyntaxError("'load_terms' requires '*terms as *variables' (got %r)" % args) - names, terms = args[as_index+1:], args[1:as_index] + names, terms = args[as_index+1:], map(lambda t: t.strip('\'').strip('"'), args[1:as_index]) if len(names) != len(terms): - raise TemplateSyntaxError("'load_terms' requires '*terms as *variable' (got %r)" % args) + raise TemplateSyntaxError("'load_terms' requires '*terms as *variables' (got %r)" % args) return LoadTermsNode(names, terms) \ No newline at end of file diff --git a/tests/test_models.py b/tests/test_models.py index 163f965..f1d99a9 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -167,6 +167,7 @@ def test_conf_textfield(self): @override_settings(IDIOTICON_THEME='abbr') def test_conf_theme(self): from idioticon.conf import settings + shortcuts.add_term('key', 'My Term') self.assertEqual(settings.IDIOTICON_THEME, 'abbr') from idioticon.templatetags.idioticon import do_term_tag self.assertIn('