Skip to content

Commit

Permalink
Merge e53c8cb into 2555c2c
Browse files Browse the repository at this point in the history
  • Loading branch information
erlenddalen committed May 28, 2018
2 parents 2555c2c + e53c8cb commit 4a3fc9f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,9 @@
*~

.idea
django_terms.egg-info/dependency_links.txt
django_terms.egg-info/requires.txt
django_terms.egg-info/top_level.txt
django_terms.egg-info/not-zip-safe
*.txt
django_terms.egg-info/PKG-INFO
5 changes: 4 additions & 1 deletion terms/html.py
Expand Up @@ -47,6 +47,8 @@ def translate(match):


def is_valid_node(node):
#if not node:
# return False
if node.tag is Comment or node.tag in TERMS_IGNORED_TAGS \
or node.get('id') in TERMS_IGNORED_IDS:
return False
Expand All @@ -57,13 +59,13 @@ def is_valid_node(node):
def get_text(node):
text = node.text or ''
for subnode in node.getchildren():
# text += subnode.text or subnode.tail or ''
text += subnode.tail or ''
return text.replace('&', '&')


def get_interesting_contents(parent_node, replace_regexp):
if is_valid_node(parent_node):

text = get_text(parent_node)
if text and replace_regexp.search(text):
yield parent_node
Expand All @@ -85,6 +87,7 @@ def replace_terms(original_html):
remove_p = False
etree = parse(StringIO(html))
root_node = etree.getroot()
#if not _looks_like_full_html_unicode(html) and root_node:
if not _looks_like_full_html_unicode(html):
root_node = root_node.getchildren()[0]
remove_body = True
Expand Down
5 changes: 4 additions & 1 deletion terms/managers.py
Expand Up @@ -5,6 +5,7 @@
from django.core.cache import cache
from django.db.models import Manager
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _


VARIANTS_DICT_CACHE_KEY = 'terms__variants_dict'
Expand All @@ -30,7 +31,9 @@ def _get_replace_dict(self, qs):
url = term.get_absolute_url()
name_variants = term.name_variants()
context = {'url': url.replace('%', '%%'),
'url_is_external': bool(term.url)}
'url_is_external': bool(term.url),
'tooltip_span': _('Open in new window'),
'definition': term.definition}

case_sensitive = term.case_sensitive
for name_variant in name_variants:
Expand Down
29 changes: 29 additions & 0 deletions terms/migrations/0001_initial.py
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
]

operations = [
migrations.CreateModel(
name='Term',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(help_text='Variants of the name can be specified with a \u201c|\u201d separator (e.g. \u201cname|names|to name\u201d).', unique=True, max_length=100, verbose_name='name')),
('case_sensitive', models.BooleanField(default=False, verbose_name='case sensitive')),
('definition', models.TextField(help_text='Accepts HTML tags.', verbose_name='definition', blank=True)),
('url', models.CharField(help_text='Address to which the term will redirect (instead of redirecting to the definition).', max_length=200, verbose_name='link', blank=True)),
],
options={
'ordering': ('name',),
'verbose_name': 'term',
'verbose_name_plural': 'terms',
},
bases=(models.Model,),
),
]
Empty file added terms/migrations/__init__.py
Empty file.
17 changes: 15 additions & 2 deletions terms/templates/terms/term_replace.html
@@ -1,8 +1,21 @@
{% spaceless %}
<a {% if url_is_external %}
href="{{ url }}"
href="{{ url }}" target="_blank"
{% else %}
onclick="window.open('{{ url }}', '', 'height=450px, width=700px');"
style="cursor: help;"
{% endif %}>%s</a>
{% endspaceless %}
{% endspaceless %}


{#{% spaceless %}#}
{# <a {% if url_is_external %}#}
{# href="{{ url }}"#}
{# {% else %}#}
{# onclick="window.open('{{ url }}', '', 'height=450px, width=700px');"#}
{# class="tooltip" title="{{ definition|safe }}" style="cursor: help;"#}
{# {% endif %}#}
{# >#}
{# <span title="{{ tooltip_span }}">%s</span>#}
{# </a>#}
{#{% endspaceless %}#}

0 comments on commit 4a3fc9f

Please sign in to comment.