Skip to content

Commit

Permalink
Merge 4f8f9b4 into c76473b
Browse files Browse the repository at this point in the history
  • Loading branch information
batiste committed Nov 2, 2018
2 parents c76473b + 4f8f9b4 commit 8ef1d8c
Show file tree
Hide file tree
Showing 30 changed files with 258 additions and 282 deletions.
7 changes: 4 additions & 3 deletions doc/changelog.rst
Expand Up @@ -4,12 +4,13 @@

This file describe new features and incompatibilities between released version of the CMS.

Release 1.9.18
Release 2.0.0
================

Released the 16th of April 2017.
Released the second of November 2018.

*
* Migrate to Django 2.1.X
* Removal of get_pages_with_tag

Release 1.9.17
================
Expand Down
18 changes: 0 additions & 18 deletions doc/display-content.rst
Expand Up @@ -100,24 +100,6 @@ an example of the use of this template tag to display a list of news:

You can use either the slug, or the id of the page.

get_pages_with_tag
---------------------

Retrieve a Pages objects with given tag and store it into a context variable that you can reuse after. Here is
an example of the use of this template tag to display a list of footer pages:

.. code-block:: html+django

<h2>Footer</h2>
{% get_pages_with_tag "footer" as footer_pages %}
<ul>
{% for page in footer_pages %}
<li>
<a href="{{ page.url }}">{{ page.title }}</a>
</li>
{% endfor %}
</ul>

show_absolute_url
-------------------

Expand Down
2 changes: 1 addition & 1 deletion doc/installation.rst
Expand Up @@ -50,7 +50,7 @@ Basically you need to have something like this::
urlpatterns = patterns('',
...
url(r'^pages/', include('pages.urls')),
(r'^admin/', include(admin.site.urls)),
(r'^admin/', admin.site.urls),
)

When you will visit the site the first time (``/pages/``), you will get a 404 error
Expand Down
2 changes: 1 addition & 1 deletion example/settings.py
Expand Up @@ -85,7 +85,7 @@

INTERNAL_IPS = ('127.0.0.1',)

MIDDLEWARE_CLASSES = (
MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
Expand Down
5 changes: 3 additions & 2 deletions example/urls.py
@@ -1,6 +1,7 @@

from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls import url
from django.urls import include, path, re_path
from django.conf.urls.static import static
from django.contrib import admin

Expand All @@ -10,7 +11,7 @@
urlpatterns = [
url(r'^i18n/', include('django.conf.urls.i18n')),
# url(r'^grappelli/', include('grappelli.urls')), # grappelli URLS
url(r'^admin/', include(admin.site.urls)),
url(r'^admin/', admin.site.urls),
]

try:
Expand Down
2 changes: 1 addition & 1 deletion pages/__init__.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""Django page CMS module."""
VERSION = (1, 9, 18)
VERSION = (2, 0, 0)
__version__ = '.'.join(map(str, VERSION))
__author__ = "Batiste Bieler"
__contact__ = "batiste.bieler@gmail.com"
Expand Down
15 changes: 0 additions & 15 deletions pages/admin/__init__.py
Expand Up @@ -16,11 +16,6 @@
from django.conf import settings as global_settings
from django.http import HttpResponseRedirect, Http404
from django.contrib.admin.sites import AlreadyRegistered
if global_settings.USE_I18N:
from django.views.i18n import javascript_catalog
else:
from django.views.i18n import null_javascript_catalog as javascript_catalog


extra_actions_registery = []
def add_page_action(action):
Expand Down Expand Up @@ -118,16 +113,6 @@ def get_urls(self):

return pages_urls + urls


def i18n_javascript(self, request):
"""Displays the i18n JavaScript that the Django admin
requires.
This takes into account the ``USE_I18N`` setting. If it's set to False, the
generated JavaScript will be leaner and faster.
"""
return javascript_catalog(request, packages='pages')

def save_model(self, request, page, form, change):
"""Move the page in the tree if necessary and save every
placeholder :class:`Content <pages.models.Content>`.
Expand Down
2 changes: 1 addition & 1 deletion pages/admin/views.py
Expand Up @@ -11,7 +11,7 @@
from django.template import RequestContext
from django import template
from django.views.decorators.csrf import csrf_exempt
from django.core.urlresolvers import reverse
from django.urls import reverse
from django import forms
from pages.managers import fake_page

Expand Down
2 changes: 1 addition & 1 deletion pages/management/commands/pages_pull.py
Expand Up @@ -15,7 +15,7 @@ def handle(self, *args, **options):

page_list = requests.get(self.host, auth=self.auth, timeout=5)
if page_list.status_code != 200:
raise ValueError(page_list.status_code)
self.http_error(response)
data = json.loads(page_list.text)

if not os.path.exists(os.path.dirname(self.filename)):
Expand Down
10 changes: 5 additions & 5 deletions pages/migrations/0001_initial.py
Expand Up @@ -45,9 +45,9 @@ class Migration(migrations.Migration):
('rght', models.PositiveIntegerField(editable=False, db_index=True)),
('tree_id', models.PositiveIntegerField(editable=False, db_index=True)),
('level', models.PositiveIntegerField(editable=False, db_index=True)),
('author', models.ForeignKey(verbose_name='author', to=settings.AUTH_USER_MODEL)),
('parent', models.ForeignKey(related_name='children', verbose_name='parent', blank=True, to='pages.Page', null=True)),
('redirect_to', models.ForeignKey(related_name='redirected_pages', blank=True, to='pages.Page', null=True)),
('author', models.ForeignKey(verbose_name='author', to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE)),
('parent', models.ForeignKey(related_name='children', verbose_name='parent', blank=True, to='pages.Page', null=True, on_delete=models.SET_NULL)),
('redirect_to', models.ForeignKey(related_name='redirected_pages', blank=True, to='pages.Page', null=True, on_delete=models.SET_NULL)),
],
options={
'ordering': ['tree_id', 'lft'],
Expand All @@ -62,7 +62,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('url', models.CharField(unique=True, max_length=255)),
('page', models.ForeignKey(verbose_name='page', blank=True, to='pages.Page', null=True)),
('page', models.ForeignKey(verbose_name='page', blank=True, to='pages.Page', null=True, on_delete=models.SET_NULL)),
],
options={
'verbose_name_plural': 'Aliases',
Expand All @@ -71,6 +71,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='content',
name='page',
field=models.ForeignKey(verbose_name='page', to='pages.Page'),
field=models.ForeignKey(verbose_name='page', to='pages.Page', on_delete=models.CASCADE),
),
]
40 changes: 40 additions & 0 deletions pages/migrations/0008_auto_20181102_0818.py
@@ -0,0 +1,40 @@
# Generated by Django 2.1.3 on 2018-11-02 08:18

