Tested for Django 1.7-1.11 0.8.6
authorRadek Czajka <rczajka@rczajka.pl>
Wed, 25 Sep 2019 23:27:51 +0000 (01:27 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Wed, 25 Sep 2019 23:27:51 +0000 (01:27 +0200)
12 files changed:
.gitignore
example_project/core/__init__.py [new file with mode: 0644]
example_project/core/settings.py [new file with mode: 0644]
example_project/core/templates/base.html [new file with mode: 0644]
example_project/core/urls.py [new file with mode: 0644]
example_project/core/wsgi.py [new file with mode: 0644]
example_project/manage.py [new file with mode: 0755]
example_project/tests.py [new file with mode: 0644]
migdal/templatetags/migdal_tags.py
migdal/views.py
setup.py
tox.ini [new file with mode: 0644]

index d6e951d..a2a13c0 100644 (file)
@@ -27,6 +27,6 @@ thumbs.db
 TAGS
 
 # testing
-migdal_site
 db.sqlite3
-manage.py
+/.tox
+/htmlcov
diff --git a/example_project/core/__init__.py b/example_project/core/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/example_project/core/settings.py b/example_project/core/settings.py
new file mode 100644 (file)
index 0000000..0535bc5
--- /dev/null
@@ -0,0 +1,152 @@
+"""
+Django settings for core project.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/1.6/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/1.6/ref/settings/
+"""
+
+# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
+import os
+BASE_DIR = os.path.dirname(os.path.dirname(__file__))
+
+
+# Quick-start development settings - unsuitable for production
+# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = ')1^j9pxlee5bz+$-g1_tphmnip=u^78r+xskny()61)ulk7n4w'
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+TEMPLATE_DEBUG = True
+
+ALLOWED_HOSTS = []
+
+
+# Application definition
+
+INSTALLED_APPS = (
+    'django.contrib.admin',
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.messages',
+    'django.contrib.staticfiles',
+
+    'django.contrib.sites', # Used by django_comments.
+    'django_comments', # Used by migdal.
+    'django_comments_xtd', # Used by migdal.
+    'migdal',
+    'fnpdjango', # Has template tags used in default migdal templates.
+    'sorl.thumbnail', # Has template tags used in default migdal templates.
+    'fnp_django_pagination', # Has template tags used in default migdal templates.
+    'django_gravatar', # Has template tags used in default migdal templates.
+    'core',
+)
+
+MIDDLEWARE_CLASSES = (
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'fnpdjango.middleware.URLLocaleMiddleware',  # Needed to set language.
+    'django.middleware.common.CommonMiddleware',
+    'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
+    'fnp_django_pagination.middleware.PaginationMiddleware', # Used in default migdal templates.
+)
+
+ROOT_URLCONF = 'core.urls'
+
+WSGI_APPLICATION = 'core.wsgi.application'
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.sqlite3',
+        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
+    }
+}
+
+# We have to provide a base template.
+TEMPLATE_DIRS = [
+    os.path.join(BASE_DIR, 'core/templates'),
+]
+TEMPLATE_CONTEXT_PROCESSORS = (
+    "django.core.context_processors.request", # Used in template tags.
+    "django.contrib.auth.context_processors.auth",
+    "django.core.context_processors.debug",
+    "django.core.context_processors.i18n",
+    "django.core.context_processors.media",
+    "django.core.context_processors.static",
+    "django.core.context_processors.tz",
+    "django.contrib.messages.context_processors.messages"
+)
+TEMPLATES = [
+    {
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
+        'APP_DIRS': True,
+        'DIRS': TEMPLATE_DIRS,
+        'OPTIONS': {
+            'context_processors': [
+                "django.template.context_processors.request", # Used in template tags.
+                "django.contrib.auth.context_processors.auth",
+                "django.template.context_processors.debug",
+                "django.template.context_processors.i18n",
+                "django.template.context_processors.media",
+                "django.template.context_processors.static",
+                "django.template.context_processors.tz",
+                "django.contrib.messages.context_processors.messages"
+            ],
+        }
+    }
+]
+
+
+# These match languages in migrations.
+LANGUAGE_CODE = 'pl'
+LANGUAGES = [
+        ('pl', 'Polish'),
+        ('en', 'English'),
+        ]
+
+TIME_ZONE = 'UTC'
+
+USE_I18N = True
+
+USE_L10N = True
+
+USE_TZ = True
+
+STATIC_URL = '/static/'
+
+
+# Match default migdal markup type.
+from fnpdjango.utils.text.textilepl import textile_pl
+MARKUP_FIELD_TYPES = (
+    ('textile_pl', textile_pl),
+)
+
+
+# Create an Entry type.
+from fnpdjango.utils.settings import LazyUGettextLazy as gettext
+from migdal.helpers import EntryType
+
+MIGDAL_TYPES = (
+    EntryType('blog', gettext('blog'), commentable=True, on_main=True),
+    EntryType('info', gettext('info'), commentable=False, on_main=False),
+)
+
+
+# Needed for Haystack to work.
+HAYSTACK_CONNECTIONS = {
+    'default': {
+        'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
+        'URL': 'http://127.0.0.1:8983/solr/prawokultury'
+    },
+}
+
+# django_comments need SITE_ID.
+SITE_ID = 1
diff --git a/example_project/core/templates/base.html b/example_project/core/templates/base.html
new file mode 100644 (file)
index 0000000..47b555d
--- /dev/null
@@ -0,0 +1,2 @@
+{% block body %}
+{% endblock %}
diff --git a/example_project/core/urls.py b/example_project/core/urls.py
new file mode 100644 (file)
index 0000000..e92ba47
--- /dev/null
@@ -0,0 +1,9 @@
+from django.conf.urls import include, url
+import migdal.urls
+
+from django.contrib import admin
+
+
+urlpatterns = [
+    url(r'^admin/', include(admin.site.urls)),
+] + migdal.urls.urlpatterns
diff --git a/example_project/core/wsgi.py b/example_project/core/wsgi.py
new file mode 100644 (file)
index 0000000..f4b141d
--- /dev/null
@@ -0,0 +1,14 @@
+"""
+WSGI config for core project.
+
+It exposes the WSGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
+"""
+
+import os
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
+
+from django.core.wsgi import get_wsgi_application
+application = get_wsgi_application()
diff --git a/example_project/manage.py b/example_project/manage.py
new file mode 100755 (executable)
index 0000000..d68553b
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+import os
+import sys
+
+if __name__ == "__main__":
+    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
+
+    from django.core.management import execute_from_command_line
+
+    execute_from_command_line(sys.argv)
diff --git a/example_project/tests.py b/example_project/tests.py
new file mode 100644 (file)
index 0000000..e4b4e4e
--- /dev/null
@@ -0,0 +1,29 @@
+from django.test import TestCase
+from migdal.models import Entry
+
+
+class MigdalTests(TestCase):
+    def test_x(self):
+        Entry.objects.create(
+                type='info', author='An author',
+                published_pl=True, title_pl='An info entry', slug_pl='test1',
+                body_pl='**Test text**',
+            )
+        Entry.objects.create(
+                type='blog', author='An author',
+                published_pl=True, title_pl='A blog entry', slug_pl='test2',
+                body_pl='**Test blog text**',
+            )
+
+
+        response = self.client.get('/')
+        self.assertContains(response, 'A blog entry')
+        self.assertNotContains(response, 'An info entry')
+
+
+
+        response = self.client.get('/info/')
+        self.assertContains(response, 'An info entry')
+
+        response = self.client.get('/info/test1/')
+        self.assertContains(response, '<b>Test text</b>')
index 9c2609c..1668e33 100644 (file)
@@ -5,6 +5,7 @@
 from django.shortcuts import get_object_or_404
 from django_comments_xtd.models import XtdComment
 import django_comments as comments
