Forward and backwards compatibility layer for Django 1.4, 1.7, 1.8, 1.9, 1.10, and 1.11

Related tags

Djangodjango-compat
Overview

django-compat

Build Status Stories in Ready Coverage Status PyPI

Forward and backwards compatibility layer for Django 1.4, 1.7, 1.8, 1.9, 1.10 and 1.11

Consider django-compat as an experiment based on the discussion on reddit. Let's see where it goes.

What started as an experiment based on this discussion on reddit has proven to be true in real life.

django-compat is under active development. To learn about other features, bug fixes, and changes, please refer to the changelog.

Who uses django-compat

Two popular examples of open source reusable app that uses django-compat are django-hijack and django-background-tasks.
Want to have yours listed here? Send us a PR.

Why use django-compat

  • Be able to use the LTS versions of Django and support newer versions in your app
  • Use features from newer Django versions in an old one
  • Manage and master the gap between different framework versions

How to use django-compat

Install compat from the PyPI or download and install manually. All relevant releases are listed here under releases.

Using one of the compatible objects is easy. For example

from compat import patterns, url

urlpatterns = patterns('ABC.views',
		url(r'^abc/$', 'abc', name='abc-link'),
...

See a full example here.

django-compat is free software. If you find it useful and would like to give back, please consider to make a donation using Bitcoin or PayPal. Thank you!

Compatible objects

Compatible object Specifically tested 1.8 1.9 1.10 1.11 Notes
BytesIO ✖️ ✔️ ✔️ ✔️ ✔️
DjangoJSONEncoder ✔️ ✔️ ✔️ ✔️ ✔️
EmailValidator ✖️ ✔️ ✔️ ✔️ ✔️
GenericForeignKey ✖️ ✔️
models.GenericForeignKey ✖️ ✔️ ✔️ ✔️ ✔️
HttpResponseBase ✖️ ✔️ ✔️ ✔️ ✔️
JsonResponse ✔️ ✔️ ✔️ ✔️ ✔️
LocaleRegexProvider ✖️ ✔️ ✔️ ✔️ ✔️
LocaleRegexURLResolver ✖️ ✔️ ✔️ ✔️ ✔️
NoReverseMatch ✖️ ✔️ ✔️ ✔️ ✔️
RegexURLPattern ✖️ ✔️ ✔️ ✔️ ✔️
RegexURLResolver ✖️ ✔️ ✔️ ✔️ ✔️
Resolver404 ✖️ ✔️ ✔️ ✔️ ✔️
ResolverMatch ✖️ ✔️ ✔️ ✔️ ✔️
SortedDict ✖️ ✔️ ✔️ ✔️ ✔️
StringIO ✖️ ✔️ ✔️ ✔️ ✔️
URLValidator ✖️ ✔️ ✔️ ✔️ ✔️
VariableNode ✖️ ✔️ ✔️ ✔️ ✔️
View ✖️ ✔️ ✔️ ✔️ ✔️
add_to_builtins ✖️ ✔️
admin_utils ✖️ ✔️ ✔️ ✔️ ✔️
atomic ✖️ ✔️ ✔️ ✔️ ✔️
clean_manytomany_helptext ✖️ ✔️ ✔️ ✔️ ✔️
clear_url_caches ✖️ ✔️ ✔️ ✔️ ✔️
close_connection ✖️ ✔️ ✔️ ✔️ ✔️
commit ✔️ ✔️ ✔️ ✔️ ✔️
commit_on_success ✔️ ✔️ ✔️ ✔️ ` ✔️ commit_on_success replaced by atomic in Django >= 1.8
force_text ✖️ ✔️ ✔️ ✔️ ✔️
format_html ✔️ ✔️ ✔️ ✔️ ✔️
get_callable ✖️ ✔️ ✔️ ✔️ ✔️
get_current_site ✖️ ✔️ ✔️ ✔️ ✔️
get_ident ✖️ ✔️ ✔️ ✔️ ✔️
get_mod_func ✖️ ✔️ ✔️ ✔️ ✔️
get_model ✖️ ✔️ ✔️ ✔️ ✔️
get_model_name ✖️ ✔️ ✔️ ✔️ ✔️
get_ns_resolver ✖️ ✔️ ✔️ ✔️ ✔️
get_resolver ✖️ ✔️ ✔️ ✔️ ✔️
get_script_prefix ✖️ ✔️ ✔️ ✔️ ✔️
get_template_loaders ✔️ ✔️ ✔️ ✔️ ✔️
get_urlconf ✖️ ✔️ ✔️ ✔️ ✔️
get_user_model ✖️ ✔️ ✔️ ✔️ ✔️
get_username_field ✖️ ✔️ ✔️ ✔️ ✔️
handler404 ✖️ ✔️ ✔️ ✔️ ✔️
handler500 ✖️ ✔️ ✔️ ✔️ ✔️
import_module ✔️ ✔️ ✔️ ✔️ ✔️
import_string ✖️ ✔️ ✔️ ✔️ ✔️
include ✖️ ✔️ ✔️ ✔️ ✔️
is_valid_path ✖️ ✔️ ✔️ ✔️ ✔️
parse_qs ✖️ ✔️ ✔️ ✔️ ✔️
patterns ✖️ ✔️ ✔️
python_2_unicode_compatible ✖️ ✔️ ✔️ ✔️ ✔️
render_to_string ✔️ ✔️ ✔️ ✔️ ✔️ The new function signature (https://docs.djangoproject.com/en/1.9/releases/1.8/#dictionary-and-context-instance-arguments-of-rendering-functions) is backported to pre-1.8.
resolve ✖️ ✔️ ✔️ ✔️ ✔️
resolve_url ✔️ ✔️ ✔️ ⚠️ ⚠️ 1.10: Reversing by dotted path has been removed
reverse ✖️ ✔️ ✔️ ✔️ ✔️
reverse_lazy ✖️ ✔️ ✔️ ✔️ ✔️
rollback ✔️ ✔️ ✔️ ✔️ ✔️ Transaction savepoint (sid) is required for Django < 1.8
set_script_prefix ✖️ ✔️ ✔️ ✔️ ✔️
set_urlconf ✖️ ✔️ ✔️ ✔️ ✔️
simplejson ✖️ ✔️ ✔️ ✔️ ✔️
slugify ✖️ ✔️ ✔️ ✔️ ✔️
smart_text ✖️ ✔️ ✔️ ✔️ ✔️
unquote_plus ✖️ ✔️ ✔️ ✔️ ✔️
url ✖️ ✔️ ✔️ ✖️ ✖️ Function used in urlpatterns
tempat.url ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
`uravy_multiplication_x: ✔️ ✔️ ✔️ ✔️ ✔️
urlparse ✖️ ✔️ ✔️ ✔️ ✔️
urlresolvers ✖️ ✔️ ✔️ ✔️ ✔️
urlunparse ✖️ ✔️ ✔️ ✔️ ✔️
user_model_label ✖️ ✔️ ✔️ ✔️ ✔️
templatetags.compat.verbatim ✔️ ✔️ ✔️ ✔️ ✔️ Templatetag; import with {% load verbatim from compat %}. 1.4: Does not allow specific closing tags, e.g. {% endverbatim myblock %}, and does not preserve whitespace inside tags.

Resources and references

Resources

compat.py

Bits and bites of the following projects were re-used to build django-compat.

Changelog

2017/04/07

  • Update existing patches for Django 1.10

2016/08/02

  • Update existing patches for Django 1.10

2016/06/01

  • Add get_current_site and admin_utils

2016/05/11

  • Fix error when installing package under python 3.4

### 2015/11/12

  • Backport new render_to_string function signature to Django < 1.8
  • Backport verbatim tag to Django 1.4
  • Add get_template_loaders
  • Add close_connection
  • Improve JsonResponse backport to Django 1.4
  • Add tests for import_module, get_model and add_to_builtins
  • Anticipate renaming of django.core.urlresolvers to django.urls in 1.10
  • Avoid warnings in setup.py

2015/11/11

  • 1.9 compatibility for existing objects with the following changes:
    • add_to_builtins was removed for Django >= 1.9
    • GenericForeignKey` was moved to compat.models`` for Django >= 1.9

2015/07/15

  • add_to_builtins was added

2015/07/08

  • get_query_set/get_queryset support was dropped again (see #29)
Comments
  • get_query_set patching is very broken

    get_query_set patching is very broken

    The method included to patch get_query_set is very broken, and leads to some very bug code in circumstances where managers get subclassed - the behaviour of the subclass can be skipped. This is a very serious error for the case of Related managers, because it means that the limiting of the queryset that is added by the subclass get_query_set method gets skipped, so the related manager queries apply to all objects.

    I've created a branch that demonstrates the problem, adding 4 tests, 2 of which fails with Django 1.8, one fails with Django 1.5:

    https://github.com/spookylukey/django-compat/tree/get_query_set_patch_bug

    I've created a PR so that you can see the tests failing.

    The full details are explained in this blog post:

    http://lukeplant.me.uk/blog/posts/handling-django's-get_query_set-rename-is-hard/

    opened by spookylukey 5
  • Stop use django-nose as it doesn't support Django<1.8

    Stop use django-nose as it doesn't support Django<1.8

    I think use django-nose is a bad idea because it doesn't support Django<1.8. So we cannot test this version with the ./runtests.py.

    We should use Django test runner like made here: https://github.com/django-dbbackup/django-dbbackup/blob/master/runtests.py It also allow to launch any commands like manage.py.

    opened by ZuluPro 3
  • WIP django monkey-patcher

    WIP django monkey-patcher

    Hello,

    i'm planning a sprint at pyconfr to build a django compatibility module, which wouldn't behave like an intermediate module (like six for py3k, or like django-compat for django), but directly monkey-patch django with log-lifespan shims.

    Thus, django webmaster who want to upgrade wouldn't have to fork/monkeypatch all their broken dependencies, and minor django upgrades would REALLY be minor (i.e would NOT rename/remove methods and attributes used by tons of unmaintained libs).

    Would you be OK with integrating this monkey-patching utility to django-compat, to have an all-in-one solution, for BOTH library maintainers and library users ?

    opened by pakal 2
  • render_to_string - Django 1.8 changed how templates operate

    render_to_string - Django 1.8 changed how templates operate

    • http://django.readthedocs.org/en/latest/topics/templates.html#django.template.loader.render_to_string

    • based on https://github.com/mysociety/mapit/blob/master/mapit/djangopatch.py#L4-L12

      """ Django 1.8 changed how templates operate. """
      import django
      if django.get_version() >= '1.8':
          from django.template.loader import render_to_string
      else:
          from django.template import loader, RequestContext
      
          def render_to_string(template_name, context=None, request=None):
              context_instance = RequestContext(request) if request else None
              return loader.render_to_string(template_name, context, context_instance
      
    enhancement 
    opened by philippeowagner 2
  • New version brokes with Django==1.5.10 and six==1.3.0

    New version brokes with Django==1.5.10 and six==1.3.0

       File "/var/www/.virtualenvs/ditchcity/local/lib/python2.7/site-packages/django/db/models/loading.py", line 72, in _populate
         self.load_app(app_name, True)
       File "/var/www/.virtualenvs/ditchcity/local/lib/python2.7/site-packages/django/db/models/loading.py", line 94, in load_app
         app_module = import_module(app_name)
       File "/var/www/.virtualenvs/ditchcity/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
         __import__(name)
       File "/var/www/.virtualenvs/ditchcity/local/lib/python2.7/site-packages/compat/__init__.py", line 42, in <module>
         from six.moves._thread import get_ident  # noqa
     ImportError: No module named _thread
    
    [email protected]:~$ python --version
    Python 2.7.6
    
    wontfix 
    opened by joac 2
  • ImportError: cannot import name 'LocaleRegexProvider' in Django 2.0a1

    ImportError: cannot import name 'LocaleRegexProvider' in Django 2.0a1

      File "/Users/Bruno/Documents/Workspace/open-source-projects/django-surveys/.tox/py36-djangomaster/lib/python3.6/site-packages/compat/__init__.py", line 388, in <module>
        from django.urls import (
    ImportError: cannot import name 'LocaleRegexProvider'
    

    From the updates in the tests in this PR, I'm under the impression that it was renamed to RegexPattern in Django 2.0a1.

    opened by browniebroke 1
  • Support for Django 1.11 LTS

    Support for Django 1.11 LTS

    Django 1.11 LTS will be the last Django version to support Python 2. The next major release, Django 2.0, will only support Python 3.5+. So Django 1.11.x will probably be the last supported version for LTS-to-LTS support of django-compat (1.8-1.11). See Django's release notes for more.

    enhancement help wanted 
    opened by philippeowagner 1
  • GitHub project blurb doesn't mention Django 1.10

    GitHub project blurb doesn't mention Django 1.10

    This GitHub project doesn't mention Django 1.10 in the blurb:

    Screenshot

    It needs to match the README file.

    This also affects the blurb in https://djangopackages.org/packages/p/django-compat/

    opened by Flimm 1
  • FileNotFoundError: No such file or directory: README.rst

    FileNotFoundError: No such file or directory: README.rst

    $ ./bin/pip --version
    pip 8.0.2 from /webapps/planexo/lib/python3.4/site-packages (python 3.4)
    
    $ ./bin/pip install django-compat
    Collecting django-compat
      Using cached django-compat-1.0.8.tar.gz
        Complete output from command python setup.py egg_info:
        Traceback (most recent call last):
          File "/tmp/pip-build-1wztbpt3/django-compat/setup.py", line 33, in <module>
            long_description=read('README.rst')
          File "/tmp/pip-build-1wztbpt3/django-compat/setup.py", line 17, in read
            return open(get_path(fname)).read()
        FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-build-1wztbpt3/django-compat/README.rst'
    
        During handling of the above exception, another exception occurred:
    
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "/tmp/pip-build-1wztbpt3/django-compat/setup.py", line 36, in <module>
            long_description=read('README.md')
          File "/tmp/pip-build-1wztbpt3/django-compat/setup.py", line 17, in read
            return open(get_path(fname)).read()
          File "/webapps/planexo/lib/python3.4/encodings/ascii.py", line 26, in decode
            return codecs.ascii_decode(input, self.errors)[0]
        UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 8678: ordinal not in range(128)
    
        ----------------------------------------
    Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-1wztbpt3/django-compat
    
    opened by SebCorbin 1
  • Test on Python 2.6, 3.2, 3.3 with supported Djangos

    Test on Python 2.6, 3.2, 3.3 with supported Djangos

    NB: This includes the Tox support added by #32

    • Fix compat.get_ident() on Python 3.2
    • Fix compat.tests.test_compat.CompatTests.test_compat() on Python 2.6
    • Fix compat.tests.test_compat.CompatTests.test_format_html() on Python 2.6

    NB: This doesn't include Python 2.5, even though it's supported by Django 1.4

    opened by moreati 1
  • Communicate supported Django version in README

    Communicate supported Django version in README

    These points should be better communicated in the README

    • [x] what version of Django is supported and unsupported anymore
    • [ ] Version convention from django-compat to Django

    Please note #17 as well that aims to show what works in wich version and if its tested.

    opened by philippeowagner 1
  • Django 2.1

    Django 2.1

    Tests fail with

      File "/home/abuild/rpmbuild/BUILD/django-compat-1.0.15/compat/tests/urls.py", line 5, in <module>
        url(r'^accounts/logout/$', views.logout, name='logout'),
    AttributeError: module 'django.contrib.auth.views' has no attribute 'logout'
    

    Fairly simple to fix https://stackoverflow.com/questions/47065438/attributeerror-module-django-contrib-auth-views-has-no-attribute

    opened by jayvdb 2
  • Add django >= 1.10 as a requirement.

    Add django >= 1.10 as a requirement.

    The lack of this creates dependency problem as provided by setup.py.

    See the following Debian bugs:

    • https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=896337
    • https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=896205
    opened by stylesen 1
  • URLs include for Django 2.0

    URLs include for Django 2.0

    The next version of Django is changing quite radically the way URLs are being included, by requiring an app name to be provided. One way to do it (and sometimes the only one) is to change the first parameter to a tuple.

    It would be great if there could be a version of include in django-compat. It looks like the new syntax is available from 1.9, and the old syntax is no longer working from 2.0.

    Would that be an acceptable change? I could try to put together a PR if so.

    opened by browniebroke 1
Releases(v1.0.15)
Owner
arteria GmbH
Wir machen Web.
arteria GmbH
Django admin CKEditor integration.

Django CKEditor NOTICE: django-ckeditor 5 has backward incompatible code moves against 4.5.1. File upload support has been moved to ckeditor_uploader.

2.2k Dec 31, 2022
The Django Leaflet Admin List package provides an admin list view featured by the map and bounding box filter for the geo-based data of the GeoDjango.

The Django Leaflet Admin List package provides an admin list view featured by the map and bounding box filter for the geo-based data of the GeoDjango. It requires a django-leaflet package.

Vsevolod Novikov 33 Nov 11, 2022
Returns unicode slugs

Python Slugify A Python slugify application that handles unicode. Overview Best attempt to create slugs from unicode strings while keeping it DRY. Not

Val Neekman (AvidCoder) 1.3k Dec 23, 2022
A web app which allows user to query the weather info of any place in the world

weather-app This is a web app which allows user to get the weather info of any place in the world as soon as possible. It makes use of OpenWeatherMap

Oladipo Adesiyan 3 Sep 20, 2021
a little task queue for python

a lightweight alternative. huey is: a task queue (2019-04-01: version 2.0 released) written in python (2.7+, 3.4+) clean and simple API redis, sqlite,

Charles Leifer 4.3k Dec 29, 2022
A pluggable Django application for integrating PayPal Payments Standard or Payments Pro

Django PayPal Django PayPal is a pluggable application that integrates with PayPal Payments Standard and Payments Pro. See https://django-paypal.readt

Luke Plant 672 Dec 22, 2022
Super simple bar charts for django admin list views visualizing the number of objects based on date_hierarchy using Chart.js.

Super simple bar charts for django admin list views visualizing the number of objects based on date_hierarchy using Chart.js.

foorilla LLC 4 May 18, 2022
Radically simplified static file serving for Python web apps

WhiteNoise Radically simplified static file serving for Python web apps With a couple of lines of config WhiteNoise allows your web app to serve its o

Dave Evans 2.1k Dec 15, 2022
A simple demonstration of how a django-based website can be set up for local development with microk8s

Django with MicroK8s Start Building Your Project This project provides a Django web app running as a single node Kubernetes cluster in microk8s. It is

Noah Jacobson 19 Oct 22, 2022
Django-MySQL extends Django's built-in MySQL and MariaDB support their specific features not available on other databases.

Django-MySQL The dolphin-pony - proof that cute + cute = double cute. Django-MySQL extends Django's built-in MySQL and MariaDB support their specific

Adam Johnson 504 Jan 04, 2023
A pickled object field for Django

django-picklefield About django-picklefield provides an implementation of a pickled object field. Such fields can contain any picklable objects. The i

Gintautas Miliauskas 167 Oct 18, 2022
🗂️ 🔍 Geospatial Data Management and Search API - Django Apps

Geospatial Data API in Django Resonant GeoData (RGD) is a series of Django applications well suited for cataloging and searching annotated geospatial

Resonant GeoData 53 Nov 01, 2022
E-Commerce Platform

Shuup Shuup is an Open Source E-Commerce Platform based on Django and Python. https://shuup.com/ Copyright Copyright (c) 2012-2021 by Shuup Commerce I

Shuup 2k Jan 07, 2023
Source files for a free pyRevit toolbar.

pyRoovit (WIP) What is this? PyRoovit is/will be a toolbar for the use with pyRevit built by Gavin Crump (aka Aussie BIM Guru). Having used and taught

Gavin Crump 11 Nov 10, 2022
This is a Django app that uses numerous Google APIs such as reCAPTURE, maps and waypoints

Django project that uses Googles APIs to auto populate fields, display maps and routes for multiple waypoints

Bobby Stearman 57 Dec 03, 2022
Django Course Project - TextCorrector

Django-TextUtils Django Course Project A tool for analyzing text data in Django backend. It is a project where you can do some of the things with you

1 Oct 29, 2021
Organize Django settings into multiple files and directories. Easily override and modify settings. Use wildcards and optional settings files.

Organize Django settings into multiple files and directories. Easily override and modify settings. Use wildcards in settings file paths and mark setti

Nikita Sobolev 940 Jan 03, 2023
Run Django tests with testcontainers.

django-rdtwt (Run Django Tests With Testcontainers) This targets users who wish to forget setting up a database for tests. There's no manually startin

2 Jan 09, 2022
TinyApp - A Python (Django) Full Stack Application for shortening URLs

TinyApp A Python (Django) Full Stack Application for shortening URLs. How to sta

Li Deng 1 Jan 23, 2022
Advanced school management system written in Django :)

Advanced school management system written in Django :) ⚙️ Config the project First you should make venv for this project. So in the main root of proje

AminAli Mazarian 72 Dec 05, 2022