Skip to content

Commit f3dce90

Browse files
author
Christina Roberts
authored
Merge pull request #24 from edx/christina/1_11_upgrade
Updates for Django 1.11.
2 parents 144a816 + f749c67 commit f3dce90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+303
-265
lines changed

django_notify/__init__.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +0,0 @@
1-
from django.contrib.contenttypes.models import ContentType
2-
from django.db.models import Model
3-
from django.utils.translation import ugettext as _
4-
5-
import models
6-
7-
_disable_notifications = False
8-
9-
def notify(message, key, target_object=None, url=None):
10-
"""
11-
Notify subscribing users of a new event. Key can be any kind of string,
12-
just make sure to reuse it where applicable! Object_id is some identifier
13-
of an object, for instance if a user subscribes to a specific comment thread,
14-
you could write:
15-
16-
notify("there was a response to your comment", "comment_response",
17-
target_object=PostersObject,
18-
url=reverse('comments:view', args=(PostersObject.id,)))
19-
20-
The below example notifies everyone subscribing to the "new_comments" key
21-
with the message "New comment posted".
22-
23-
notify("New comment posted", "new_comments")
24-
25-
"""
26-
27-
if _disable_notifications:
28-
return 0
29-
30-
if target_object:
31-
if not isinstance(target_object, Model):
32-
raise TypeError(_(u"You supplied a target_object that's not an instance of a django Model."))
33-
object_id = target_object.id
34-
else:
35-
object_id = None
36-
37-
objects = models.Notification.create_notifications(key, object_id=object_id,
38-
message=message, url=url)
39-
return len(objects)
40-

django_notify/models.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# -*- coding: utf-8 -*-
22
from django.db import models
3-
from django.db.models import Q
3+
from django.db.models import Q, Model
44
from django.contrib.auth.models import User
55
from django.utils.translation import ugettext_lazy as _
66

77
from django.contrib.contenttypes.models import ContentType
88

99
from django_notify import settings
1010

11+
_disable_notifications = False
12+
1113
class NotificationType(models.Model):
1214
"""
1315
Notification types are added on-the-fly by the
@@ -105,3 +107,36 @@ class Meta:
105107
db_table = settings.DB_TABLE_PREFIX + '_notification'
106108
verbose_name = _(u'notification')
107109
verbose_name_plural = _(u'notifications')
110+
111+
112+
def notify(message, key, target_object=None, url=None):
113+
"""
114+
Notify subscribing users of a new event. Key can be any kind of string,
115+
just make sure to reuse it where applicable! Object_id is some identifier
116+
of an object, for instance if a user subscribes to a specific comment thread,
117+
you could write:
118+
119+
notify("there was a response to your comment", "comment_response",
120+
target_object=PostersObject,
121+
url=reverse('comments:view', args=(PostersObject.id,)))
122+
123+
The below example notifies everyone subscribing to the "new_comments" key
124+
with the message "New comment posted".
125+
126+
notify("New comment posted", "new_comments")
127+
128+
"""
129+
130+
if _disable_notifications:
131+
return 0
132+
133+
if target_object:
134+
if not isinstance(target_object, Model):
135+
raise TypeError(_(u"You supplied a target_object that's not an instance of a django Model."))
136+
object_id = target_object.id
137+
else:
138+
object_id = None
139+
140+
objects = Notification.create_notifications(key, object_id=object_id,
141+
message=message, url=url)
142+
return len(objects)

django_notify/urls.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# -*- coding: utf-8 -*-
2-
from django.conf.urls import patterns, url
2+
from django.conf.urls import url
3+
from django_notify import views
34

4-
urlpatterns = patterns('',
5-
url('^json/get/$', 'django_notify.views.get_notifications', name='json_get', kwargs={}),
6-
url('^json/mark-read/$', 'django_notify.views.mark_read', name='json_mark_read_base', kwargs={}),
7-
url('^json/mark-read/(\d+)/$', 'django_notify.views.mark_read', name='json_mark_read', kwargs={}),
8-
url('^goto/(?P<notification_id>\d+)/$', 'django_notify.views.goto', name='goto', kwargs={}),
9-
url('^goto/$', 'django_notify.views.goto', name='goto_base', kwargs={}),
10-
)
5+
urlpatterns = [
6+
url('^json/get/$', views.get_notifications, name='json_get', kwargs={}),
7+
url('^json/mark-read/$', views.mark_read, name='json_mark_read_base', kwargs={}),
8+
url('^json/mark-read/(\d+)/$', views.mark_read, name='json_mark_read', kwargs={}),
9+
url('^goto/(?P<notification_id>\d+)/$', views.goto, name='goto', kwargs={}),
10+
url('^goto/$', views.goto, name='goto_base', kwargs={}),
11+
]
1112

1213
def get_pattern(app_name="notify", namespace="notify"):
1314
"""Every url resolution takes place as "notify:view_name".