+import django
 from django import template
 from migdal import app_settings
 from migdal.models import Category, Entry
@@ -12,6 +13,14 @@ from migdal.models import Category, Entry
 register = template.Library()
 
 
+if django.VERSION < (1, 8):
+    # See https://docs.djangoproject.com/en/2.2/releases/1.8/#rendering-templates-loaded-by-get-template-with-a-context
+    context_for_get_template = template.Context
+else:
+    context_for_get_template = lambda x: x
+
+
+
 @register.simple_tag(takes_context=True)
 def entry_begin(context, entry, detail=False):
     t = template.loader.select_template((
@@ -23,7 +32,7 @@ def entry_begin(context, entry, detail=False):
         'object': entry,
         'detail': detail,
     }
-    return t.render(template.Context(context))
+    return t.render(context_for_get_template(context))
 
 
 @register.simple_tag(takes_context=True)
@@ -36,7 +45,7 @@ def entry_short(context, entry):
         'request': context['request'],
         'object': entry,
     }
-    return t.render(template.Context(context))
+    return t.render(context_for_get_template(context))
 
 
 @register.simple_tag(takes_context=True)
@@ -50,7 +59,7 @@ def entry_promobox(context, entry, counter):
         'object': entry,
         'counter': counter,
     }
-    return t.render(template.Context(context))
+    return t.render(context_for_get_template(context))
 
 
 @register.inclusion_tag('migdal/categories.html', takes_context=True)
