clone cms with menus, make menus standalone app

This commit is contained in:
bruks 2026-09-30 15:27:04 +01:00
commit afb096b7a3
1153 changed files with 318897 additions and 37 deletions

View file

@ -0,0 +1,10 @@
[run]
branch = True
source =
cms
menus
publisher
omit =
../*migrations*
[report]
precision = 2

View file

View file

View file

@ -0,0 +1,13 @@
from cms.api import add_plugin
from cms.test_utils.project.fakemlng.models import MainModel, Translations
class FakemlngFixtures:
def create_fixtures(self):
main = MainModel.objects.create()
en = Translations.objects.create(master=main, language_code='en')
Translations.objects.create(master=main, language_code='de')
Translations.objects.create(master=main, language_code='nl')
fr = Translations.objects.create(master=main, language_code='fr')
add_plugin(en.placeholder, 'TextPlugin', 'en', body='<p>ENGLISH</p>')
add_plugin(fr.placeholder, 'TextPlugin', 'fr', body='<p>FRENCH</p>')

View file

@ -0,0 +1,132 @@
from cms.api import create_page
class MenusFixture:
def create_fixtures(self):
"""
Tree from fixture:
+ P1
| + P2
| + P3
+ P4
| + P5
+ P6 (not in menu)
+ P7
+ P8
"""
defaults = {
'template': 'nav_playground.html',
'language': 'en',
}
with self.settings(CMS_PERMISSION=False):
p1 = create_page('P1', in_navigation=True, **defaults)
p1.set_as_homepage()
p4 = create_page('P4', in_navigation=True, **defaults)
p6 = create_page('P6', in_navigation=False, **defaults)
p2 = create_page('P2', in_navigation=True, parent=p1, **defaults)
create_page('P3', in_navigation=True, parent=p2, **defaults)
create_page('P5', in_navigation=True, parent=p4, **defaults)
create_page('P7', in_navigation=True, parent=p6, **defaults)
create_page('P8', in_navigation=True, parent=p6, **defaults)
class ExtendedMenusFixture:
def create_fixtures(self):
"""
Tree from fixture:
+ P1
| + P2
| + P3
| + P9
| + P10
| + P11
+ P4
| + P5
+ P6 (not in menu)
+ P7
+ P8
"""
defaults = {
'template': 'nav_playground.html',
'language': 'en',
}
with self.settings(CMS_MODERATOR=False, CMS_PERMISSION=False):
p1 = create_page('P1', in_navigation=True, **defaults)
p1.set_as_homepage()
p4 = create_page('P4', in_navigation=True, **defaults)
p6 = create_page('P6', in_navigation=False, **defaults)
p2 = create_page('P2', in_navigation=True, parent=p1, **defaults)
create_page('P3', in_navigation=True, parent=p2, **defaults)
create_page('P5', in_navigation=True, parent=p4, **defaults)
create_page('P7', in_navigation=True, parent=p6, **defaults)
create_page('P8', in_navigation=True, parent=p6, **defaults)
p9 = create_page('P9', in_navigation=True, parent=p1, **defaults)
p10 = create_page('P10', in_navigation=True, parent=p9, **defaults)
create_page('P11', in_navigation=True, parent=p10, **defaults)
class SubMenusFixture:
def create_fixtures(self):
"""
Tree from fixture:
+ P1
| + P2
| + P3
+ P4
| + P5
+ P6
+ P7 (not in menu)
+ P8
"""
defaults = {
'template': 'nav_playground.html',
'language': 'en',
}
with self.settings(CMS_PERMISSION=False):
p1 = create_page('P1', in_navigation=True, **defaults)
p1.set_as_homepage()
p4 = create_page('P4', in_navigation=True, **defaults)
p6 = create_page('P6', in_navigation=True, **defaults)
p2 = create_page('P2', in_navigation=True, parent=p1, **defaults)
create_page('P3', in_navigation=True, parent=p2, **defaults)
create_page('P5', in_navigation=True, parent=p4, **defaults)
create_page('P7', in_navigation=False, parent=p6, **defaults)
create_page('P8', in_navigation=True, parent=p6, **defaults)
class SoftrootFixture:
def create_fixtures(self):
"""
top
root
aaa
111
ccc
ddd
222
bbb
333
444
# all in nav, published and NOT softroot
"""
defaults = {
'template': 'nav_playground.html',
'language': 'en',
'in_navigation': True,
}
with self.settings(CMS_PERMISSION=False):
top = create_page('top', **defaults)
top.set_as_homepage()
root = create_page('root', parent=top, **defaults)
aaa = create_page('aaa', parent=root, **defaults)
_111 = create_page('111', parent=aaa, **defaults)
ccc = create_page('ccc', parent=_111, **defaults)
create_page('ddd', parent=ccc, **defaults)
create_page('222', parent=aaa, **defaults)
bbb = create_page('bbb', parent=root, **defaults)
create_page('333', parent=bbb, **defaults)
create_page('444', parent=bbb, **defaults)

View file

@ -0,0 +1,28 @@
from cms.api import create_page
from cms.models.pagemodel import Page
class NavextendersFixture:
def create_fixtures(self):
"""
Tree from fixture:
page1
page2
page3
page4
page5
"""
defaults = {
'template': 'nav_playground.html',
'language': 'en',
}
with self.settings(CMS_PERMISSION=False):
p1 = create_page('page1', in_navigation=True, **defaults)
p1.set_as_homepage()
p4 = create_page('page4', in_navigation=True, **defaults)
p1 = Page.objects.get(pk=p1.pk)
p2 = create_page('page2', in_navigation=True, parent=p1, **defaults)
create_page('page3', in_navigation=True, parent=p2, **defaults)
p4 = Page.objects.get(pk=p4.pk)
create_page('page5', in_navigation=True, parent=p4, **defaults)

View file

@ -0,0 +1,14 @@
from cms.api import create_page, create_page_content
class TwoPagesFixture:
def create_fixtures(self):
defaults = {
'template': 'nav_playground.html',
'in_navigation': True,
}
with self.settings(CMS_PERMISSION=False):
first = create_page('first', language='en', **defaults)
create_page_content('de', 'erste', first)
second = create_page('second', language='en', reverse_id='myreverseid', **defaults)
create_page_content('de', 'zweite', second)

12
cms/test_utils/mail.py Normal file
View file

@ -0,0 +1,12 @@
from django.core import mail
MAILERS_SUPPORTED = hasattr(mail, "mailers")
LOCMEM_BACKEND = "django.core.mail.backends.locmem.EmailBackend"
def get_email_settings():
"""Configure in-memory email using the running Django's settings API."""
if MAILERS_SUPPORTED:
return {"MAILERS": {"default": {"BACKEND": LOCMEM_BACKEND}}}
return {"EMAIL_BACKEND": LOCMEM_BACKEND}

View file

View file

@ -0,0 +1 @@
{% load placeholder_tags %}

View file

@ -0,0 +1 @@
default_app_config = 'cms.test_utils.project.app_using_non_feature.apps.NonFeatureCMSConfig'

View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class NonFeatureCMSConfig(AppConfig):
name = 'cms.test_utils.project.app_using_non_feature'
label = 'app_using_non_feature'

View file

@ -0,0 +1,7 @@
from cms.app_base import CMSAppConfig
class NonFeatureCMSConfig(CMSAppConfig):
# Attempting to use features from a cms app that doesn't define a
# configure_app method
app_with_feature_not_implemented_enabled = True

View file

@ -0,0 +1 @@
default_app_config = 'cms.test_utils.project.app_with_bad_cms_file.apps.BadCMSFileConfig'

View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class BadCMSFileConfig(AppConfig):
name = 'cms.test_utils.project.app_with_bad_cms_file'
label = 'bad_cms_file'

View file

@ -0,0 +1,3 @@
# Use this app to test what happens when exceptions are raised in this
# file. RuntimeError is just an example exception
raise RuntimeError

View file

@ -0,0 +1 @@
default_app_config = 'cms.test_utils.project.app_with_cms_config.apps.CMSConfigConfig'

View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class CMSConfigConfig(AppConfig):
name = 'cms.test_utils.project.app_with_cms_config'
label = 'app_with_cms_config'

View file

@ -0,0 +1,5 @@
from cms.app_base import CMSAppConfig
class CMSConfigConfig(CMSAppConfig):
app_with_cms_feature_enabled = True

View file

@ -0,0 +1 @@
default_app_config = 'cms.test_utils.project.app_with_cms_feature.apps.CMSFeatureConfig'

View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class CMSFeatureConfig(AppConfig):
name = 'cms.test_utils.project.app_with_cms_feature'
label = 'app_with_cms_feature'

View file

@ -0,0 +1,12 @@
from cms.app_base import CMSAppExtension
class CMSSomeFeatureConfig(CMSAppExtension):
def __init__(self, *args, **kwargs):
self.num_configured_apps = 0
self.configured_apps = []
def configure_app(self, cms_config):
self.num_configured_apps += 1
self.configured_apps.append(cms_config.app_config.label)

View file

@ -0,0 +1 @@
default_app_config = 'cms.test_utils.project.app_with_cms_feature_and_config.apps.CMSFeatureAndConfigConfig'

View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class CMSFeatureAndConfigConfig(AppConfig):
name = 'cms.test_utils.project.app_with_cms_feature_and_config'
label = 'app_with_cms_feature_and_config'

View file

@ -0,0 +1,11 @@
from cms.app_base import CMSAppConfig, CMSAppExtension
class CMSConfig(CMSAppConfig):
app_with_cms_feature_enabled = False
class CMSExtension(CMSAppExtension):
def configure_app(self, cms_config):
pass

View file

@ -0,0 +1 @@
default_app_config = 'cms.test_utils.project.app_with_feature_not_implemented.apps.CMSFeatureConfig'

View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class CMSFeatureConfig(AppConfig):
name = 'cms.test_utils.project.app_with_feature_not_implemented'
label = 'app_with_feature_not_implemented'

View file

@ -0,0 +1,5 @@
from cms.app_base import CMSAppExtension
class CMSSomeFeatureConfig(CMSAppExtension):
pass

View file

@ -0,0 +1 @@
default_app_config = 'cms.test_utils.project.app_with_two_cms_config_classes.apps.TwoCMSAppClassesConfig'

View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class TwoCMSAppClassesConfig(AppConfig):
name = 'cms.test_utils.project.app_with_two_cms_config_classes'
label = 'app_with_two_cms_config_classes'

View file

@ -0,0 +1,13 @@
from cms.app_base import CMSAppConfig, CMSAppExtension
class CMSConfigConfig(CMSAppConfig):
pass
class CMSConfigConfig2(CMSAppConfig):
pass
class CMSExtension(CMSAppExtension):
pass

View file

@ -0,0 +1 @@
default_app_config = 'cms.test_utils.project.app_with_two_cms_feature_classes.apps.TwoCMSAppClassesConfig'

View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class TwoCMSAppClassesConfig(AppConfig):
name = 'cms.test_utils.project.app_with_two_cms_feature_classes'
label = 'app_with_two_cms_feature_classes'

View file

@ -0,0 +1,13 @@
from cms.app_base import CMSAppConfig, CMSAppExtension
class CMSFeatureConfig(CMSAppExtension):
pass
class CMSFeatureConfig2(CMSAppExtension):
pass
class CMSConfig(CMSAppConfig):
pass

View file

@ -0,0 +1 @@
default_app_config = 'cms.test_utils.project.app_without_cms_app_class.apps.WithoutCMSAppClassConfig'

View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class WithoutCMSAppClassConfig(AppConfig):
name = 'cms.test_utils.project.app_without_cms_app_class'
label = 'app_without_cms_app_class'

View file

@ -0,0 +1 @@
default_app_config = 'cms.test_utils.project.app_without_cms_file.apps.WithoutCMSFileConfig'

View file

@ -0,0 +1,6 @@
from django.apps import AppConfig
class WithoutCMSFileConfig(AppConfig):
name = 'cms.test_utils.project.app_without_cms_file'
label = 'app_without_cms_file'

View file

@ -0,0 +1,7 @@
from cms.test_utils.project.backwards_wizards.wizards import wizard
from cms.wizards.wizard_pool import wizard_pool
# NOTE: We keep this line separate from the actual wizard definition
# because if both are in the same file then importing the wizard causes
# this line to run, which makes it impossible to test properly
wizard_pool.register(wizard)

View 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
wizard = SampleWizard(
title="Sample",
weight=505,
form=SampleWizardForm,
description="Create something",
)

View file

@ -0,0 +1 @@
import nonexistingmodule # noqa: F401

View file

@ -0,0 +1,17 @@
from cms.models import CMSPlugin
class TestPlugin1(CMSPlugin):
pass
class LeftMixin:
pass
class RightMixin:
pass
class TestPlugin2(LeftMixin, CMSPlugin, RightMixin):
pass

View file

@ -0,0 +1,23 @@
from django.conf import settings
from django.urls import re_path
from cms.apphook_pool import apphook_pool
from cms.views import details
if settings.APPEND_SLASH:
reg = re_path(r'^(?P<slug>[0-9A-Za-z-_.//]+)/$', details, name='pages-details-by-slug')
else:
reg = re_path(r'^(?P<slug>[0-9A-Za-z-_.//]+)$', details, name='pages-details-by-slug')
urlpatterns = [
# Public pages
re_path(r'^$', details, {'slug': ''}, name='pages-root'),
reg,
]
if apphook_pool.get_apphooks():
"""If there are some application urls, add special resolver, so we will
have standard reverse support.
"""
from cms.appresolver import get_app_patterns
urlpatterns = get_app_patterns() + urlpatterns

View file

@ -0,0 +1,6 @@
from django.utils.translation import gettext_lazy as _
TEMPLATES = {
'wrong_col_two.html': _('Two columns'),
'wrong_col_three.html': _('Three columns'),
}

View file

@ -0,0 +1,82 @@
{% load i18n cms_tags menu_tags sekizai_tags %}
<!doctype html><html lang="{{ LANGUAGE_CODE }}">
<head>
<meta charset="utf-8" />
<title>{% page_attribute page_title %}</title>
<meta name="description" content="{% page_attribute meta_description %}" />
<link href="{{ STATIC_URL }}css/style.css" media="all" rel="stylesheet" type="text/css" />
{% render_block "css" %}
<style type="text/css">
body { font:normal 16px/18px "Times New Roman", Times, serif; margin:0; background:#fcfcfc; }
#header { padding:15px 10px 15px; box-shadow:#eee 0px 2px 5px; background:#fff;
clear:both; overflow:hidden; }
#header #logo { float:left; background:#eee; border-radius:10px; }
#header #logo a { color:#999; display:block; text-align:center; padding:10px 25px; text-decoration:none; }
#header #nav_lang,
#header #nav_main { float:left; padding-left:15px; }
#header #nav_lang ul,
#header #nav_main ul { list-style-type:none; padding:0; margin:0; }
#header #nav_lang ul li,
#header #nav_main ul li { float:left; padding:0; margin:0; }
#header #nav_lang ul li a,
#header #nav_main ul li a { float:left; padding:10px 5px; }
#main, .breadcrumb { width:960px; margin:0 auto; }
.breadcrumb { padding:15px 0; list-style-type:none; }
.breadcrumb li { padding-right:10px; }
.grid_1, .grid_2, .grid_3, .grid_4, .grid_5, .grid_6,
.grid_7, .grid_8, .grid_9, .grid_10, .grid_11, .grid_12 { float:left; margin:0 10px; }
.grid_1 { width:60px; }
.grid_2 { width:140px; }
.grid_3 { width:220px; }
.grid_4 { width:300px; }
.grid_5 { width:380px; }
.grid_6 { width:460px; }
.grid_7 { width:540px; }
.grid_8 { width:620px; }
.grid_9 { width:700px; }
.grid_10 { width:780px; }
.grid_11 { width:860px; }
.grid_12 { width:940px; }
p { padding:0; margin:0 0 15px; }
img { max-width:100%; }
</style>
</head>
<body id="{% block tpl_id %}none{% endblock %}" class="{{ LANGUAGE_CODE }}">
{% cms_toolbar %}
<div id="page" class="container_16 ">
<div id="header">
<div id="logo">
<a href="/">Company name</a>
</div>
<div id="nav_lang">
{% spaceless %}
<ul>
{% language_chooser %}
</ul>
{% endspaceless %}
</div>
<div id="nav_main" class="clearfix">
{% spaceless %}
<ul>
{% show_menu 0 0 100 100 %}
</ul>
{% endspaceless %}
</div>
</div>
<ul class="breadcrumb clearfix">
{% show_breadcrumb %}
</ul>
<div id="main">
{% block content %}{% endblock content %}
</div>
</div>
{% render_block "js" %}
</body>
</html>

View file

@ -0,0 +1,31 @@
{% extends "base.html" %}
{% load i18n cms_tags %}
{% block tpl_id %}tpl_col_three{% endblock %}
{% block content %}
<h1>{% render_model request.current_page "page_title" %}</h1>
<div id="col1" class="grid_3">
{% block col_sidebar %}
{% with "220" as width %}
{% placeholder col_sidebar %}
{% endwith %}
{% endblock %}
</div>
<div id="col2" class="grid_6">
{% block col_left %}
{% with "340" as width %}
{% placeholder col_left %}
{% endwith %}
{% endblock %}
</div>
<div id="col3" class="grid_3">
{% block col_right %}
{% with "220" as width %}
{% placeholder col_right %}
{% endwith %}
{% endblock %}
</div>
{% endblock %}

View file

@ -0,0 +1,28 @@
{% extends "base.html" %}
{% load i18n cms_tags %}
{% block tpl_id %}tpl_col_two{% endblock %}
{% block content %}
<h1>{% render_model request.current_page "titles" %} {% render_model_icon request.current_page %}</h1>
<div id="col1" class="grid_3">
{% render_model request.current_page "menu_title" %}
{% block col_sidebar %}
{% with "220" as width %}
{% placeholder col_sidebar %}
{% endwith %}
{% endblock %}
</div>
<div id="col2" class="grid_9">
{% render_model request.current_page "page_title" %}
{% block col_left %}
{% with "640" as width %}
{% placeholder col_left %}
{% endwith %}
{% endblock %}
</div>
<footer>{% render_model request.current_page "title" %}</footer>
{% endblock %}

View file

@ -0,0 +1,18 @@
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.contrib.auth.admin import UserAdmin as OriginalUserAdmin
from django.contrib.auth.models import User as OriginalUser
if getattr(OriginalUser._meta, 'swapped', False):
class UserAdmin(OriginalUserAdmin):
list_display = ('username', 'email', 'get_full_name', 'is_staff')
search_fields = ('username', 'email',)
fieldsets = (
(None, {'fields': ('username', 'password')}),
('Personal info', {'fields': ('email',)}),
('Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser',
'groups', 'user_permissions')}),
('Important dates', {'fields': ('last_login',)}),
)
admin.site.register(get_user_model(), UserAdmin)

View file

@ -0,0 +1,90 @@
import re
from urllib.parse import quote
from django.contrib.auth.models import (
AbstractBaseUser,
PermissionsMixin,
UserManager,
)
from django.core import validators
from django.core.mail import send_mail
from django.db import models
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
class CustomUserManager(UserManager):
def _create_user(self, username, email, password,
is_staff, is_superuser, **extra_fields):
"""
Creates and saves a User with the given username, email and password.
"""
now = timezone.now()
if not username:
raise ValueError('The given username must be set')
email = self.normalize_email(email)
user = self.model(username=username, email=email,
is_staff=is_staff, is_active=True,
is_superuser=is_superuser, last_login=now,
**extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
class User(AbstractBaseUser, PermissionsMixin):
"""
An abstract base class implementing a fully featured User model with
admin-compliant permissions.
Username, password and email are required. Other fields are optional.
"""
username = models.CharField(
_('username'), max_length=300, unique=True,
help_text=_('Required. 300 characters or fewer. Letters, numbers and '
'@/./+/-/_ characters'),
validators=[
validators.RegexValidator(re.compile('^[\\w.@+-]+$'), _('Enter a valid username.'), 'invalid')
]
)
email = models.EmailField(_('email address'), blank=True)
is_staff = models.BooleanField(
_('staff status'), default=False,
help_text=_('Designates whether the user can log into this admin '
'site.')
)
is_active = models.BooleanField(
_('active'), default=True,
help_text=_('Designates whether this user should be treated as '
'active. Unselect this instead of deleting accounts.')
)
my_new_field = models.IntegerField(null=True, blank=True, default=42)
objects = CustomUserManager()
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email']
class Meta:
verbose_name = _('user')
verbose_name_plural = _('users')
def get_absolute_url(self):
return "/users/%s/" % quote(self.username)
def get_full_name(self):
"""
Returns the first_name plus the last_name, with a space in between.
"""
return "A user called %s" % self.username
def get_short_name(self):
"Returns the short name for the user."
return self.username
def email_user(self, subject, message, from_email=None):
"""
Sends an email to this User.
"""
send_mail(subject, message, from_email, [self.email])

View file

@ -0,0 +1,41 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as OriginalUserAdmin
from .forms import UserChangeForm, UserCreationForm
from .models import EmailUser
class UserAdmin(OriginalUserAdmin):
# The form to add and change user instances
form = UserChangeForm
add_form = UserCreationForm
# Overrides the field lists from UserAdmin
list_display = ('email', 'first_name', 'last_name', 'is_staff')
list_filter = ('is_staff', 'is_superuser', 'is_active', 'groups')
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Personal Info', {'fields': ('first_name', 'last_name')}),
('Permissions', {'fields': (
'is_active', 'is_staff', 'is_superuser',
'groups', 'user_permissions')}),
('Important dates', {'fields': ('last_login', 'date_joined')}),
)
# UserAdmin overrides get_fieldsets to use this attribute
# so it must be populated
add_fieldsets = (
(
None, {
'fields': ('email', 'password1', 'password2')
}
),
)
search_fields = ('email', 'first_name', 'last_name',)
ordering = ('last_name', 'first_name', 'email')
# Now register the emailuser admin
admin.site.register(EmailUser, UserAdmin)

View file

@ -0,0 +1,113 @@
from django import forms
from django.contrib.auth import get_user_model
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from .models import EmailUser
class UserCreationForm(forms.ModelForm):
"""
A form for creating a new user, including the required
email and password fields.
"""
error_messages = {
'duplicate_email': "A user with that email already exists.",
'password_mismatch': "The two password fields didn't match.",
}
email = forms.EmailField(
label='Email',
help_text="Required. Standard format email address.",
)
password1 = forms.CharField(
label='Password',
widget=forms.PasswordInput
)
password2 = forms.CharField(
label='Password confirmation',
widget=forms.PasswordInput,
help_text="Enter the same password as above, for verification."
)
class Meta:
model = EmailUser
fields = ('email',)
def clean_email(self):
# Since User.username is unique, this check is redundant,
# but it sets a nicer error message than the ORM. See #13147.
email = self.cleaned_data["email"]
User = get_user_model()
try:
User._default_manager.get(email=email)
except User.DoesNotExist:
return email
raise forms.ValidationError(
self.error_messages['duplicate_email'],
code='duplicate_email',
)
def clean_password2(self):
# check that the two passwords match
password1 = self.cleaned_data.get("password1")
password2 = self.cleaned_data.get("password2")
if password1 and password2 and password1 != password2:
raise forms.ValidationError(
self.error_messages['password_mismatch'],
code='password_mismatch',
)
return password2
def save(self, commit=True):
# Save the provided password in hashed format
user = super().save(commit=False)
user.set_password(self.cleaned_data["password1"])
if commit:
user.save()
return user
class UserChangeForm(forms.ModelForm):
"""
A form for updating users, including all fields on the user,
but replaces the password field with admin's password hash display
field.
"""
email = forms.EmailField(
label='Email',
help_text="Required. Standard format email address.",
)
password = ReadOnlyPasswordHashField(
label="Password",
help_text="Raw passwords are not stored, so there is no way to see this user's password, "
"but you can change the password using <a href=\"password/\">this form</a>."
)
class Meta:
model = EmailUser
fields = (
'email', 'password', 'first_name', 'last_name', 'is_active',
'is_staff', 'is_superuser', 'groups', 'user_permissions', 'last_login',
'date_joined'
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
f = self.fields.get('user_permissions', None)
if f is not None:
f.queryset = f.queryset.select_related('content_type')
def clean_password(self):
"""
Regardless of what the user provides, return the initial value.
This is done here, rather than on the field, because the
field does not have access to the initial value.
"""
return self.initial["password"]

View file

@ -0,0 +1,126 @@
from urllib.parse import quote
from django.contrib.auth.models import (
AbstractBaseUser,
BaseUserManager,
PermissionsMixin,
)
from django.core.mail import send_mail
from django.db import models
from django.utils import timezone
class EmailUserManager(BaseUserManager):
def _create_user(self, email, password,
is_staff, is_superuser, **extra_fields):
"""
Creates and saves a User with the given email and password.
"""
now = timezone.now()
if not email:
raise ValueError('Users are required to have an email address.')
email = self.normalize_email(email)
user = self.model(
email=email,
is_staff=is_staff, is_active=True,
is_superuser=is_superuser, last_login=now,
date_joined=now, **extra_fields
)
user.set_password(password)
user.save(using=self._db)
return user
def create_user(self, username, email, password, **extra_fields):
return self._create_user(email, password, False, False,
**extra_fields)
def create_superuser(self, username, email, password, **extra_fields):
return self._create_user(email, password, True, True,
**extra_fields)
class AbstractEmailUser(AbstractBaseUser, PermissionsMixin):
"""
An abstract user model that is an alternative to the standard AbstractUser. The
sole difference is that AbstractEmailUser does not have a username field, and uses
the email field as the primary identifier by default.
Email and password are required. Other fields are optional.
"""
email = models.EmailField(
'email address',
max_length=300,
blank=True,
unique=True,
help_text="Required. Standard format email address."
)
first_name = models.CharField(
'first name',
max_length=30,
blank=True
)
last_name = models.CharField(
'last name',
max_length=30,
blank=True
)
is_staff = models.BooleanField(
'staff status',
default=False,
help_text='Designates whether the user can log into this admin site.'
)
is_active = models.BooleanField(
'active',
default=True,
help_text='Designates whether this user should be treated as active. '
'Unselect this instead of deleting accounts.'
)
date_joined = models.DateTimeField('date joined', default=timezone.now)
objects = EmailUserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
class Meta:
verbose_name = 'user'
verbose_name_plural = 'users'
abstract = True
def get_absolute_url(self):
return "/users/%s/" % quote(self.pk)
def get_full_name(self):
"""
Returns the first_name plus the last_name, with a space in between.
"""
full_name = f'{self.first_name} {self.last_name}'
return full_name.strip()
def get_short_name(self):
"Returns the short name for the user."
return self.first_name
def email_user(self, subject, message, from_email=None):
"""
Sends an email to this User.
"""
send_mail(subject, message, from_email, [self.email])
class EmailUser(AbstractEmailUser):
"""
Users within the Django authentication system are represented by this
model.
Email and password are required. Other fields are optional.
"""

View file

@ -0,0 +1,21 @@
from django.contrib import admin
from cms.extensions import PageContentExtensionAdmin, PageExtensionAdmin
from cms.test_utils.project.extensionapp.models import (
MyPageContentExtension,
MyPageExtension,
)
class MyPageExtensionAdmin(PageExtensionAdmin):
pass
admin.site.register(MyPageExtension, MyPageExtensionAdmin)
class MyPageContentExtensionAdmin(PageContentExtensionAdmin):
pass
admin.site.register(MyPageContentExtension, MyPageContentExtensionAdmin)

View file

@ -0,0 +1,75 @@
from django.urls import NoReverseMatch
from django.utils.translation import gettext_lazy as _
from cms.test_utils.project.extensionapp.models import (
MyPageContentExtension,
MyPageExtension,
)
from cms.toolbar_base import CMSToolbar
from cms.toolbar_pool import toolbar_pool
from cms.utils.page_permissions import user_can_change_page
from cms.utils.urlutils import admin_reverse
@toolbar_pool.register
class MyPageContentExtensionToolbar(CMSToolbar):
def populate(self):
# always use draft if we have a page
self.page = self.request.current_page
if not self.page:
# Nothing to do
return
if user_can_change_page(self.request.user, page=self.page):
try:
mypagecontentextension = MyPageContentExtension.objects.get(extended_object_id=self.page.id)
except MyPageContentExtension.DoesNotExist:
mypagecontentextension = None
try:
if mypagecontentextension:
url = admin_reverse(
'extensionapp_mypagecontentextension_change', args=(mypagecontentextension.pk,)
)
else:
url = admin_reverse(
'extensionapp_mypagecontentextension_add'
) + '?extended_object=%s' % self.page.pk
except NoReverseMatch:
# not in urls
pass
else:
not_edit_mode = not self.toolbar.edit_mode_active
current_page_menu = self.toolbar.get_or_create_menu('page')
current_page_menu.add_modal_item(_('Title Extension'), url=url, disabled=not_edit_mode)
@toolbar_pool.register
class MyPageExtensionToolbar(CMSToolbar):
supported_apps = ('cms.test_utils.project.extensionapp.cms_toolbar', 'cms.test_utils.project.placeholderapp')
def populate(self):
# always use draft if we have a page
self.page = self.request.current_page
if not self.page:
# Nothing to do
return
if user_can_change_page(self.request.user, page=self.page):
try:
mypageextension = MyPageExtension.objects.get(extended_object_id=self.page.id)
except MyPageExtension.DoesNotExist:
mypageextension = None
try:
if mypageextension:
url = admin_reverse('extensionapp_mypageextension_change', args=(mypageextension.pk,))
else:
url = admin_reverse('extensionapp_mypageextension_add') + '?extended_object=%s' % self.page.pk
except NoReverseMatch:
# not in urls
pass
else:
not_edit_mode = not self.toolbar.edit_mode_active
current_page_menu = self.toolbar.get_or_create_menu('page')
current_page_menu.add_modal_item(_('Page Extension'), url=url, disabled=not_edit_mode)

View file

@ -0,0 +1,47 @@
from django.conf import settings
from django.db import models
from cms.extensions import PageContentExtension, PageExtension
from cms.extensions.extension_pool import extension_pool
class MyPageExtension(PageExtension):
extra = models.CharField(blank=True, default='', max_length=255)
favorite_users = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True)
def copy_relations(self, other, language):
for favorite_user in other.favorite_users.all():
favorite_user.pk = None
favorite_user.mypageextension = self
favorite_user.save()
extension_pool.register(MyPageExtension)
# extension_pool.register can be used also as a decorator
@extension_pool.register
class MyPageContentExtension(PageContentExtension):
extra_title = models.CharField(blank=True, default='', max_length=255)
class MultiTablePageExtensionParent(models.Model):
extension_parent_field = models.CharField(blank=True, default='', max_length=255)
class MultiTablePageExtension(MultiTablePageExtensionParent, PageExtension):
multitable_extra = models.CharField(blank=True, default='', max_length=255)
extension_pool.register(MultiTablePageExtension)
class MultiTableContentExtensionParent(models.Model):
extension_content_parent_field = models.CharField(blank=True, default='', max_length=255)
class MultiTablePageContentExtension(MultiTableContentExtensionParent, PageContentExtension):
multitable_extra_content = models.CharField(blank=True, default='', max_length=255)
extension_pool.register(MultiTablePageContentExtension)

View file

@ -0,0 +1 @@
[{"pk": 1, "model": "cms.placeholder", "fields": {"slot": "translated", "default_width": null}}, {"pk": 2, "model": "cms.placeholder", "fields": {"slot": "translated", "default_width": null}}, {"pk": 3, "model": "cms.placeholder", "fields": {"slot": "translated", "default_width": null}}, {"pk": 4, "model": "cms.placeholder", "fields": {"slot": "translated", "default_width": null}}, {"pk": 5, "model": "cms.placeholder", "fields": {"slot": "translated", "default_width": null}}, {"pk": 6, "model": "cms.placeholder", "fields": {"slot": "translated", "default_width": null}}, {"pk": 7, "model": "cms.placeholder", "fields": {"slot": "translated", "default_width": null}}, {"pk": 1, "model": "cms.cmsplugin", "fields": {"rght": 2, "parent": null, "language": "en", "level": 0, "creation_date": "2011-01-04 08:52:59", "lft": 1, "tree_id": 1, "position": null, "placeholder": 6, "plugin_type": "TextPlugin"}}, {"pk": 2, "model": "cms.cmsplugin", "fields": {"rght": 2, "parent": null, "language": "en", "level": 0, "creation_date": "2011-01-04 08:53:28", "lft": 1, "tree_id": 2, "position": null, "placeholder": 5, "plugin_type": "TextPlugin"}}, {"pk": 1, "model": "text.text", "fields": {"body": "<p>FRENCH!</p>", "cmsplugin_ptr": 1}}, {"pk": 2, "model": "text.text", "fields": {"body": "<p>ENGLISH</p>", "cmsplugin_ptr": 2}}, {"pk": 1, "model": "fakemlng.mainmodel", "fields": {}}, {"pk": 1, "model": "fakemlng.translations", "fields": {"placeholder": 4, "master": 1, "language_code": "de"}}, {"pk": 2, "model": "fakemlng.translations", "fields": {"placeholder": 5, "master": 1, "language_code": "en"}}, {"pk": 3, "model": "fakemlng.translations", "fields": {"placeholder": 6, "master": 1, "language_code": "fr"}}, {"pk": 4, "model": "fakemlng.translations", "fields": {"placeholder": null, "master": 1, "language_code": "nl"}}]

View file

@ -0,0 +1,23 @@
from functools import cached_property
from django.db import models
from cms.models.fields import PlaceholderRelationField
from cms.utils.placeholder import get_placeholder_from_slot
class MainModel(models.Model):
pass
class Translations(models.Model):
master = models.ForeignKey(MainModel, on_delete=models.CASCADE)
language_code = models.CharField(max_length=15, db_index=True)
placeholders = PlaceholderRelationField()
@cached_property
def placeholder(self):
return get_placeholder_from_slot(self.placeholders, "translated")
class Meta:
unique_together = [('master', 'language_code')]

View file

@ -0,0 +1,23 @@
from django.conf import settings
from django.urls import re_path
from cms.apphook_pool import apphook_pool
from cms.views import details
if settings.APPEND_SLASH:
reg = re_path(r'^(?P<slug>[0-9A-Za-z-_.//]+)/$', details, name='pages-details-by-slug')
else:
reg = re_path(r'^(?P<slug>[0-9A-Za-z-_.//]+)$', details, name='pages-details-by-slug')
urlpatterns = [
# Public pages
re_path(r'^$', details, {'slug': ''}, name='pages-root'),
reg,
]
if apphook_pool.get_apphooks():
"""If there are some application urls, add special resolver, so we will
have standard reverse support.
"""
from cms.appresolver import get_app_patterns
urlpatterns = get_app_patterns() + urlpatterns

View file

@ -0,0 +1,23 @@
from django.conf import settings
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.urls import include, re_path
from django.views.i18n import JavaScriptCatalog
from django.views.static import serve
from cms.utils.conf import get_cms_setting
admin.autodiscover()
urlpatterns = [
re_path(r'^admin/', admin.site.urls),
re_path(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
re_path(
r'^media/cms/(?P<path>.*)$', serve, {'document_root': get_cms_setting('MEDIA_ROOT'), 'show_indexes': True}
),
re_path(r'^jsi18n/(?P<packages>\S+?)/$', JavaScriptCatalog.as_view()),
]
urlpatterns += i18n_patterns(
re_path(r'^', include('cms.test_utils.project.fourth_cms_urls_for_apphook_tests')),
)

View file

View file

@ -0,0 +1,31 @@
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from .models import TestPluginAlphaModel, TestPluginBetaModel
class TestPluginAlpha(CMSPluginBase):
model = TestPluginAlphaModel
render_template = 'mti_pluginapp/alpha.html'
name = 'test mti plugin alpha'
def render(self, context, instance, placeholder):
context['alpha'] = instance.alpha
return context
plugin_pool.register_plugin(TestPluginAlpha)
class TestPluginBeta(CMSPluginBase):
model = TestPluginBetaModel
render_template = 'mti_pluginapp/beta.html'
name = 'test mti plugin beta'
def render(self, context, instance, placeholder):
context['alpha'] = instance.alpha
context['beta'] = instance.beta
return context
plugin_pool.register_plugin(TestPluginBeta)

Some files were not shown because too many files have changed in this diff Show more