Skip to content

Commit

Permalink
Compatibility with Django 2, and functional fixes.
Browse files Browse the repository at this point in the history
Ignore migrations and a lot more in .gitignore.
Solved stack trace in mgaitan#155
Transfer page instance on page_save in signals.
assignment_tag -> simple_tag in waliki_tags.
  • Loading branch information
frenchbeard committed Feb 1, 2019
1 parent 5baaf6f commit 0af9702
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 59 deletions.
140 changes: 108 additions & 32 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,49 +1,125 @@
# preciosa
site_media
datasets
backups
local_settings.py
waliki_data
waliki_attachments
.nose*
.noseids
*.db
*.sqlite3
*.swp
docs/_build/*

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
lib
lib64
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.tox
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# project specific
waliki_data

# Django
*/migrations/

# tags file
tags
39 changes: 21 additions & 18 deletions waliki/models.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
# -*- coding: utf-8 -*-
import os
import codecs
import shutil
import os
import os.path
import shutil

from django import VERSION
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AnonymousUser, Group, Permission
from django.core.cache import cache
from django.db import models
from django.db.models import Q
from django.db.models.signals import post_save, pre_delete
from django.db.utils import IntegrityError
from django.conf import settings
if VERSION[:2] >= (1, 10):
from django.urls import reverse
else:
from django.core.urlresolvers import reverse
from django.dispatch import receiver
from django.utils.encoding import python_2_unicode_compatible
from django.utils.six import string_types
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import python_2_unicode_compatible
from django.contrib.auth.models import Permission, Group, AnonymousUser
from django.contrib.auth import get_user_model
from django.core.cache import cache
from django.db.models.signals import post_save, pre_delete

from docutils.utils import SystemMessage
from waliki.settings import (WALIKI_CACHE_TIMEOUT, WALIKI_DATA_DIR,
WALIKI_DEFAULT_MARKUP, WALIKI_MARKUPS_SETTINGS,
get_slug, sanitize)

from . import _markups
from waliki.settings import (get_slug, sanitize, WALIKI_DEFAULT_MARKUP,
WALIKI_MARKUPS_SETTINGS, WALIKI_DATA_DIR,
WALIKI_CACHE_TIMEOUT)

if VERSION[:2] >= (1, 10):
from django.urls import reverse
else:
from django.core.urlresolvers import reverse

@python_2_unicode_compatible
class Page(models.Model):
Expand Down Expand Up @@ -120,7 +124,7 @@ def get_markup_instance(markup):

@staticmethod
def preview(markup, text):
content = Page.get_markup_instance(markup).get_document_body(text)
content = Page.get_markup_instance(markup).convert(text).get_document_body()
content= sanitize(content)
return content

Expand All @@ -132,7 +136,7 @@ def markup_(self):

def _get_part(self, part):
try:
return getattr(self.markup_, part)(self.raw)
return getattr(self.markup_.convert(self.raw), part)
except SystemMessage:
return ''

Expand All @@ -158,7 +162,6 @@ def get_cached_content(self):

if cached_content is None:
cached_content = self._get_part('get_document_body')
cached_content = sanitize(cached_content)
cache.set(cache_key, cached_content, WALIKI_CACHE_TIMEOUT)
return cached_content

Expand Down
2 changes: 1 addition & 1 deletion waliki/signals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import django.dispatch

page_preedit = django.dispatch.Signal(providing_args=["page"])
page_saved = django.dispatch.Signal(providing_args=["raw", "author", "message"])
page_saved = django.dispatch.Signal(providing_args=["raw", "page", "author", "message"])
page_moved = django.dispatch.Signal(providing_args=["page", "old_path", "author", "message"])
16 changes: 8 additions & 8 deletions waliki/templatetags/waliki_tags.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from django import VERSION
from django import template
from django import VERSION, template
from django.utils.translation import ugettext_lazy as _
from waliki import settings
from waliki.acl import check_perms as check_perms_helper
from waliki.forms import PageForm
from waliki.models import Page

if VERSION[:2] >= (1, 10):
from django.urls import reverse
else:
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from waliki.acl import check_perms as check_perms_helper
from waliki.models import Page
from waliki.forms import PageForm
from waliki import settings


register = template.Library()
Expand Down Expand Up @@ -169,7 +169,7 @@ def waliki_box(context, slug, show_edit=True, *args, **kwargs):
}


@register.assignment_tag
@register.simple_tag
def waliki_breadcrumbs(slug):
if not settings.WALIKI_BREADCRUMBS:
return None
Expand Down

0 comments on commit 0af9702

Please sign in to comment.