Skip to content

Commit 634c9a5

Browse files
committed
Fixup wagtail
1 parent 9e6097a commit 634c9a5

12 files changed

Lines changed: 629 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2010 New Relic, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2010 New Relic, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import webtest
16+
from wsgi import application
17+
18+
_target_application = webtest.TestApp(application)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2010 New Relic, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import pytest
16+
17+
from newrelic.api.application import application_instance
18+
from newrelic.core.agent import agent_instance
19+
20+
21+
# Even though `django_collector_agent_registration_fixture()` also
22+
# has the application deletion during the breakdown of the fixture,
23+
# and `django_collector_agent_registration_fixture()` is scoped to
24+
# "function", not all modules are using this. Some are using
25+
# `collector_agent_registration_fixture()` scoped to "module".
26+
# Therefore, for those instances, we need to make sure that the
27+
# application is removed from the agent.
28+
@pytest.fixture(scope="module", autouse=True)
29+
def remove_application_from_agent():
30+
yield
31+
application = application_instance()
32+
if application and application.name and (application.name in agent_instance()._applications):
33+
del agent_instance()._applications[application.name]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2010 New Relic, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2010 New Relic, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from django.apps import AppConfig
16+
17+
18+
class LibraryConfig(AppConfig):
19+
default_auto_field = "django.db.models.BigAutoField"
20+
name = "dummy_app"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2010 New Relic, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from django.db import models
16+
from wagtail.models import Page
17+
from wagtail.contrib.routable_page.models import RoutablePage, re_path
18+
from wagtail.fields import RichTextField
19+
20+
class HomePage(Page):
21+
body = RichTextField(blank=True)
22+
23+
content_panels = Page.content_panels + ["body"]
24+
25+
26+
class RoutablePage(RoutablePage):
27+
body = RichTextField(blank=True)
28+
29+
content_panels = Page.content_panels + ["body"]
30+
31+
@re_path(r"^routable")
32+
def index(self, request):
33+
# Handle URLs of the form /<id>
34+
return super().serve(request)
35+
36+
class Meta:
37+
verbose_name = "Routable page"
38+
39+
def __str__(self):
40+
return "Page from routable"
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
from django.db import migrations, models
2+
import wagtail.fields
3+
from wagtail.models import Page
4+
import django.db.models.deletion
5+
import wagtail.contrib.routable_page.models
6+
7+
8+
def create_homepage(apps, schema_editor):
9+
# Get models
10+
ContentType = apps.get_model("contenttypes.ContentType")
11+
Page = apps.get_model("wagtailcore.Page")
12+
Site = apps.get_model("wagtailcore.Site")
13+
HomePage = apps.get_model("home.HomePage")
14+
15+
# Delete the default homepage
16+
# If migration is run multiple times, it may have already been deleted
17+
Page.objects.filter(id=2).delete()
18+
19+
# Create content type for homepage model
20+
homepage_content_type, __ = ContentType.objects.get_or_create(
21+
model="homepage", app_label="home"
22+
)
23+
24+
# Create a new homepage
25+
homepage = HomePage.objects.create(
26+
title="Home",
27+
draft_title="Home",
28+
slug="home",
29+
content_type=homepage_content_type,
30+
path="00010001",
31+
depth=2,
32+
numchild=0,
33+
url_path="/home/",
34+
)
35+
36+
# Create a site with the new homepage set as the root
37+
Site.objects.create(hostname="localhost", root_page=homepage, is_default_site=True)
38+
39+
def remove_homepage(apps, schema_editor):
40+
# Get models
41+
ContentType = apps.get_model("contenttypes.ContentType")
42+
HomePage = apps.get_model("home.HomePage")
43+
44+
# Delete the default homepage
45+
# Page and Site objects CASCADE
46+
HomePage.objects.filter(slug="home", depth=2).delete()
47+
48+
# Delete content type for homepage model
49+
ContentType.objects.filter(model="homepage", app_label="home").delete()
50+
51+
52+
class Migration(migrations.Migration):
53+
54+
dependencies = [
55+
("wagtailcore", "0040_page_draft_title"),
56+
]
57+
58+
operations = [
59+
migrations.CreateModel(
60+
name="HomePage",
61+
fields=[
62+
(
63+
"page_ptr",
64+
models.OneToOneField(
65+
on_delete=models.CASCADE,
66+
parent_link=True,
67+
auto_created=True,
68+
primary_key=True,
69+
serialize=False,
70+
to="wagtailcore.Page",
71+
),
72+
),
73+
],
74+
options={
75+
"abstract": False,
76+
},
77+
bases=("wagtailcore.page",),
78+
),
79+
migrations.RunPython(create_homepage, remove_homepage),
80+
migrations.AddField(
81+
model_name='homepage',
82+
name='body',
83+
field=wagtail.fields.RichTextField(blank=True),
84+
),
85+
migrations.CreateModel(
86+
name='RoutablePage',
87+
fields=[
88+
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')),
89+
],
90+
options={
91+
'verbose_name': 'Routable page',
92+
},
93+
bases=(wagtail.contrib.routable_page.models.RoutablePage,),
94+
),
95+
migrations.AddField(
96+
model_name='routablepage',
97+
name='body',
98+
field=wagtail.fields.RichTextField(blank=True),
99+
),
100+
]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright 2010 New Relic, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
from pathlib import Path
17+
18+
BASE_DIR = Path(__file__).parent
19+
DEBUG = True
20+
21+
# Make this unique, and don't share it with anybody.
22+
SECRET_KEY = "cookies"
23+
24+
# List of callables that know how to import templates from various sources.
25+
TEMPLATE_LOADERS = ("django.template.loaders.filesystem.Loader", "django.template.loaders.app_directories.Loader")
26+
27+
MIDDLEWARE = (
28+
"django.middleware.common.CommonMiddleware",
29+
"django.contrib.sessions.middleware.SessionMiddleware",
30+
"django.middleware.csrf.CsrfViewMiddleware",
31+
"django.contrib.auth.middleware.AuthenticationMiddleware",
32+
"django.contrib.messages.middleware.MessageMiddleware",
33+
"django.middleware.gzip.GZipMiddleware",
34+
)
35+
36+
ROOT_URLCONF = "urls"
37+
38+
TEMPLATE_DIRS = [BASE_DIR / "templates"]
39+
40+
# For Django 1.10 compatibility because TEMPLATE_DIRS is deprecated
41+
TEMPLATES = [{"BACKEND": "django.template.backends.django.DjangoTemplates", "DIRS": TEMPLATE_DIRS}]
42+
43+
INSTALLED_APPS = [
44+
"dummy_app",
45+
"wagtail.contrib.forms",
46+
"wagtail.contrib.redirects",
47+
"wagtail.embeds",
48+
"wagtail.sites",
49+
"wagtail.users",
50+
"wagtail.snippets",
51+
"wagtail.documents",
52+
"wagtail.images",
53+
"wagtail.search",
54+
"wagtail.admin",
55+
"wagtail",
56+
"django_filters",
57+
"django.contrib.admin",
58+
"django.contrib.auth",
59+
"django.contrib.contenttypes",
60+
"django.contrib.sessions",
61+
"django.contrib.messages",
62+
"django.contrib.staticfiles",
63+
]
64+
65+
DATABASES = {
66+
"default": {
67+
"ENGINE": "django.db.backends.sqlite3",
68+
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
69+
}
70+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{% load static wagtailcore_tags wagtailuserbar %}
2+
3+
<!DOCTYPE html>
4+
<html lang="en">
5+
<head>
6+
<meta charset="utf-8" />
7+
<title>
8+
{% block title %}
9+
{% if page.seo_title %}{{ page.seo_title }}{% else %}{{ page.title }}{% endif %}
10+
{% endblock %}
11+
{% block title_suffix %}
12+
{% wagtail_site as current_site %}
13+
{% if current_site and current_site.site_name %}- {{ current_site.site_name }}{% endif %}
14+
{% endblock %}
15+
</title>
16+
{% if page.search_description %}
17+
<meta name="description" content="{{ page.search_description }}" />
18+
{% endif %}
19+
<meta name="viewport" content="width=device-width, initial-scale=1" />
20+
21+
{# Force all links in the live preview panel to be opened in a new tab #}
22+
{% if request.in_preview_panel %}
23+
<base target="_blank">
24+
{% endif %}
25+
26+
{# Global stylesheets #}
27+
<link rel="stylesheet" type="text/css" href="{% static 'css/nr_debug.css' %}">
28+
29+
{% block extra_css %}
30+
{# Override this in templates to add extra stylesheets #}
31+
{% endblock %}
32+
</head>
33+
34+
<body class="{% block body_class %}{% endblock %}">
35+
{% wagtailuserbar %}
36+
37+
{% block content %}{% endblock %}
38+
39+
{# Global javascript #}
40+
<script type="text/javascript" src="{% static 'js/nr_debug.js' %}"></script>
41+
42+
{% block extra_js %}
43+
{# Override this in templates to add extra javascript #}
44+
{% endblock %}
45+
</body>
46+
</html>

0 commit comments

Comments
 (0)