-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from hidalgopl/add-crud-newsletter-signup-example
Add newsletter signup example
- Loading branch information
Showing
10 changed files
with
175 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 3.2 on 2021-04-25 17:06 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='NewsletterSubscription', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('email', models.EmailField(max_length=254)), | ||
('name', models.CharField(max_length=256)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
from django.db import models | ||
|
||
# Create your models here. | ||
|
||
class NewsletterSubscription(models.Model): | ||
email = models.EmailField() | ||
name = models.CharField(max_length=256) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from sockpuppet.reflex import Reflex | ||
|
||
from core.models import NewsletterSubscription | ||
|
||
|
||
class SubscriptionReflex(Reflex): | ||
def add_person(self): | ||
o = NewsletterSubscription.objects.update_or_create( | ||
name=self.params['name'], | ||
email=self.params['email'] | ||
) | ||
|
||
def remove_person(self): | ||
id = self.element.dataset['id'] | ||
NewsletterSubscription.objects.filter(id=id).delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{% load static %} | ||
|
||
|
||
<h2>Sign up for newsletter!</h2> | ||
<form id="morph-form" data-reflex-root="#morph"> | ||
{{ form }} | ||
<input type="submit" data-reflex="click->Subscription_Reflex#add_person"> | ||
<div id="morph"> | ||
<h2>Signed:</h2> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th scope="col">Name</th> | ||
<th scope="col">Email</th> | ||
<th scope="col">Remove</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for p in people %} | ||
<tr> | ||
<td>{{ p.name }} </td> | ||
<td>{{ p.email }}</td> | ||
<td><a href="#" data-reflex="click->Subscription_Reflex#remove_person" | ||
data-id="{{ p.id }}">Remove</a></td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from django.forms import ModelForm | ||
from django.views.generic.edit import FormView | ||
|
||
from core.models import NewsletterSubscription | ||
from core.views.mixins import NewsletterSignupMixin | ||
|
||
|
||
class NewsletterSubscriptionForm(ModelForm): | ||
class Meta: | ||
model = NewsletterSubscription | ||
fields = ['name', 'email'] | ||
|
||
|
||
class NewsletterSignupView(NewsletterSignupMixin, FormView): | ||
demo_template = '_newsletter_signup.html' | ||
form_class = NewsletterSubscriptionForm | ||
subtitle = 'Newsletter Signup' | ||
|
||
def get_context_data(self, *args, **kwargs): | ||
context = super().get_context_data(*args, **kwargs) | ||
context['people'] = NewsletterSubscription.objects.all() | ||
return context | ||
|
||
|
||
view = NewsletterSignupView.as_view() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# | ||
# This file is autogenerated by pip-compile | ||
# To update, run: | ||
# | ||
# pip-compile --output-file=requirements.txt requirements.in | ||
# | ||
aioredis==1.3.1 # via channels-redis | ||
asgiref==3.3.4 # via channels, channels-redis, daphne, django | ||
async-timeout==3.0.1 # via aioredis | ||
attrs==21.2.0 # via automat, service-identity, twisted | ||
autobahn==21.3.1 # via daphne | ||
automat==20.2.0 # via twisted | ||
bcrypt==3.2.0 # via paramiko | ||
beautifulsoup4==4.9.3 # via bs4 | ||
bs4==0.0.1 # via django-sockpuppet | ||
certifi==2020.12.5 # via requests | ||
cffi==1.14.5 # via bcrypt, cryptography, pynacl | ||
channels-redis==3.2.0 # via django-sockpuppet | ||
channels==3.0.3 # via channels-redis, django-sockpuppet | ||
chardet==4.0.0 # via requests | ||
constantly==15.1.0 # via twisted | ||
cryptography==3.4.7 # via autobahn, paramiko, pyopenssl, service-identity | ||
daphne==3.0.2 # via channels | ||
django-pygments-renderer==0.0.1 # via -r requirements.in | ||
django-redis==4.12.1 # via -r requirements.in | ||
django-seed==0.2.2 # via -r requirements.in | ||
django-sockpuppet==0.6.0 # via -r requirements.in | ||
django-webpack-loader==0.7.0 # via -r requirements.in | ||
django-widget-tweaks==1.4.8 # via -r requirements.in | ||
django==3.2.2 # via -r requirements.in, channels, django-pygments-renderer, django-redis, django-seed | ||
fabric==2.6.0 # via -r requirements.in, patchwork | ||
faker==8.1.2 # via django-seed | ||
gunicorn==20.1.0 # via -r requirements.in | ||
hiredis==2.0.0 # via aioredis | ||
hyperlink==21.0.0 # via autobahn, twisted | ||
idna==2.10 # via hyperlink, requests, twisted | ||
incremental==21.3.0 # via twisted | ||
invoke==1.5.0 # via fabric | ||
msgpack==1.0.2 # via channels-redis | ||
paramiko==2.7.2 # via fabric | ||
patchwork==1.0.1 # via -r requirements.in | ||
pathlib2==2.3.5 # via fabric | ||
pyasn1-modules==0.2.8 # via service-identity | ||
pyasn1==0.4.8 # via pyasn1-modules, service-identity | ||
pycparser==2.20 # via cffi | ||
pygments==2.9.0 # via django-pygments-renderer | ||
pynacl==1.4.0 # via paramiko | ||
pyopenssl==20.0.1 # via twisted | ||
python-dateutil==2.8.1 # via faker | ||
pytz==2021.1 # via django | ||
redis==3.5.3 # via django-redis | ||
requests==2.25.1 # via -r requirements.in | ||
service-identity==21.1.0 # via twisted | ||
six==1.16.0 # via automat, bcrypt, pathlib2, pynacl, pyopenssl, python-dateutil, service-identity | ||
soupsieve==2.2.1 # via beautifulsoup4 | ||
sqlparse==0.4.1 # via django | ||
text-unidecode==1.3 # via faker | ||
twisted[tls]==21.2.0 # via daphne | ||
txaio==21.2.1 # via autobahn | ||
urllib3==1.26.4 # via requests | ||
whitenoise==5.2.0 # via -r requirements.in | ||
zope.interface==5.4.0 # via twisted | ||
|
||
# The following packages are considered to be unsafe in a requirements file: | ||
# setuptools |