Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creates an initial newsletter sign-up form #33

Open
wants to merge 2 commits into
base: new
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Empty file.
15 changes: 15 additions & 0 deletions djangodenmark/apps/newsletter/templates/consent/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "base.html" %}


{% comment %}
This part of the demo shows how you can overwrite consent/base.html in order to
have your own main template apply to django-consent's built-in templates.

Simply place the consent_content block in the appropriate location.
{% endcomment %}

{% block content %}
{% block consent_content %}

{% endblock %}
{% endblock %}
27 changes: 27 additions & 0 deletions djangodenmark/apps/newsletter/templates/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% extends "base.html" %}

{% block content %}

<h1>Sign up for {{ consent_source.source_name }}</h1>

<p>
The below form is an example of inheriting from <code>ConsentCreateView</code> which
uses the <code>EmailConsentForm</code>. In your own application, you can make
similar patterns and it's encouraged that you extend one of these two classes.
</p>

<form method="POST">

{% csrf_token %}

<table>
{{ form.as_table }}
</table>

<p>
<button type="submit">Send</button>
</p>

</form>

{% endblock %}
Empty file.
9 changes: 9 additions & 0 deletions djangodenmark/apps/newsletter/templatetags/demotags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django import template
from django_consent import models

register = template.Library()


@register.simple_tag
def consent_sources():
return models.ConsentSource.objects.all()
21 changes: 21 additions & 0 deletions djangodenmark/apps/newsletter/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.urls import path

from . import views


app_name = "newsletter"


urlpatterns = [
path("", views.Index.as_view(), name="index"),
path(
"signup/<int:source_id>/",
views.ConsentCreateView.as_view(),
name="signup",
),
path(
"signup/<int:source_id>/confirmation/",
views.ConsentConfirmationSentView.as_view(),
name="signup_confirmation",
),
]
32 changes: 32 additions & 0 deletions djangodenmark/apps/newsletter/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from django.urls.base import reverse
from django.views.generic.base import RedirectView
from django_consent import models
from django_consent.views import ConsentConfirmationSentView
from django_consent.views import ConsentCreateView


class Index(RedirectView):

permanent = False

def get_redirect_url(self, *args, **kwargs):
source = models.ConsentSource.objects.all().first()
if not source:
source = models.ConsentSource.objects.create(
source_name="Auto-created default newsletter"
)
return reverse("newsletter:signup", kwargs={"source_id": source.id})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the really sloppy part. This should be a proper data migration. The /newsletter/ redirect is perhaps useful, but more likely completely useless :)



class ConsentCreateView(ConsentCreateView):
template_name = "signup.html"

def get_success_url(self):
return reverse(
"newsletter:signup_confirmation",
kwargs={"source_id": self.consent_source.id},
)


class ConsentConfirmationSentView(ConsentConfirmationSentView):
pass
1 change: 1 addition & 0 deletions djangodenmark/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"djangodenmark.apps.memberships",
"djangodenmark.apps.newsletter",
"django_consent",
"djangodenmark.apps.events",
"djangodenmark.apps.accounts",
Expand Down
4 changes: 4 additions & 0 deletions djangodenmark/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
from django.contrib import admin
from django.urls import include
from django.urls import path
from django_consent import urls as consent_urls

from .apps.companies import urls as company_urls
from .apps.events import urls as event_urls
from .apps.jobposts import urls as jobpost_urls
from .apps.newsletter import urls as newsletter_urls

urlpatterns = [
path("admin/", admin.site.urls),
Expand All @@ -30,6 +32,8 @@
path("accounts/", include("django.contrib.auth.urls")),
path("companies/", include(company_urls)),
path("jobs/", include(jobpost_urls)),
path("consent/", include(consent_urls)),
path("newsletter/", include(newsletter_urls)),
]

if settings.DEBUG:
Expand Down