forked from ungleich-public/dynamicweb
clone cms with menus, make menus standalone app
This commit is contained in:
parent
1ece5ce7c7
commit
afb096b7a3
1153 changed files with 318897 additions and 37 deletions
0
cms/test_utils/project/sampleapp/__init__.py
Normal file
0
cms/test_utils/project/sampleapp/__init__.py
Normal file
46
cms/test_utils/project/sampleapp/admin.py
Normal file
46
cms/test_utils/project/sampleapp/admin.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from cms.admin.placeholderadmin import FrontendEditableAdminMixin
|
||||
from cms.admin.utils import GrouperModelAdmin
|
||||
from cms.test_utils.project.sampleapp.models import (
|
||||
Category,
|
||||
GrouperModel,
|
||||
Picture,
|
||||
SampleAppConfig,
|
||||
SimpleGrouperModel,
|
||||
SomeEditableModel,
|
||||
)
|
||||
|
||||
|
||||
class PictureInline(admin.StackedInline):
|
||||
model = Picture
|
||||
|
||||
|
||||
class CategoryAdmin(admin.ModelAdmin):
|
||||
inlines = [PictureInline]
|
||||
|
||||
|
||||
class SomeEditableAdmin(FrontendEditableAdminMixin, admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
class GrouperAdmin(GrouperModelAdmin):
|
||||
extra_grouping_fields = ("language",)
|
||||
list_display = ("category_name", "content__secret_greeting", "admin_list_actions")
|
||||
|
||||
def can_change_content(self, request, content_obj):
|
||||
return getattr(self, "change_content", True)
|
||||
|
||||
|
||||
class SimpleGrouperAdmin(GrouperModelAdmin):
|
||||
list_display = ("category_name", "content__secret_greeting", "admin_list_actions")
|
||||
|
||||
def can_change_content(self, request, content_obj):
|
||||
return getattr(self, "change_content", True)
|
||||
|
||||
|
||||
admin.site.register(Category, CategoryAdmin)
|
||||
admin.site.register(SampleAppConfig)
|
||||
admin.site.register(SomeEditableModel, SomeEditableAdmin)
|
||||
admin.site.register(GrouperModel, GrouperAdmin)
|
||||
admin.site.register(SimpleGrouperModel, SimpleGrouperAdmin)
|
||||
151
cms/test_utils/project/sampleapp/cms_apps.py
Normal file
151
cms/test_utils/project/sampleapp/cms_apps.py
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.http import HttpResponse
|
||||
from django.urls import re_path, reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from cms.app_base import CMSApp
|
||||
from cms.apphook_pool import apphook_pool
|
||||
from cms.test_utils.project.sampleapp.cms_menus import (
|
||||
SampleAppMenu,
|
||||
StaticMenu3,
|
||||
StaticMenu4,
|
||||
)
|
||||
|
||||
from .models import SampleAppConfig
|
||||
|
||||
|
||||
class AppWithNoMenu(CMSApp):
|
||||
app_name = 'app_with_no_menu'
|
||||
|
||||
def get_urls(self, page=None, language=None, **kwargs):
|
||||
return ["cms.test_utils.project.sampleapp.urls"]
|
||||
|
||||
|
||||
class SampleApp(CMSApp):
|
||||
name = _("Sample App")
|
||||
permissions = True
|
||||
|
||||
def get_menus(self, page=None, language=None, **kwargs):
|
||||
return [SampleAppMenu]
|
||||
|
||||
def get_urls(self, page=None, language=None, **kwargs):
|
||||
return ["cms.test_utils.project.sampleapp.urls"]
|
||||
|
||||
|
||||
class SampleAppWithConfig(CMSApp):
|
||||
name = _("Sample App with config")
|
||||
app_config = SampleAppConfig
|
||||
|
||||
def get_urls(self, page=None, language=None, **kwargs):
|
||||
return ["cms.test_utils.project.sampleapp.urls_sample_config"]
|
||||
|
||||
def get_configs(self):
|
||||
return self.app_config.objects.all()
|
||||
|
||||
def get_config(self, namespace):
|
||||
try:
|
||||
return self.app_config.objects.get(namespace=namespace)
|
||||
except ObjectDoesNotExist:
|
||||
return None
|
||||
|
||||
def get_config_add_url(self):
|
||||
return reverse(f'admin:{self.app_config._meta.app_label}_{self.app_config._meta.model_name}_add')
|
||||
|
||||
|
||||
class SampleAppWithExcludedPermissions(CMSApp):
|
||||
name = _("Sample App with excluded permissions")
|
||||
permissions = True
|
||||
exclude_permissions = ['excluded']
|
||||
|
||||
def get_urls(self, page=None, language=None, **kwargs):
|
||||
return ["cms.test_utils.project.sampleapp.urls_excluded"]
|
||||
|
||||
|
||||
class SampleApp2(CMSApp):
|
||||
name = _("Sample App 2")
|
||||
|
||||
def get_menus(self, page=None, language=None, **kwargs):
|
||||
return [StaticMenu3]
|
||||
|
||||
def get_urls(self, page=None, language=None, **kwargs):
|
||||
return ["cms.test_utils.project.sampleapp.urls2"]
|
||||
|
||||
|
||||
class SampleApp3(CMSApp):
|
||||
# CMSApp which returns the url directly rather than through another Python module
|
||||
name = _("Sample App 3")
|
||||
|
||||
def get_urls(self, page=None, language=None, **kwargs):
|
||||
def my_view(request):
|
||||
return HttpResponse("Sample App 3 Response")
|
||||
|
||||
return [
|
||||
re_path(r'^$', my_view, name='sample3-root'),
|
||||
]
|
||||
|
||||
|
||||
class SampleAppWithoutLandingPage(CMSApp):
|
||||
# CMSApp that does not define a view at ''
|
||||
|
||||
name = _("Sample App Without Landing Page")
|
||||
|
||||
def get_urls(self, page=None, language=None, **kwargs):
|
||||
return ["cms.test_utils.project.sampleapp.urls_extra"]
|
||||
|
||||
|
||||
class NamespacedApp(CMSApp):
|
||||
name = _("Namespaced App")
|
||||
app_name = 'namespaced_app_ns'
|
||||
|
||||
def get_menus(self, page=None, language=None, **kwargs):
|
||||
return [SampleAppMenu, StaticMenu3]
|
||||
|
||||
def get_urls(self, page=None, language=None, **kwargs):
|
||||
return [
|
||||
"cms.test_utils.project.sampleapp.ns_urls",
|
||||
"cms.test_utils.project.sampleapp.urls"
|
||||
]
|
||||
|
||||
|
||||
class ParentApp(CMSApp):
|
||||
name = _("Parent app")
|
||||
|
||||
def get_urls(self, page=None, language=None, **kwargs):
|
||||
return ["cms.test_utils.project.sampleapp.urls_parentapp"]
|
||||
|
||||
|
||||
class ChildApp(CMSApp):
|
||||
name = _("Child app")
|
||||
|
||||
def get_urls(self, page=None, language=None, **kwargs):
|
||||
return ["cms.test_utils.project.sampleapp.urls_childapp"]
|
||||
|
||||
|
||||
class VariableUrlsApp(CMSApp):
|
||||
name = _("Variable urls-menus App")
|
||||
|
||||
def get_menus(self, page=None, language=None, **kwargs):
|
||||
if page and page.reverse_id == 'page1':
|
||||
return [SampleAppMenu]
|
||||
elif page and page.reverse_id == 'page2':
|
||||
return [StaticMenu4]
|
||||
else:
|
||||
return [StaticMenu4, SampleAppMenu]
|
||||
|
||||
def get_urls(self, page=None, language=None, **kwargs):
|
||||
if page and page.reverse_id == 'page1':
|
||||
return ["cms.test_utils.project.sampleapp.urls"]
|
||||
|
||||
else:
|
||||
return ["cms.test_utils.project.sampleapp.urls2"]
|
||||
|
||||
|
||||
apphook_pool.register(ChildApp)
|
||||
apphook_pool.register(SampleApp)
|
||||
apphook_pool.register(SampleAppWithExcludedPermissions)
|
||||
apphook_pool.register(SampleApp2)
|
||||
apphook_pool.register(SampleApp3)
|
||||
apphook_pool.register(SampleAppWithoutLandingPage)
|
||||
apphook_pool.register(NamespacedApp)
|
||||
apphook_pool.register(ParentApp)
|
||||
apphook_pool.register(VariableUrlsApp)
|
||||
7
cms/test_utils/project/sampleapp/cms_config.py
Normal file
7
cms/test_utils/project/sampleapp/cms_config.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
from cms.app_base import CMSAppConfig
|
||||
from cms.test_utils.project.sampleapp.cms_wizards import sample_wizard
|
||||
|
||||
|
||||
class SampleAppConfig(CMSAppConfig):
|
||||
cms_enabled = True
|
||||
cms_wizards = [sample_wizard]
|
||||
82
cms/test_utils/project/sampleapp/cms_menus.py
Normal file
82
cms/test_utils/project/sampleapp/cms_menus.py
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
from django.urls import NoReverseMatch, reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from cms.menu_bases import CMSAttachMenu
|
||||
from cms.test_utils.project.sampleapp.models import Category
|
||||
from menus.base import Menu, NavigationNode
|
||||
from menus.menu_pool import menu_pool
|
||||
|
||||
|
||||
class SampleAppMenu(Menu):
|
||||
|
||||
def get_nodes(self, request):
|
||||
nodes = []
|
||||
for cat in Category.objects.all():
|
||||
n = NavigationNode(cat.name, cat.get_absolute_url(), cat.pk, cat.parent_id, "sampleapp")
|
||||
nodes.append(n)
|
||||
try:
|
||||
n = NavigationNode(_('sample root page'), reverse('sample-root'), 1)
|
||||
n2 = NavigationNode(_('sample settings page'), reverse('sample-settings'), 2)
|
||||
n3 = NavigationNode(_('sample account page'), reverse('sample-account'), 3)
|
||||
n4 = NavigationNode(_('sample my profile page'), reverse('sample-profile'), 4, 3)
|
||||
nodes.append(n)
|
||||
nodes.append(n2)
|
||||
nodes.append(n3)
|
||||
nodes.append(n4)
|
||||
except NoReverseMatch:
|
||||
pass
|
||||
return nodes
|
||||
|
||||
|
||||
menu_pool.register_menu(SampleAppMenu)
|
||||
|
||||
|
||||
class StaticMenu(CMSAttachMenu):
|
||||
name = _("Static Menu")
|
||||
|
||||
def get_nodes(self, request):
|
||||
nodes = []
|
||||
n = NavigationNode('static root page', "/fresh/", 1)
|
||||
n2 = NavigationNode('static settings page', "/bye/", 2)
|
||||
n3 = NavigationNode('static account page', "/hello/", 3)
|
||||
n4 = NavigationNode('static my profile page', "/hello/world/", 4, 3)
|
||||
nodes.append(n)
|
||||
nodes.append(n2)
|
||||
nodes.append(n3)
|
||||
nodes.append(n4)
|
||||
return nodes
|
||||
|
||||
|
||||
menu_pool.register_menu(StaticMenu)
|
||||
|
||||
|
||||
class StaticMenu2(StaticMenu):
|
||||
name = _("Static Menu2")
|
||||
|
||||
|
||||
menu_pool.register_menu(StaticMenu2)
|
||||
|
||||
|
||||
class StaticMenu3(StaticMenu):
|
||||
name = _("Static Menu3")
|
||||
|
||||
|
||||
menu_pool.register_menu(StaticMenu3)
|
||||
|
||||
|
||||
class StaticMenu4(CMSAttachMenu):
|
||||
name = _("Static Menu4")
|
||||
|
||||
def get_nodes(self, request):
|
||||
nodes = list()
|
||||
nodes.append(NavigationNode('static fresh', '/static/fresh/', 'static fresh'))
|
||||
try:
|
||||
# 'sample2-root' only resolves while the sample2 apphook is attached;
|
||||
# skip it gracefully otherwise instead of letting menu_pool log it.
|
||||
nodes.append(NavigationNode('sample2-root', reverse('sample2-root'), 'sample2-root'))
|
||||
except NoReverseMatch:
|
||||
pass
|
||||
return nodes
|
||||
|
||||
|
||||
menu_pool.register_menu(StaticMenu4)
|
||||
32
cms/test_utils/project/sampleapp/cms_toolbars.py
Normal file
32
cms/test_utils/project/sampleapp/cms_toolbars.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from cms.cms_toolbars import ADMIN_MENU_IDENTIFIER, ADMINISTRATION_BREAK
|
||||
from cms.toolbar.items import Break
|
||||
from cms.toolbar_base import CMSToolbar
|
||||
from cms.toolbar_pool import toolbar_pool
|
||||
from cms.utils.urlutils import admin_reverse
|
||||
|
||||
SAMPLEAPP_BREAK = 'Sample App Break'
|
||||
|
||||
|
||||
@toolbar_pool.register
|
||||
class CategoryToolbar(CMSToolbar):
|
||||
def populate(self):
|
||||
admin_menu = self.toolbar.get_or_create_menu(ADMIN_MENU_IDENTIFIER)
|
||||
position = admin_menu.find_first(Break, identifier=ADMINISTRATION_BREAK)
|
||||
if position:
|
||||
position -= 1
|
||||
else:
|
||||
position = 0
|
||||
category_menu = admin_menu.get_or_create_menu('category', _('Category'), position=position)
|
||||
category_menu.add_sideframe_item(_('Categories'), url=admin_reverse('sampleapp_category_changelist'))
|
||||
category_menu.add_modal_item(_('Add Category'), url=admin_reverse('sampleapp_category_add'))
|
||||
|
||||
|
||||
class ToolbarWithMedia(CMSToolbar):
|
||||
|
||||
class Media:
|
||||
js = ('samplemap/js/sampleapp.js',)
|
||||
css = {
|
||||
'all': ('samplemap/css/sampleapp.css',)
|
||||
}
|
||||
14
cms/test_utils/project/sampleapp/cms_wizards.py
Normal file
14
cms/test_utils/project/sampleapp/cms_wizards.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
from cms.test_utils.project.sampleapp.forms import SampleWizardForm
|
||||
from cms.wizards.wizard_base import Wizard
|
||||
|
||||
|
||||
class SampleWizard(Wizard):
|
||||
pass
|
||||
|
||||
|
||||
sample_wizard = SampleWizard(
|
||||
title="Sample",
|
||||
weight=105,
|
||||
form=SampleWizardForm,
|
||||
description="Create a new Sample",
|
||||
)
|
||||
24
cms/test_utils/project/sampleapp/forms.py
Normal file
24
cms/test_utils/project/sampleapp/forms.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
from django import forms
|
||||
from django.contrib.auth.forms import AuthenticationForm
|
||||
|
||||
from cms.test_utils.project.sampleapp.models import Category
|
||||
|
||||
|
||||
class LoginForm(AuthenticationForm):
|
||||
pass
|
||||
|
||||
|
||||
class LoginForm2(AuthenticationForm):
|
||||
pass
|
||||
|
||||
|
||||
class LoginForm3(AuthenticationForm):
|
||||
def __init__(self, request=None, *args, **kwargs):
|
||||
super().__init__(request, *args, **kwargs)
|
||||
|
||||
|
||||
class SampleWizardForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = Category
|
||||
exclude = []
|
||||
135
cms/test_utils/project/sampleapp/models.py
Normal file
135
cms/test_utils/project/sampleapp/models.py
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
from functools import cached_property
|
||||
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
|
||||
from cms.models.fields import PlaceholderRelationField
|
||||
from cms.utils.mptree import get_tree_base
|
||||
from cms.utils.placeholder import get_placeholder_from_slot
|
||||
|
||||
MP_Node = get_tree_base()
|
||||
|
||||
|
||||
class Category(MP_Node):
|
||||
parent = models.ForeignKey("self", blank=True, null=True, on_delete=models.CASCADE)
|
||||
name = models.CharField(max_length=20)
|
||||
placeholders = PlaceholderRelationField()
|
||||
|
||||
@cached_property
|
||||
def description(self):
|
||||
return get_placeholder_from_slot(self.placeholders, "description", default_width=600)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("category_view", args=[self.pk])
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "categories"
|
||||
|
||||
|
||||
class Picture(models.Model):
|
||||
image = models.ImageField(upload_to="pictures")
|
||||
category = models.ForeignKey(Category, on_delete=models.CASCADE)
|
||||
|
||||
|
||||
class SampleAppConfig(models.Model):
|
||||
namespace = models.CharField(
|
||||
default=None,
|
||||
max_length=100,
|
||||
unique=True,
|
||||
)
|
||||
|
||||
|
||||
class SomeEditableModel(models.Model):
|
||||
def get_absolute_url(self):
|
||||
return reverse("some_editable_model_view", args=[self.pk])
|
||||
|
||||
|
||||
|
||||
class GrouperModel(models.Model):
|
||||
category_name = models.CharField(max_length=200, default="")
|
||||
some_field = models.CharField(max_length=200, default="")
|
||||
|
||||
|
||||
class GrouperModelContent(models.Model):
|
||||
# grouper field name: snake case of GrouperModel
|
||||
grouper_model = models.ForeignKey(
|
||||
GrouperModel,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
|
||||
language = models.TextField(
|
||||
default="en",
|
||||
choices=(
|
||||
("en", "English"),
|
||||
("de", "German"),
|
||||
("it", "Italian"),
|
||||
),
|
||||
)
|
||||
|
||||
region = models.TextField(
|
||||
default="world",
|
||||
max_length=10,
|
||||
choices=(
|
||||
("world", "World"),
|
||||
("americas", "Americas"),
|
||||
("europe", "Europe"),
|
||||
("africa", "Africa"),
|
||||
("asia", "Asia"),
|
||||
("australia", "Australia"),
|
||||
),
|
||||
)
|
||||
|
||||
uptodate = models.BooleanField(
|
||||
verbose_name="Yes/No",
|
||||
default=False,
|
||||
)
|
||||
|
||||
secret_greeting = models.TextField(
|
||||
max_length=100,
|
||||
)
|
||||
|
||||
|
||||
class SimpleGrouperModel(models.Model):
|
||||
category_name = models.CharField(max_length=200, default="")
|
||||
|
||||
|
||||
class SimpleGrouperModelContent(models.Model):
|
||||
# grouper field name: snake case of GrouperModel
|
||||
simple_grouper_model = models.ForeignKey(
|
||||
SimpleGrouperModel,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
|
||||
language = models.TextField(
|
||||
default="en",
|
||||
choices=(
|
||||
("en", "English"),
|
||||
("de", "German"),
|
||||
("it", "Italian"),
|
||||
),
|
||||
)
|
||||
|
||||
region = models.TextField(
|
||||
default="world",
|
||||
max_length=10,
|
||||
choices=(
|
||||
("world", "World"),
|
||||
("americas", "Americas"),
|
||||
("europe", "Europe"),
|
||||
("africa", "Africa"),
|
||||
("asia", "Asia"),
|
||||
("australia", "Australia"),
|
||||
),
|
||||
)
|
||||
|
||||
uptodate = models.BooleanField(
|
||||
verbose_name="Yes/No",
|
||||
default=False,
|
||||
)
|
||||
|
||||
secret_greeting = models.TextField(
|
||||
max_length=100,
|
||||
)
|
||||
9
cms/test_utils/project/sampleapp/ns_urls.py
Normal file
9
cms/test_utils/project/sampleapp/ns_urls.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
from django.urls import re_path
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r'^current-app/$', views.current_app, name='current-app'),
|
||||
re_path(_('page'), views.current_app, name='translated-url'),
|
||||
]
|
||||
0
cms/test_utils/project/sampleapp/static/css/style.css
Normal file
0
cms/test_utils/project/sampleapp/static/css/style.css
Normal file
BIN
cms/test_utils/project/sampleapp/static/sampleapp/img/gift.jpg
Normal file
BIN
cms/test_utils/project/sampleapp/static/sampleapp/img/gift.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.4 KiB |
|
|
@ -0,0 +1,12 @@
|
|||
{% load cms_tags menu_tags %}
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head lang="en">
|
||||
<meta charset="UTF-8">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{% page_language_url 'fr' %}</h1>
|
||||
{{form}}
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
{{ app }}
|
||||
{% url 'namespaced_app_ns:current-app' %}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{{ category.get_title }}</h1>
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
{% extends "base.html" %}
|
||||
{% load cms_tags %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Sample application page - on page {% page_attribute page_title %}</h2>
|
||||
<h3>{{ message }}</h3>
|
||||
<h4>{{ opts }}</h4>
|
||||
{{ block.super }}
|
||||
{% if app %}{% url 'namespaced_app_ns:extra_first' %}{% else %}{% url 'extra_first' %}{% endif %}
|
||||
{% if app %}{% url 'namespaced_app_ns:extra_second' %}{% else %}{% url 'extra_second' %}{% endif %}
|
||||
{% endblock content %}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
{% extends "base.html" %}
|
||||
{% load cms_tags i18n %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Sample application home page - on page {% page_attribute page_title %}</h2>
|
||||
<h3>{{ message }}</h3>
|
||||
{% if my_params %}<p>my_params: {{ my_params }}</p>{% endif %}
|
||||
{{ block.super }}
|
||||
<ul>
|
||||
<li>
|
||||
<a href="{% if app %}{% url 'namespaced_app_ns:sample-root' %}{% else %}{% url 'sample-root' %}{% endif %}">Sample app root reverse test</a>
|
||||
</li>
|
||||
<li>
|
||||
{% language 'de' %}
|
||||
<a href="{% if app %}{% url 'namespaced_app_ns:sample-account' %}{% else %}{% url 'sample-account' %}{% endif %}">Sample app account reverse test german</a>
|
||||
{% endlanguage %}
|
||||
</li>
|
||||
<li>
|
||||
{% language 'en' %}
|
||||
<a href="{% if app %}{% url 'namespaced_app_ns:sample-account' %}{% else %}{% url 'sample-account' %}{% endif %}">Sample app account reverse test english</a>
|
||||
{% endlanguage %}
|
||||
</li>
|
||||
</ul>
|
||||
<h4>Sample image - appmedia works?</h4>
|
||||
<img src="{{ STATIC_URL }}sampleapp/img/gift.jpg" alt="gift">
|
||||
{% placeholder "test" or %}<--noplaceholder-->{% endplaceholder %}
|
||||
{% endblock content %}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
{{ content }}
|
||||
{% endblock %}
|
||||
22
cms/test_utils/project/sampleapp/urls.py
Normal file
22
cms/test_utils/project/sampleapp/urls.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
from django.urls import include, re_path
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from . import views
|
||||
|
||||
"""
|
||||
Also used in cms.tests.ApphooksTestCase
|
||||
"""
|
||||
urlpatterns = [
|
||||
re_path(r'^$', views.sample_view, {'message': 'sample root page', }, name='sample-root'),
|
||||
re_path(r'^exempt/$', views.exempt_view, {'message': 'sample root page', }, name='sample-exempt'),
|
||||
re_path(r'^settings/$', views.sample_view, kwargs={'message': 'sample settings page'}, name='sample-settings'),
|
||||
re_path(r'^myparams/(?P<my_params>[\w_-]+)/$', views.sample_view, name='sample-params'),
|
||||
re_path(_(r'^account/$'), views.sample_view, {'message': 'sample account page'}, name='sample-account'),
|
||||
re_path(r'^account/my_profile/$', views.sample_view, {'message': 'sample my profile page'}, name='sample-profile'),
|
||||
re_path(r'^category/(?P<id>[0-9]+)/$', views.category_view, name='category_view'),
|
||||
re_path(r'^notfound/$', views.notfound, name='notfound'),
|
||||
re_path(r'^extra_1/$', views.extra_view, {'message': 'test urlconf'}, name='extra_first'),
|
||||
re_path(r'^class-view/$', views.ClassView(), name='sample-class-view'),
|
||||
re_path(r'^class-based-view/$', views.ClassBasedView.as_view(), name='sample-class-based-view'),
|
||||
re_path(r'^', include('cms.test_utils.project.sampleapp.urls_extra'), {'opts': 'someopts'}),
|
||||
]
|
||||
7
cms/test_utils/project/sampleapp/urls2.py
Normal file
7
cms/test_utils/project/sampleapp/urls2.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
from django.urls import re_path
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r'^$', views.sample_view, {'message': 'sample apphook2 root page', }, name='sample2-root'),
|
||||
]
|
||||
7
cms/test_utils/project/sampleapp/urls_childapp.py
Normal file
7
cms/test_utils/project/sampleapp/urls_childapp.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
from django.urls import re_path
|
||||
|
||||
from cms.test_utils.project.sampleapp import views
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r'^(?P<path>.+)$', views.childapp_view, name='childapp_view'),
|
||||
]
|
||||
9
cms/test_utils/project/sampleapp/urls_example.py
Normal file
9
cms/test_utils/project/sampleapp/urls_example.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
from django.urls import re_path
|
||||
|
||||
from ..placeholderapp import views
|
||||
|
||||
app_name = 'example_app'
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r'^example/$', views.example_view, name="example"),
|
||||
]
|
||||
6
cms/test_utils/project/sampleapp/urls_excluded.py
Normal file
6
cms/test_utils/project/sampleapp/urls_excluded.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from django.urls import include, re_path
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r'^excluded/', include('cms.test_utils.project.sampleapp.urls_example', namespace="excluded")),
|
||||
re_path(r'^not_excluded/', include('cms.test_utils.project.sampleapp.urls_example', namespace="not_excluded")),
|
||||
]
|
||||
7
cms/test_utils/project/sampleapp/urls_extra.py
Normal file
7
cms/test_utils/project/sampleapp/urls_extra.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
from django.urls import re_path
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r'extra_2/$', views.extra_view, {'message': 'test included urlconf'}, name='extra_second'),
|
||||
]
|
||||
7
cms/test_utils/project/sampleapp/urls_parentapp.py
Normal file
7
cms/test_utils/project/sampleapp/urls_parentapp.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
from django.urls import re_path
|
||||
|
||||
from cms.test_utils.project.sampleapp import views
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r'^(?P<path>.+)$', views.parentapp_view, name='parentapp_view'),
|
||||
]
|
||||
7
cms/test_utils/project/sampleapp/urls_sample_config.py
Normal file
7
cms/test_utils/project/sampleapp/urls_sample_config.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
from django.urls import re_path
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r'^$', views.sample_view, {'message': 'sample root page', }, name='sample-config-root'),
|
||||
]
|
||||
78
cms/test_utils/project/sampleapp/views.py
Normal file
78
cms/test_utils/project/sampleapp/views.py
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
# Create your views here.
|
||||
from django.http import Http404
|
||||
from django.shortcuts import render
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.generic.base import TemplateView
|
||||
|
||||
from cms.test_utils.project.sampleapp.models import Category
|
||||
from cms.utils.urlutils import admin_reverse
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def exempt_view(request, **kw):
|
||||
context = kw
|
||||
request.current_app = request.resolver_match.namespace
|
||||
context['app'] = request.current_app
|
||||
return render(request, "sampleapp/home.html", context)
|
||||
|
||||
|
||||
def sample_view(request, **kw):
|
||||
context = kw
|
||||
request.current_app = request.resolver_match.namespace
|
||||
context['app'] = request.current_app
|
||||
return render(request, "sampleapp/home.html", context)
|
||||
|
||||
|
||||
def category_view(request, id):
|
||||
cat = Category.objects.get(pk=id)
|
||||
if request.user.is_staff:
|
||||
category_menu = request.toolbar.get_or_create_menu('category', _('Category'))
|
||||
change_url = admin_reverse('sampleapp_category_change', args=(cat.pk,))
|
||||
category_menu.add_modal_item(_("Change Category"), url=change_url)
|
||||
return render(request, 'sampleapp/category_view.html', {'category': cat})
|
||||
|
||||
|
||||
def extra_view(request, **kw):
|
||||
context = kw
|
||||
request.current_app = request.resolver_match.namespace
|
||||
context['app'] = request.current_app
|
||||
return render(request, "sampleapp/extra.html", context)
|
||||
|
||||
|
||||
def current_app(request):
|
||||
context = {}
|
||||
request.current_app = request.resolver_match.namespace
|
||||
context['app'] = request.current_app
|
||||
return render(request, "sampleapp/app.html", context)
|
||||
|
||||
|
||||
def plain_view(request):
|
||||
context = {'content': 'plain text'}
|
||||
request.current_app = request.resolver_match.namespace
|
||||
context['app'] = request.current_app
|
||||
return render(request, "sampleapp/plain.html", context)
|
||||
|
||||
|
||||
def notfound(request):
|
||||
raise Http404
|
||||
|
||||
|
||||
class ClassView:
|
||||
def __call__(self, request, *args, **kwargs):
|
||||
context = {'content': 'plain text'}
|
||||
return render(request, "sampleapp/plain.html", context)
|
||||
|
||||
|
||||
class ClassBasedView(TemplateView):
|
||||
template_name = 'sampleapp/plain.html'
|
||||
|
||||
|
||||
def parentapp_view(request, path):
|
||||
context = {'content': 'parent app content'}
|
||||
return render(request, "sampleapp/plain.html", context)
|
||||
|
||||
|
||||
def childapp_view(request, path):
|
||||
context = {'content': 'child app content'}
|
||||
return render(request, "sampleapp/plain.html", context)
|
||||
Loading…
Add table
Add a link
Reference in a new issue