Skip to content

Commit

Permalink
Merge pull request #15 from sebastian-philipp/remove-coffin
Browse files Browse the repository at this point in the history
remove Coffin
  • Loading branch information
martin-bts committed Jun 24, 2019
2 parents 62b7329 + 7931863 commit 6ff29bb
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 113 deletions.
2 changes: 0 additions & 2 deletions askbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
'akismet': 'akismet==1.0.1',
'avatar': 'django-avatar==3.1.0',
'bs4': 'beautifulsoup4<=4.7.1',
'coffin': 'Coffin>=2.0',
'compressor': 'django-compressor>=2.0,<=2.2',
'django': 'django>=1.9,<1.12',
'django_countries': 'django-countries>=3.3',
Expand Down Expand Up @@ -60,7 +59,6 @@
from askbot.deployment.assertions import assert_package_compatibility
assert_package_compatibility()
patches.patch_django()
patches.patch_coffin() # must go after django
except ImportError:
pass

Expand Down
8 changes: 0 additions & 8 deletions askbot/deployment/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,3 @@ def assert_package_compatibility():
package_utils.get_django_version()
if django_major < 1:
raise DeploymentError('Django version < 1.0 is not supported by askbot')

coffin_version = package_utils.get_coffin_version()
if coffin_version == (0, 3, 0) and django_major == 1 and django_minor > 1:
raise DeploymentError(
'Coffin package version 0.3 is not compatible '
'with the current version of Django, please upgrade '
'coffin to at least 0.3.3'
)
16 changes: 0 additions & 16 deletions askbot/deployment/package_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,8 @@
versions of all packages are normalized to three-tuples
of integers (missing zeroes added)
"""
import coffin
import django

def get_coffin_version():
"""Returns version of Coffin package
as a three integer value tuple
"""
version = coffin.__version__
if len(version) == 2:
micro_version = 0
elif len(version) == 3:
micro_version = version[2]
else:
raise ValueError('unsupported version of coffin %s' % '.'.join(version))
major_version = version[0]
minor_version = version[1]
return (major_version, minor_version, micro_version)

def get_django_version():
"""returns three-tuple for the version
of django"""
Expand Down
11 changes: 0 additions & 11 deletions askbot/patches/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,3 @@ def patch_django():

if major == 1 and minor == 8:
django_patches.patch_django_template()

def patch_coffin():
"""coffin before version 0.3.4
does not have csrf_token template tag.
This patch must be applied after the django patches
"""
from askbot.patches import coffin_patches

(major, minor, micro) = package_utils.get_coffin_version()
if major == 0 and minor == 3 and micro < 4:
coffin_patches.add_csrf_token_tag()
7 changes: 1 addition & 6 deletions askbot/patches/coffin_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,4 @@ def _render(self, csrf_token):
return Markup(CsrfTokenNode().render({'csrf_token': csrf_token}))

def add_csrf_token_tag():
"""adds csrf token tag to the default library"""
import coffin.template.defaulttags
coffin.template.defaulttags.CsrfTokenExtension = CsrfTokenExtension
csrf_token = CsrfTokenExtension
coffin.template.defaulttags.csrf_token = csrf_token
coffin.template.defaulttags.register.tag(csrf_token)
"""TODO: Removed when migrated to Python 3"""
35 changes: 1 addition & 34 deletions askbot/patches/django_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,40 +283,7 @@ def process_response(self, request, response):
"""

def add_import_library_function():

#this definition is copy/pasted from django 1.2 source code
#it is necessary to make Coffin library happy
try:
from importlib import import_module
except ImportError:
from django.utils.importlib import import_module
class InvalidTemplateLibrary(Exception):
pass

def import_library(taglib_module):
"""Load a template tag library module.
Verifies that the library contains a 'register' attribute, and
returns that attribute as the representation of the library
"""
app_path, taglib = taglib_module.rsplit('.',1)
app_module = import_module(app_path)
try:
mod = import_module(taglib_module)
except ImportError as e:
# If the ImportError is because the taglib submodule does not exist, that's not
# an error that should be raised. If the submodule exists and raised an ImportError
# on the attempt to load it, that we want to raise.
if not module_has_submodule(app_module, taglib):
return None
else:
raise InvalidTemplateLibrary("ImportError raised loading %s: %s" % (taglib_module, e))
try:
return mod.register
except AttributeError:
raise InvalidTemplateLibrary("Template library %s does not have a variable named 'register'" % taglib_module)

import django.template
django.template.import_library = import_library
"""TODO: Remove"""

def add_csrf_protection():
"""adds csrf_token template tag to django
Expand Down
13 changes: 0 additions & 13 deletions askbot/skins/jinja2_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@
# which is why we keep this around.
# Commented extensions have (hopefully) been replaced by django_jinja

import coffin

COFFIN_EXTENSIONS = [
coffin.LoadExtension,
coffin.URLExtension,
#coffin.WithExtension,
coffin.SpacelessExtension,
coffin.PrefixExtension,
coffin.GetStaticPrefixExtension,
coffin.GetMediaPrefixExtension,
#coffin.StaticExtension
]

import askbot
from askbot.conf import settings as askbot_settings
Expand Down Expand Up @@ -74,7 +62,6 @@ def factory(**options):
# JINJA2_EXTENSIONS was a thing in Coffin. We keep it around because it
# may be used in Askbot. Should think about deprecating its use.
options["extensions"] = DEFAULT_EXTENSIONS \
+ COFFIN_EXTENSIONS \
+ list(django_settings.JINJA2_EXTENSIONS)
askbot_globals = { 'settings': askbot_settings,
'hasattr' : hasattr
Expand Down
13 changes: 2 additions & 11 deletions askbot/templatetags/extra_filters_jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
import re
import time
import urllib.request, urllib.parse, urllib.error
try:
from coffin import template as coffin_template
except ImportError:
from django_jinja import library as d_j_library
class coffin_template:
@classmethod
def Library(cls):
return d_j_library
from bs4 import BeautifulSoup
from django.core import exceptions as django_exceptions
from django.utils.encoding import force_unicode
Expand All @@ -21,6 +13,7 @@ def Library(cls):
from django.core.urlresolvers import reverse, resolve
from django.http import Http404
import simplejson
from django import template
from django.utils import timezone
from django.utils.text import Truncator
from askbot import exceptions as askbot_exceptions
Expand All @@ -40,9 +33,7 @@ def Library(cls):
from django_countries import countries
from django_countries import settings as countries_settings

register = coffin_template.Library()

absolutize_urls = register.filter(absolutize_urls)
register = template.Library()

TIMEZONE_STR = pytz.timezone(
django_settings.TIME_ZONE
Expand Down
13 changes: 1 addition & 12 deletions askbot/tests/test_page_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@
import simplejson
from django.utils.translation import activate as activate_language

import coffin
try:
# this import is only supposed to work with old versions of Coffin
# newer versions do not have a template module
import coffin.template
except ImportError as e:
if coffin.__version__[0] < 1:
raise e

from bs4 import BeautifulSoup

import askbot
Expand Down Expand Up @@ -46,9 +37,7 @@ def instrumented_render(template_object, *args, **kwargs):
return ORIG_JINJA2_RENDERER(template_object, *args, **kwargs)
Template.render = instrumented_render

(CMAJOR, CMINOR, CMICRO) = package_utils.get_coffin_version()
if CMAJOR > 0 or CMINOR == 3 and CMICRO < 4:
patch_jinja2()
patch_jinja2()


class PageLoadTestCase(AskbotTestCase):
Expand Down

0 comments on commit 6ff29bb

Please sign in to comment.