diff --git a/shared/utils/fields.py b/shared/utils/fields.py index 1e509bd..e27e1cf 100644 --- a/shared/utils/fields.py +++ b/shared/utils/fields.py @@ -6,10 +6,6 @@ import re from .text import slugify -# TODO Remove deprecated location -from .models.slugs import AutoSlugField - - def uniquify_field_value(instance, field_name, value, max_length=None, queryset=None): """ Makes a char field value unique by appending an index, taking care of the diff --git a/shared/utils/management/commands/fix_proxymodel_permissions.py b/shared/utils/management/commands/fix_proxymodel_permissions.py index bb880ad..504c112 100644 --- a/shared/utils/management/commands/fix_proxymodel_permissions.py +++ b/shared/utils/management/commands/fix_proxymodel_permissions.py @@ -1,11 +1,9 @@ -# -*- coding: utf-8 -*- - """Add permissions for proxy model. This is needed because of the bug https://code.djangoproject.com/ticket/11154 in Django (as of 1.6, it's not fixed). -When a permission is created for a proxy model, it actually creates if for it's +When a permission is created for a proxy model, it gets actually created for the base model app_label (eg: for "article" instead of "about", for the About proxy model). diff --git a/shared/utils/models/slugs.py b/shared/utils/models/slugs.py index 6c66df5..48f9c83 100644 --- a/shared/utils/models/slugs.py +++ b/shared/utils/models/slugs.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals -import six +from functools import reduce from django.conf import settings from django.core import validators @@ -12,12 +10,10 @@ from django.utils.translation import gettext_lazy as _ from dirtyfields import DirtyFieldsMixin -from ..text import slugify, downgrading_slugify, django_slugify - -if six.PY3: - from functools import reduce +from ..text import slugify, downgrading_slugify +# TODO: Use english SLUG_HELP = _("Kurzfassung des Namens für die Adresszeile im Browser. Vorzugsweise englisch, keine Umlaute, nur Bindestrich als Sonderzeichen.") @@ -167,7 +163,7 @@ def slug_tree_mixin_post_save(sender, instance, **kwargs): if kwargs.get('created'): # Always get a new database instance before saving again # or MPTTModel.save() will interpret the newly .save as - # not allowed tree move action + # a forbidden tree move action # FIXME Not clear if this is a proper solution -> get rid of the slug_path stuff altogether instance_copy = type(instance).objects.get(pk=instance.pk) instance_copy.slug_path = instance_copy._get_slug_path() diff --git a/shared/utils/text.py b/shared/utils/text.py index 99962dc..8959e06 100644 --- a/shared/utils/text.py +++ b/shared/utils/text.py @@ -1,13 +1,10 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - import codecs -import translitcodec # provides 'translit/long', used by codecs.encode() +import html import re -import six +import translitcodec # provides 'translit/long', used by codecs.encode() # noqa from django.conf import settings -from django.utils.encoding import force_str, smart_str +from django.utils.encoding import force_str from django.utils.functional import keep_lazy_text from django.utils.html import mark_safe from django.utils.text import slugify as django_slugify @@ -43,20 +40,8 @@ SLUGIFY_FUNCTION = getattr(settings, 'SLUGIFY_FUNCTION', downgrading_slugify) slugify = SLUGIFY_FUNCTION -if six.PY2: - import bs4 - - def html_entities_to_unicode(html): - # An incoming HTML or XML entity is always converted into the corresponding Unicode character in bs4 - return smart_str(bs4.BeautifulSoup(html), 'lxml') - -else: - import html - - # Works only with Python >= 3.4 - def html_entities_to_unicode(html_str): - return html.unescape(html_str) - # html_entities_to_unicode = allow_lazy(html_entities_to_unicode, six.text_type, SafeText) +def html_entities_to_unicode(html_str): + return html.unescape(html_str) # Translators: Separator between list elements @@ -67,7 +52,7 @@ LAST_WORD_SEPARATOR = gettext_lazy(" and ") @keep_lazy_text -def get_text_joined(list_, separator=DEFAULT_SEPARATOR, last_word=LAST_WORD_SEPARATOR): +def text_joined(list_, separator=DEFAULT_SEPARATOR, last_word=LAST_WORD_SEPARATOR): list_ = list(list_) if len(list_) == 0: return '' @@ -78,16 +63,19 @@ def get_text_joined(list_, separator=DEFAULT_SEPARATOR, last_word=LAST_WORD_SEPA force_str(last_word), force_str(list_[-1])) +# TODO Don't match escaped stars (like \*) + +b_pattern = re.compile(r"(\*\*)(.*?)\1") +i_pattern = re.compile(r"(\*)(.*?)\1") +u_pattern = re.compile(r"(__)(.*?)\1") +link_pattern = re.compile(r"\[([^\[]+)\]\(([^\)]+)\)") + + @keep_lazy_text def slimdown(text): """ Converts simplified markdown (`**`, `*`, `__`) to , und tags. """ - b_pattern = re.compile(r"(\*\*)(.*?)\1") - i_pattern = re.compile(r"(\*)(.*?)\1") - u_pattern = re.compile(r"(__)(.*?)\1") - link_pattern = re.compile(r"\[([^\[]+)\]\(([^\)]+)\)") - if text: text, n = re.subn(b_pattern, "\\2", text) text, n = re.subn(i_pattern, "\\2", text)