index 0d4d996..47fddf2 100644 (file)
@@ -102,5 +102,4 @@ class SearchPublishedView(SearchView):
             else:
                 return True
         results = filter(lambda r: is_published(r.object), results)
-        print results
         return results
index 07fb7f1..456ee59 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -23,7 +23,7 @@ def whole_trees(package_dir, paths):
 
 setup(
     name='django-migdal',
-    version='0.8.5',
+    version='0.8.6',
     author='Radek Czajka',
     author_email='radoslaw.czajka@nowoczesnapolska.org.pl',
     url='',
@@ -33,11 +33,18 @@ setup(
     description='.',
     long_description="",
     install_requires=[
-        'django-contrib-comments',
-        'django-comments-xtd',
+        'django-contrib-comments==1.7.3',
+        'django-comments-xtd==1.5.1',
         'django-gravatar2',
-        'django-haystack',
-        'django-markupfield',
+        'django-haystack==2.7.0',
+        'django-markupfield==1.4.3',
         'python-slugify',
+
+        'fnpdjango==0.3',
+        'Pillow',
+        'sorl-thumbnail==12.4.1',
+        'pysolr==3.8.1',
+        'fnp-django-pagination==2.2.4',
+        'Django>=1.7,<2.0',
     ],
 )
diff --git a/tox.ini b/tox.ini
new file mode 100644 (file)
index 0000000..d7d9909
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,41 @@
+[tox]
+envlist =
+    clean,
+    d17-py{27,34},
+    d{18,19,110}-py{27,34,35},
+    d111-py{27,34,35,36,37},
+    #d20-py{34,35,36,37},
+    #d{21,22}-py{35,36,37},
+    stats
+
+[testenv]
+deps =
+    d16: Django>=1.6,<1.7
+    d17: Django>=1.7,<1.8
+    d18: Django>=1.8,<1.9
+    d19: Django>=1.9,<1.10
+    d110: Django>=1.10,<1.11
+    d111: Django>=1.11,<2.0
+    d20: Django>=2.0,<2.1
+    d21: Django>=2.1,<2.2
+    d22: Django>=2.2,<2.3
+    coverage
+commands =
+    coverage run --append example_project/manage.py test example_project
+install_command = pip install --extra-index-url https://py.mdrn.pl/simple {packages}
+
+[testenv:clean]
+commands =
+    coverage erase
+deps = coverage
+
+[testenv:stats]
+commands =
+    coverage report
+    coverage html
+deps = coverage
+
+[coverage:run]
+branch = true
+source = migdal
+