requirements.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
django<1.9
2-
South==1.0.1
3-
Markdown<2.3.0
4-
django-sekizai<0.7
5-
django-mptt<0.8
6-
sorl-thumbnail<13
1+
django>=1.8,<2.0
2+
Markdown>=2.6,<2.7
3+
django-sekizai>=0.10
4+
django-mptt>=0.8.6,<0.9
5+
sorl-thumbnail>=12,<13
6+
six>=1.10.0,<2.0.0

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def build_media_pattern(base_folder, file_extension):
2929

3030
setup(
3131
name = "django-wiki",
32-
version = "0.0.10",
32+
version="0.0.11",
3333
author = "Benjamin Bach",
3434
author_email = "[email protected]",
3535
description = ("A wiki system written for the Django framework."),
@@ -39,7 +39,7 @@ def build_media_pattern(base_folder, file_extension):
3939
long_description=read('README.md'),
4040
zip_safe = False,
4141
install_requires=[
42-
'Django>=1.4',
42+
'Django>=1.8',
4343
'markdown',
4444
'django-sekizai',
4545
'django-mptt',
0 Bytes
Binary file not shown.

testproject/testproject/settings.py

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
PROJECT_PATH = os_path.abspath(os_path.split(__file__)[0])
44

55
DEBUG = True
6-
TEMPLATE_DEBUG = DEBUG
76

87
ADMINS = (
98
# ('Your Name', '[email protected]'),
@@ -47,22 +46,9 @@
4746

4847
STATIC_ROOT = os_path.join(PROJECT_PATH, 'static')
4948
STATIC_URL = '/static/'
50-
STATICFILES_DIRS = (
51-
)
52-
STATICFILES_FINDERS = (
53-
'django.contrib.staticfiles.finders.FileSystemFinder',
54-
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
55-
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
56-
)
5749

5850
SECRET_KEY = 'b^fv_)t39h%9p40)fnkfblo##jkr!$0)lkp6bpy!fi*f$4*92!'
5951

60-
TEMPLATE_LOADERS = (
61-
'django.template.loaders.filesystem.Loader',
62-
'django.template.loaders.app_directories.Loader',
63-
# 'django.template.loaders.eggs.Loader',
64-
)
65-
6652
MIDDLEWARE_CLASSES = (
6753
'django.middleware.common.CommonMiddleware',
6854
'django.contrib.sessions.middleware.SessionMiddleware',
@@ -79,22 +65,31 @@
7965
# Python dotted path to the WSGI application used by Django's runserver.
8066
WSGI_APPLICATION = 'testproject.wsgi.application'
8167

82-
TEMPLATE_DIRS = (
83-
'templates',
84-
)
85-
86-
TEMPLATE_CONTEXT_PROCESSORS =(
87-
'django.contrib.auth.context_processors.auth',
88-
'django.core.context_processors.debug',
89-
'django.core.context_processors.i18n',
90-
'django.core.context_processors.media',
91-
'django.core.context_processors.static',
92-
'django.core.context_processors.tz',
93-
'django.contrib.messages.context_processors.messages',
94-
'sekizai.context_processors.sekizai',
95-
)
68+
TEMPLATES = [
69+
{
70+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
71+
'DIRS': [
72+
os_path.join(PROJECT_PATH, 'templates'),
73+
],
74+
'APP_DIRS': True,
75+
'OPTIONS': {
76+
'context_processors': [
77+
"django.contrib.auth.context_processors.auth",
78+
"django.template.context_processors.debug",
79+
"django.template.context_processors.i18n",
80+
"django.template.context_processors.media",
81+
"django.template.context_processors.static",
82+
"django.template.context_processors.request",
83+
"django.template.context_processors.tz",
84+
"django.contrib.messages.context_processors.messages",
85+
"sekizai.context_processors.sekizai",
86+
],
87+
'debug': DEBUG,
88+
},
89+
},
90+
]
9691

97-
INSTALLED_APPS = (
92+
INSTALLED_APPS = [
9893
'django.contrib.humanize',
9994
'django.contrib.auth',
10095
'django.contrib.contenttypes',
@@ -114,7 +109,7 @@
114109
'wiki.plugins.attachments',
115110
'wiki.plugins.notifications',
116111
'mptt',
117-
)
112+
]
118113

119114
# A sample logging configuration. The only tangible logging
120115
# performed by this configuration is to send an email to
@@ -146,3 +141,6 @@
146141
}
147142

148143
WIKI_ANONYMOUS_WRITE = True
144+
145+
# We disable this in edx-platform lms/envs/common.py, so disabling for test project also.
146+
WIKI_USE_BOOTSTRAP_SELECT_WIDGET = False

testproject/testproject/urls.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
from django.conf.urls import patterns, include, url
1+
from django.conf.urls import include, url
22
from django.conf import settings
33
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
4+
from django.views.static import serve as static_serve
45

56
from django.contrib import admin
67
admin.autodiscover()
78

8-
urlpatterns = patterns('',
9-
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
9+
urlpatterns = [
1010
url(r'^admin/', include(admin.site.urls)),
11-
url(r'^notify/', include('django_notify.urls', namespace='notify')),
12-
)
11+
]
1312

1413
if settings.DEBUG:
1514
urlpatterns += staticfiles_urlpatterns()
16-
urlpatterns += patterns('',
17-
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
18-
'document_root': settings.MEDIA_ROOT,
19-
}),
20-
)
15+
urlpatterns += [
16+
url(r'^media/(?P<path>.*)$', static_serve, {'document_root': settings.MEDIA_ROOT}),
17+
]
18+
2119

2220
from wiki.urls import get_pattern as get_wiki_pattern
2321
from django_notify.urls import get_pattern as get_notify_pattern
24-
urlpatterns += patterns('',
25-
(r'^notify/', get_notify_pattern()),
26-
(r'', get_wiki_pattern())
27-
)
22+
23+
urlpatterns += [
24+
url(r'^notify/', get_notify_pattern()),
25+
url(r'', get_wiki_pattern()),
26+
]

wiki/conf/settings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
URL_CASE_SENSITIVE = getattr(django_settings, 'WIKI_URL_CASE_SENSITIVE', False)
77

88
# Non-configurable (at the moment)
9-
APP_LABEL = 'wiki'
109
WIKI_LANGUAGE = 'markdown'
1110

1211
# The editor class to use -- maybe a 3rd party or your own...? You can always

wiki/core/compat.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Django 1.11 Widget.build_attrs has a different signature, designed for the new
2+
# template based rendering. The previous version was more useful for our needs,
3+
# so we restore that version.
4+
# When support for Django < 1.11 is dropped, we should look at using the
5+
# new template based rendering, at which point this probably won't be needed at all.
6+
class BuildAttrsCompat(object):
7+
def build_attrs_compat(self, extra_attrs=None, **kwargs):
8+
"Helper function for building an attribute dictionary."
9+
attrs = self.attrs.copy()
10+
if extra_attrs is not None:
11+
attrs.update(extra_attrs)
12+
if kwargs is not None:
13+
attrs.update(kwargs)
14+
return attrs

0 commit comments

Comments
 (0)