from django.db import migrations, models
import django.db.models.deletion
import mptt.fields


class Migration(migrations.Migration):

dependencies = [
('pages', '0007_language_code'),
]

operations = [
migrations.AlterField(
model_name='media',
name='extension',
field=models.CharField(blank=True, editable=False, max_length=32),
),
migrations.AlterField(
model_name='page',
name='parent',
field=mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='pages.Page', verbose_name='parent'),
),
migrations.AlterField(
model_name='page',
name='redirect_to',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='redirected_pages', to='pages.Page', verbose_name='redirect to'),
),
migrations.AlterField(
model_name='page',
name='redirect_to_url',
field=models.CharField(blank=True, max_length=200, null=True, verbose_name='redirect to url'),
),
migrations.AlterField(
model_name='pagealias',
name='page',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='pages.Page', verbose_name='page'),
),
]
16 changes: 9 additions & 7 deletions pages/models.py
Expand Up @@ -13,12 +13,13 @@
from django.conf import settings as django_settings
from django.utils.translation import ugettext_lazy as _
from django.utils.safestring import mark_safe
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.conf import settings as global_settings
from django.utils.encoding import python_2_unicode_compatible


from mptt.models import MPTTModel
from mptt.fields import TreeForeignKey
import uuid
import os

Expand Down Expand Up @@ -77,10 +78,10 @@ class Page(MPTTModel):
uuid = models.UUIDField(default=uuid.uuid4, editable=False)

author = models.ForeignKey(django_settings.AUTH_USER_MODEL,
verbose_name=_('author'))
verbose_name=_('author'), on_delete=models.CASCADE)

parent = models.ForeignKey('self', null=True, blank=True,
related_name='children', verbose_name=_('parent'))
parent = TreeForeignKey('self', null=True, blank=True,
related_name='children', verbose_name=_('parent'), on_delete=models.CASCADE)
creation_date = models.DateTimeField(_('creation date'), editable=False,
default=get_now)
publication_date = models.DateTimeField(_('publication date'),
Expand Down Expand Up @@ -112,7 +113,7 @@ class Page(MPTTModel):
redirect_to_url = models.CharField(_('redirect to url'), max_length=200, null=True, blank=True)

redirect_to = models.ForeignKey('self', null=True, blank=True,
related_name='redirected_pages', verbose_name=_('redirect to'))
related_name='redirected_pages', verbose_name=_('redirect to'), on_delete=models.SET_NULL)

