Skip to content

Commit

Permalink
Implementing support for Django 4, dropping support for Django 1 and 2
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Dec 17, 2021
1 parent 5589cc9 commit 69e9569
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 96 deletions.
27 changes: 10 additions & 17 deletions flat/modes/editor/urls.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
#from django.conf.urls import patterns, include, url
from django import VERSION
if VERSION[0] > 1 or VERSION[1] >= 8: #Django 1.8 and higher
from django.conf.urls import url, include
elif VERSION[1] >= 6: #Django 1.6
from django.conf.urls import patterns, url, include
else:
from django.conf.urls.defaults import *
from django.urls import re_path, include

import flat.modes.editor.views

urlpatterns = [
# Examples:
url(r'^pub/(?P<configuration>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/?$', flat.modes.editor.views.pub_view, name='view'),
url(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/history/?$', flat.modes.editor.views.history, name='history'),
url(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/revert/(?P<commithash>[a-f0-9]*)/?$', flat.modes.editor.views.revert, name='revert'),
url(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/save/?$', flat.modes.editor.views.save, name='save'),
url(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/?$', flat.modes.editor.views.view, name='view'),
re_path(r'^pub/(?P<configuration>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/?$', flat.modes.editor.views.pub_view, name='view'),
re_path(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/history/?$', flat.modes.editor.views.history, name='history'),
re_path(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/revert/(?P<commithash>[a-f0-9]*)/?$', flat.modes.editor.views.revert, name='revert'),
re_path(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/save/?$', flat.modes.editor.views.save, name='save'),
re_path(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/?$', flat.modes.editor.views.view, name='view'),

#redeclare viewer stuff: (why?)
url(r'^pub/(?P<docid>[\w\d\-_\.]+)/poll/?$', flat.modes.viewer.views.pub_poll, name='poll'),
url(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/poll/?$', flat.modes.viewer.views.poll, name='poll'),
url(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/query/?$', flat.modes.viewer.views.query, name='query'),
#url(r'^(?P<namespace>[\w\d\-_\./]+)/(?P<docid>[\w\d\-_\.]+)/(?P<elementid>[\w\d\-_\.]+)/?$', 'flat.modes.viewer.views.subview', name='subview'),
re_path(r'^pub/(?P<docid>[\w\d\-_\.]+)/poll/?$', flat.modes.viewer.views.pub_poll, name='poll'),
re_path(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/poll/?$', flat.modes.viewer.views.poll, name='poll'),
re_path(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/query/?$', flat.modes.viewer.views.query, name='query'),
#re_path(r'^(?P<namespace>[\w\d\-_\./]+)/(?P<docid>[\w\d\-_\.]+)/(?P<elementid>[\w\d\-_\.]+)/?$', 'flat.modes.viewer.views.subview', name='subview'),
]

if VERSION[0] == 1 and VERSION[1] < 8: #Django <1.8
urlpatterns = patterns('',*urlpatterns)
12 changes: 2 additions & 10 deletions flat/modes/metadata/urls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
#from django.conf.urls import patterns, include, url
from django import VERSION
if VERSION[0] > 1 or VERSION[1] >= 8: #Django 1.8 and higher
from django.conf.urls import url, include
elif VERSION[1] >= 6: #Django 1.6
from django.conf.urls import patterns, url, include
else:
from django.conf.urls.defaults import *
from django.urls import re_path, include

import flat.modes.metadata.views

urlpatterns = [
url(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/?$', flat.modes.metadata.views.view, name='view'),
re_path(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/?$', flat.modes.metadata.views.view, name='view'),
]

if VERSION[0] == 1 and VERSION[1] < 8: #Django <1.8
urlpatterns = patterns('',*urlpatterns)
13 changes: 3 additions & 10 deletions flat/modes/structureeditor/urls.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
#from django.conf.urls import patterns, include, url
from django import VERSION
if VERSION[0] > 1 or VERSION[1] >= 8: #Django 1.8 and higher
from django.conf.urls import url, include
elif VERSION[1] >= 6: #Django 1.6
from django.conf.urls import patterns, url, include
else:
from django.conf.urls.defaults import *
from django.urls import re_path, include

import flat.modes.structureeditor.views

urlpatterns = [
# Examples:
url(r'^(?P<namespace>[\w\-_\.@]+)/(?P<docid>[\w\-\.]+)/?$', flat.modes.structureeditor.views.view, name='view'),
#url(r'^(?P<namespace>[\w\-\.]+)/(?P<docid>[\w\-\.]+)/annotate/?$', 'flat.modes.structureeditor.views.annotate', name='annotate'),
re_path(r'^(?P<namespace>[\w\-_\.@]+)/(?P<docid>[\w\-\.]+)/?$', flat.modes.structureeditor.views.view, name='view'),
#re_path(r'^(?P<namespace>[\w\-\.]+)/(?P<docid>[\w\-\.]+)/annotate/?$', 'flat.modes.structureeditor.views.annotate', name='annotate'),
]

if VERSION[0] == 1 and VERSION[1] < 8: #Django <1.8
urlpatterns = patterns('',*urlpatterns)
17 changes: 5 additions & 12 deletions flat/modes/viewer/urls.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
#from django.conf.urls import patterns, include, url
from django import VERSION
if VERSION[0] > 1 or VERSION[1] >= 8: #Django 1.8 and higher
from django.conf.urls import url, include
elif VERSION[1] >= 6: #Django 1.6
from django.conf.urls import patterns, url, include
else:
from django.conf.urls.defaults import *
from django.urls import re_path, include

import flat.modes.viewer.views

urlpatterns = [
# Examples:
url(r'^pub/(?P<docid>[\w\d\-_\.]+)/poll/?$', flat.modes.viewer.views.pub_poll, name='poll'),
url(r'^pub/(?P<configuration>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/?$', flat.modes.viewer.views.pub_view, name='view'),
url(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/poll/?$', flat.modes.viewer.views.poll, name='poll'),
url(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/?$', flat.modes.viewer.views.view, name='view'),
re_path(r'^pub/(?P<docid>[\w\d\-_\.]+)/poll/?$', flat.modes.viewer.views.pub_poll, name='poll'),
re_path(r'^pub/(?P<configuration>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/?$', flat.modes.viewer.views.pub_view, name='view'),
re_path(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/poll/?$', flat.modes.viewer.views.poll, name='poll'),
re_path(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/?$', flat.modes.viewer.views.view, name='view'),
]

if VERSION[0] == 1 and VERSION[1] < 8: #Django <1.8
urlpatterns = patterns('',*urlpatterns)
77 changes: 32 additions & 45 deletions flat/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,55 @@

from django.contrib import admin, auth

if VERSION[0] >= 2 or VERSION[1] >= 8: #Django 1.8 and higher
from django.conf.urls import url, include
from django.conf.urls.static import static
elif VERSION[1] >= 6: #Django 1.6
from django.conf.urls import patterns, url, include
from django.conf.urls.static import static
else:
from django.conf.urls.defaults import *
from django.urls import re_path, include
from django.conf.urls.static import static

from django.conf import settings
import flat.views
admin.autodiscover()

urlpatterns = [
# Examples:
url(r'^$', flat.views.index, name='index'),
url(r'^index/?$', flat.views.index, name='index'),
url(r'^pub/?$', flat.views.pub, name='pub'),
url(r'^config/?$', flat.views.config, name='config'),
url(r'^index/(?P<namespace>[\w\d\-_\./@]+)/?$', flat.views.index, name='index'),
url(r'^login/?$', flat.views.login, name='login'),
url(r'^selectconf/?$', flat.views.selectconf, name='selectconf'),
url(r'^logout/?$', flat.views.logout, name='logout'),
url(r'^account/', include('django.contrib.auth.urls')),
url(r'^admin/', admin.site.urls if VERSION[0] >= 2 else include(admin.site.urls)),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^register/?$', flat.views.register, name='register'),
url(r'^download/pub/(?P<docid>[\w\d\-_\.]+)\.folia\.xml/?$', flat.views.pub_download, name='download'),
url(r'^download/pub/(?P<docid>[\w\d\-_\.]+)/?$', flat.views.pub_download, name='download'),
url(r'^download/(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)\.folia\.xml/?$', flat.views.download, name='download'),
url(r'^download/(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/?$', flat.views.download, name='download'),
url(r'^pub/upload/?$', flat.views.pub_upload, name='pub_upload'),
url(r'^upload/?$', flat.views.upload, name='upload'),
url(r'^filemanagement/?$', flat.views.filemanagement, name='filemanagement'),
url(r'^addnamespace/?$', flat.views.addnamespace, name='addnamespace'),
url(r'^pub/(?P<configuration>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/query/?$', flat.views.pub_query, name='query'), #generic query function
url(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/query/?$', flat.views.query, name='query'), #generic query function
url('^oidc/', include('mozilla_django_oidc.urls')),
# url(r'^flat/', include('flat.foo.urls')),
re_path(r'^$', flat.views.index, name='index'),
re_path(r'^index/?$', flat.views.index, name='index'),
re_path(r'^pub/?$', flat.views.pub, name='pub'),
re_path(r'^config/?$', flat.views.config, name='config'),
re_path(r'^index/(?P<namespace>[\w\d\-_\./@]+)/?$', flat.views.index, name='index'),
re_path(r'^login/?$', flat.views.login, name='login'),
re_path(r'^selectconf/?$', flat.views.selectconf, name='selectconf'),
re_path(r'^logout/?$', flat.views.logout, name='logout'),
re_path(r'^account/', include('django.contrib.auth.urls')),
re_path(r'^admin/', admin.site.urls if VERSION[0] >= 2 else include(admin.site.urls)),
re_path(r'^admin/doc/', include('django.contrib.admindocs.urls')),
re_path(r'^register/?$', flat.views.register, name='register'),
re_path(r'^download/pub/(?P<docid>[\w\d\-_\.]+)\.folia\.xml/?$', flat.views.pub_download, name='download'),
re_path(r'^download/pub/(?P<docid>[\w\d\-_\.]+)/?$', flat.views.pub_download, name='download'),
re_path(r'^download/(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)\.folia\.xml/?$', flat.views.download, name='download'),
re_path(r'^download/(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/?$', flat.views.download, name='download'),
re_path(r'^pub/upload/?$', flat.views.pub_upload, name='pub_upload'),
re_path(r'^upload/?$', flat.views.upload, name='upload'),
re_path(r'^filemanagement/?$', flat.views.filemanagement, name='filemanagement'),
re_path(r'^addnamespace/?$', flat.views.addnamespace, name='addnamespace'),
re_path(r'^pub/(?P<configuration>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/query/?$', flat.views.pub_query, name='query'), #generic query function
re_path(r'^(?P<namespace>[\w\d\-_\./@]+)/(?P<docid>[\w\d\-_\.]+)/query/?$', flat.views.query, name='query'), #generic query function
re_path('^oidc/', include('mozilla_django_oidc.urls')),
# re_path(r'^flat/', include('flat.foo.urls')),
]

if VERSION[0] == 1 and VERSION[1] < 8: #Django <1.8
urlpatterns = patterns('',*urlpatterns)

if settings.DEBUG:
if VERSION[0] > 1 or VERSION[1] >= 6: #Django 1.6
urlpatterns += static(settings.STYLE_URL, document_root=settings.STYLE_ROOT)
urlpatterns += static(settings.SCRIPT_URL, document_root=settings.SCRIPT_ROOT)
else:
#Django 1.3
urlpatterns += patterns('',
(r'^style/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STYLE_ROOT}),
(r'^script/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.SCRIPT_ROOT}),
)
if VERSION[0] > 1 or VERSION[1] >= 6: #Django 1.6
urlpatterns += static(settings.STYLE_URL, document_root=settings.STYLE_ROOT)
urlpatterns += static(settings.SCRIPT_URL, document_root=settings.SCRIPT_ROOT)


for mode, _ in settings.MODES:
urlpatterns += [ url(r'^' + mode + '/', include('flat.modes.' + mode + '.urls'))]
urlpatterns += [ re_path(r'^' + mode + '/', include('flat.modes.' + mode + '.urls'))]
if VERSION[0] == 1 and VERSION[1] < 8: #Django <1.8
urlpatterns += patterns('', url(r'^' + mode + '/', include('flat.modes.' + mode + '.urls')))
urlpatterns += patterns('', re_path(r'^' + mode + '/', include('flat.modes.' + mode + '.urls')))
else:
urlpatterns += [ url(r'^' + mode + '/', include('flat.modes.' + mode + '.urls'))]
urlpatterns += [ re_path(r'^' + mode + '/', include('flat.modes.' + mode + '.urls'))]



2 changes: 1 addition & 1 deletion requires.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
folia >= 2.5.4
foliadocserve >= 0.7.6
Django>=1.8.13
Django>=3.0
requests
mozilla_django_oidc
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ def read(fname):
],
zip_safe=False,
package_data = {'flat':['templates/*.html','style/*','script/*'], 'flat.modes.structureeditor':['templates/*.html'], 'flat.modes.viewer':['templates/*.html'], 'flat.modes.editor':['templates/*.html'], 'flat.modes.metadata':['templates/*.html'] },
install_requires=['folia >= 2.5.5','Django >= 1.8','requests', 'foliadocserve >= 0.7.6', 'mozilla-django-oidc']
install_requires=['folia >= 2.5.5','Django >= 3.0','requests', 'foliadocserve >= 0.7.6', 'mozilla-django-oidc']
)

0 comments on commit 69e9569

Please sign in to comment.