Skip to content

Commit 1449a71

Browse files
committed
Creates an initial newsletter sign-up form
1 parent dcf37e3 commit 1449a71

File tree

11 files changed

+168
-0
lines changed

11 files changed

+168
-0
lines changed

djangodenmark/apps/newsletter/__init__.py

Whitespace-only changes.

djangodenmark/apps/newsletter/migrations/__init__.py

Whitespace-only changes.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
body, html {
2+
font-family: monospace;
3+
margin: 0;
4+
padding: 0;
5+
font-size: 120%;
6+
}
7+
8+
header, article, footer {
9+
margin: 0 auto;
10+
}
11+
12+
header {
13+
background-color: #5500ab;
14+
color: #fff;
15+
}
16+
17+
.container {
18+
margin: 0 auto;
19+
max-width: 800px;
20+
padding: 20px;
21+
}
22+
23+
a, a:visited, a:active {
24+
color: #fff;
25+
}
26+
27+
td, th {
28+
padding: 10px 0;
29+
}
30+
th {
31+
text-align: left;
32+
line-height: 40px;
33+
vertical-align: top;
34+
padding-right: 20px;
35+
}
36+
37+
38+
td input,
39+
td textarea {
40+
width: 300px;
41+
}
42+
43+
input[type=checkbox]
44+
{
45+
width: auto;
46+
margin-bottom: 5px;
47+
}
48+
49+
input, textarea, select {
50+
font-family: monospace;
51+
font-size: 120%;
52+
padding: 5px;
53+
}
54+
55+
code {
56+
border: 1px solid #ccc;
57+
padding: 3px;
58+
font-size: 80%;
59+
background-color: #f8f8f8;
60+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% extends "base.html" %}
2+
3+
4+
{% comment %}
5+
This part of the demo shows how you can overwrite consent/base.html in order to
6+
have your own main template apply to django-consent's built-in templates.
7+
8+
Simply place the consent_content block in the appropriate location.
9+
{% endcomment %}
10+
11+
{% block demo_content %}
12+
{% block consent_content %}
13+
14+
{% endblock %}
15+
{% endblock %}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
5+
<h1>Sign up for {{ consent_source.source_name }}</h1>
6+
7+
<p>
8+
The below form is an example of inheriting from <code>ConsentCreateView</code> which
9+
uses the <code>EmailConsentForm</code>. In your own application, you can make
10+
similar patterns and it's encouraged that you extend one of these two classes.
11+
</p>
12+
13+
<form method="POST">
14+
15+
{% csrf_token %}
16+
17+
<table>
18+
{{ form.as_table }}
19+
</table>
20+
21+
<p>
22+
<button type="submit">Send</button>
23+
</p>
24+
25+
</form>
26+
27+
{% endblock %}

djangodenmark/apps/newsletter/templatetags/__init__.py

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django import template
2+
from django_consent import models
3+
4+
register = template.Library()
5+
6+
7+
@register.simple_tag
8+
def consent_sources():
9+
return models.ConsentSource.objects.all()

djangodenmark/apps/newsletter/urls.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from django.urls import path
2+
3+
from . import views
4+
5+
6+
app_name = "newsletter"
7+
8+
9+
urlpatterns = [
10+
path("", views.Index.as_view(), name="index"),
11+
path(
12+
"signup/<int:source_id>/",
13+
views.ConsentCreateView.as_view(),
14+
name="signup",
15+
),
16+
path(
17+
"signup/<int:source_id>/confirmation/",
18+
views.ConsentConfirmationSentView.as_view(),
19+
name="signup_confirmation",
20+
),
21+
]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from django.urls.base import reverse
2+
from django.views.generic.base import RedirectView
3+
from django_consent import models
4+
from django_consent.views import ConsentConfirmationSentView
5+
from django_consent.views import ConsentCreateView
6+
7+
8+
class Index(RedirectView):
9+
10+
permanent = False
11+
12+
def get_redirect_url(self, *args, **kwargs):
13+
source = models.ConsentSource.objects.all().first()
14+
if not source:
15+
source = models.ConsentSource.objects.create(
16+
source_name="Auto-created default newsletter"
17+
)
18+
return reverse("newsletter:signup", kwargs={"source_id": source.id})
19+
20+
21+
class ConsentCreateView(ConsentCreateView):
22+
template_name = "signup.html"
23+
24+
def get_success_url(self):
25+
return reverse(
26+
"demo:signup_confirmation", kwargs={"source_id": self.consent_source.id}
27+
)
28+
29+
30+
class ConsentConfirmationSentView(ConsentConfirmationSentView):
31+
pass

djangodenmark/settings/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"djangodenmark.apps.companies",
2525
"widget_tweaks",
2626
"djangodenmark.apps.jobposts",
27+
"djangodenmark.apps.newsletter",
2728
]
2829

2930
MIDDLEWARE = [

djangodenmark/urls.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
from django.contrib import admin
1919
from django.urls import include
2020
from django.urls import path
21+
from django_consent import urls as consent_urls
2122

2223
from .apps.companies import urls as company_urls
2324
from .apps.events import urls as event_urls
2425
from .apps.jobposts import urls as jobpost_urls
26+
from .apps.newsletter import urls as newsletter_urls
2527

2628
urlpatterns = [
2729
path("admin/", admin.site.urls),
@@ -30,6 +32,8 @@
3032
path("accounts/", include("django.contrib.auth.urls")),
3133
path("companies/", include(company_urls)),
3234
path("jobs/", include(jobpost_urls)),
35+
path("consent/", include(consent_urls)),
36+
path("newsletter/", include(newsletter_urls)),
3337
]
3438

3539
if settings.DEBUG:

0 commit comments

Comments
 (0)