# Managers
objects = PageManager()
Expand Down Expand Up @@ -516,7 +517,8 @@ class Content(models.Model):
type = models.CharField(
_('type'), max_length=100, blank=False,
db_index=True)
page = models.ForeignKey(Page, verbose_name=_('page'), null=True)
page = models.ForeignKey(Page, verbose_name=_('page'), null=True,
on_delete=models.CASCADE)

creation_date = models.DateTimeField(
_('creation date'), editable=False,
Expand All @@ -536,7 +538,7 @@ def __str__(self):
class PageAlias(models.Model):
"""URL alias for a :class:`Page <pages.models.Page>`"""
page = models.ForeignKey(Page, null=True, blank=True,
verbose_name=_('page'))
verbose_name=_('page'), on_delete=models.CASCADE)
url = models.CharField(max_length=255, unique=True)
objects = PageAliasManager()

Expand Down
23 changes: 8 additions & 15 deletions pages/phttp.py
Expand Up @@ -6,26 +6,19 @@


def get_request_mock():
"""Build a ``request`` mock up that is used in to render
the templates in the most fidel environement as possible.
This fonction is used in the get_placeholders method to
render the input template and search for the placeholder
within.
"""
"""Build a ``request`` mock up for tests"""
from django.test.client import RequestFactory
from django.core.handlers.base import BaseHandler
factory = RequestFactory()
basehandler = BaseHandler()
basehandler.load_middleware()

request = factory.get('/')
# Apply request middleware
for middleware_method in basehandler._request_middleware:
# LocaleMiddleware should never be applied a second time because
# it would broke the current real request language
if 'LocaleMiddleware' not in str(middleware_method.__self__.__class__):
middleware_method(request)

class FakeUser():
is_authenticated = False
is_staff = False

request.user = FakeUser()
request.session = {}

return request

Expand Down
16 changes: 0 additions & 16 deletions pages/templatetags/pages_tags.py
Expand Up @@ -600,22 +600,6 @@ def language_content_up_to_date(page, language):

register.filter(language_content_up_to_date)


@register.assignment_tag
def get_pages_with_tag(tag):
"""
Return Pages with given tag
Syntax::
{% get_pages_with_tag <tag name> as <varname> %}
Example use::
{% get_pages_with_tag "footer" as pages %}
"""
return Page.objects.filter(tags__name__in=[tag])


def do_page_has_content(parser, token):
"""
Conditional tag that only renders its nodes if the page
Expand Down
1 change: 0 additions & 1 deletion pages/test_runner.py
Expand Up @@ -3,7 +3,6 @@

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pages.testproj.test_settings")
current_dirname = os.path.dirname(__file__)
#sys.path.insert(0, current_dirname)
sys.path.insert(0, os.path.join(current_dirname, '..'))

import django
Expand Down
2 changes: 1 addition & 1 deletion pages/testproj/documents/models.py
Expand Up @@ -11,7 +11,7 @@ class Document(models.Model):
text = models.TextField(_('text'), blank=True)

# the foreign key _must_ be called page
page = models.ForeignKey(Page)
page = models.ForeignKey(Page, on_delete=models.CASCADE)


class DocumentForm(ModelForm):
Expand Down
14 changes: 4 additions & 10 deletions pages/testproj/manage.py
@@ -1,18 +1,12 @@
#!/usr/bin/env python
import os, sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'test_settings'
current_dirname = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(current_dirname, '..'))
sys.path.insert(0, os.path.join(current_dirname, '../..'))

from django.core.management import execute_manager
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_settings")

try:
from . import test_settings # Assumed to be in the same directory.
except ImportError:
import sys
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
sys.exit(1)
from django.core.management import execute_from_command_line

if __name__ == "__main__":
execute_manager(test_settings)
execute_from_command_line(sys.argv)
11 changes: 5 additions & 6 deletions pages/testproj/test_settings.py
Expand Up @@ -19,14 +19,13 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'test.db'
'NAME': 'test.db',
'OPTIONS': {
'timeout': 10,
}
}
}

# We still want to be ale to test with 1.1.X
DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = 'test.db'

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be avilable on all operating systems.
Expand Down Expand Up @@ -69,7 +68,7 @@

INTERNAL_IPS = ('127.0.0.1',)

MIDDLEWARE_CLASSES = (
MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
Expand Down
2 changes: 1 addition & 1 deletion pages/testproj/urls.py
Expand Up @@ -17,7 +17,7 @@
# this is only used to enable the reverse url to work with documents
url(r'^pages/(?P<path>.*)', include('pages.testproj.documents.urls')),

url(r'^admin/', include(admin.site.urls)),
url(r'^admin/', admin.site.urls),
# make tests fail if a backend is not present on the system
#(r'^search/', include('haystack.urls')),

Expand Down

0 comments on commit 8ef1d8c

Please sign in to comment.