Skip to content

Commit 337cead

Browse files
committed
Merge pull request #4 from tfroehlich82/master
Fixed example-project for use with Django 1.8
2 parents 6a32bdd + e3c779a commit 337cead

File tree

5 files changed

+44
-29
lines changed

5 files changed

+44
-29
lines changed

djangoplugins/fields.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
class PluginField(models.ForeignKey):
11-
def __init__(self, point=None, **kwargs):
11+
def __init__(self, point=None, *args, **kwargs):
1212
# Normal path.
1313
if point is not None:
1414
kwargs['limit_choices_to'] = {
@@ -18,11 +18,11 @@ def __init__(self, point=None, **kwargs):
1818
else:
1919
if "to" in kwargs:
2020
del kwargs["to"]
21-
super(PluginField, self).__init__(Plugin, **kwargs)
21+
super(PluginField, self).__init__(Plugin, *args, **kwargs)
2222

2323

2424
class ManyPluginField(models.ManyToManyField):
25-
def __init__(self, point=None, **kwargs):
25+
def __init__(self, point=None, *args, **kwargs):
2626
# Normal path.
2727
if point is not None:
2828
kwargs['limit_choices_to'] = {
@@ -32,7 +32,7 @@ def __init__(self, point=None, **kwargs):
3232
else:
3333
if "to" in kwargs:
3434
del kwargs["to"]
35-
super(ManyPluginField, self).__init__(Plugin, **kwargs)
35+
super(ManyPluginField, self).__init__(Plugin, *args, **kwargs)
3636

3737

3838
def get_plugins_qs(point):
@@ -43,7 +43,7 @@ class PluginChoiceField(forms.ModelChoiceField):
4343
def __init__(self, point, *args, **kwargs):
4444
kwargs['to_field_name'] = 'name'
4545
super(PluginChoiceField, self).\
46-
__init__(queryset=get_plugins_qs(point), *args, **kwargs)
46+
__init__(queryset=get_plugins_qs(point), **kwargs)
4747

4848
def to_python(self, value):
4949
value = super(PluginChoiceField, self).to_python(value)
@@ -57,16 +57,16 @@ class PluginMultipleChoiceField(forms.ModelMultipleChoiceField):
5757
def __init__(self, point, *args, **kwargs):
5858
kwargs['to_field_name'] = 'name'
5959
super(PluginMultipleChoiceField, self).\
60-
__init__(queryset=get_plugins_qs(point), *args, **kwargs)
60+
__init__(queryset=get_plugins_qs(point), **kwargs)
6161

6262

6363
class PluginModelChoiceField(forms.ModelChoiceField):
6464
def __init__(self, point, *args, **kwargs):
6565
super(PluginModelChoiceField, self).\
66-
__init__(queryset=get_plugins_qs(point), *args, **kwargs)
66+
__init__(queryset=get_plugins_qs(point), **kwargs)
6767

6868

6969
class PluginModelMultipleChoiceField(forms.ModelMultipleChoiceField):
7070
def __init__(self, point, *args, **kwargs):
7171
super(PluginModelMultipleChoiceField, self).\
72-
__init__(queryset=get_plugins_qs(point), *args, **kwargs)
72+
__init__(queryset=get_plugins_qs(point), **kwargs)

example-project/mycmsproject/forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
class ContentForm(forms.ModelForm):
99
class Meta:
1010
model = Content
11+
fields = '__all__'

example-project/mycmsproject/settings.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
Django settings for mycmsproject project.
33
44
For more information on this file, see
5-
https://docs.djangoproject.com/en/1.6/topics/settings/
5+
https://docs.djangoproject.com/en/1.8/topics/settings/
66
77
For the full list of settings and their values, see
8-
https://docs.djangoproject.com/en/1.6/ref/settings/
8+
https://docs.djangoproject.com/en/1.8/ref/settings/
99
"""
10-
from __future__ import absolute_import
1110

1211
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
1312
import os
@@ -23,7 +22,6 @@
2322
# SECURITY WARNING: don't run with debug turned on in production!
2423
DEBUG = True
2524

26-
TEMPLATE_DEBUG = True
2725

2826
ALLOWED_HOSTS = []
2927

@@ -57,7 +55,7 @@
5755

5856

5957
# Database
60-
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases
58+
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
6159

6260
DATABASES = {
6361
'default': {
@@ -67,7 +65,7 @@
6765
}
6866

6967
# Internationalization
70-
# https://docs.djangoproject.com/en/1.6/topics/i18n/
68+
# https://docs.djangoproject.com/en/1.8/topics/i18n/
7169

7270
LANGUAGE_CODE = 'en-us'
7371

@@ -81,6 +79,6 @@
8179

8280

8381
# Static files (CSS, JavaScript, Images)
84-
# https://docs.djangoproject.com/en/1.6/howto/static-files/
82+
# https://docs.djangoproject.com/en/1.8/howto/static-files/
8583

8684
STATIC_URL = '/static/'

example-project/mycmsproject/urls.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1+
"""
2+
The `urlpatterns` list routes URLs to views. For more information please see:
3+
https://docs.djangoproject.com/en/1.8/topics/http/urls/
4+
Examples:
5+
Function views
6+
1. Add an import: from my_app import views
7+
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
8+
Class-based views
9+
1. Add an import: from other_app.views import Home
10+
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
11+
Including another URLconf
12+
1. Add an import: from blog import urls as blog_urls
13+
2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls))
14+
"""
115
from __future__ import absolute_import
216

3-
from django.conf.urls import patterns, url
17+
from django.conf.urls import url, patterns
418

519
from djangoplugins.utils import include_plugins
6-
720
from .plugins import ContentType
821

922
urlpatterns = patterns(

example-project/mycmsproject/views.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import absolute_import
2+
from django.http import HttpResponseRedirect
23

34
from django.shortcuts import render
45
from django.shortcuts import get_object_or_404
@@ -13,10 +14,10 @@ def index(request):
1314

1415

1516
def content_list(request, plugin):
16-
return render(request, 'content/list.html', dict(
17-
plugin=ContentType.get_plugin(plugin),
18-
posts=Content.objects.all(),
19-
))
17+
return render(request, 'content/list.html', {
18+
'plugin': ContentType.get_plugin(plugin),
19+
'posts': Content.objects.all(),
20+
})
2021

2122

2223
def content_create(request, plugin):
@@ -27,18 +28,20 @@ def content_create(request, plugin):
2728
content = form.save(commit=False)
2829
content.plugin = plugin.get_model()
2930
content.save()
30-
return content.get_absolute_url()
31+
return HttpResponseRedirect(content.get_absolute_url())
32+
else:
33+
return "[ERROR] from views: {0}".format(form.errors)
3134
else:
3235
form = ContentForm()
33-
return render(request, 'content/form.html', dict(
34-
form=form,
35-
))
36+
return render(request, 'content/form.html', {
37+
'form': form,
38+
})
3639

3740

3841
def content_read(request, pk, plugin):
3942
plugin = ContentType.get_plugin(plugin)
4043
content = get_object_or_404(Content, pk=pk, plugin=plugin.get_model())
41-
return render(request, 'content/read.html', dict(
42-
plugin=plugin,
43-
content=content,
44-
))
44+
return render(request, 'content/read.html', {
45+
'plugin': plugin,
46+
'content': content,
47+
})

0 commit comments

Comments
 (0)