-
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.
- Loading branch information
Showing
6 changed files
with
99 additions
and
1 deletion.
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,33 @@ | ||
{% load static %} | ||
<body xmlns="http://www.w3.org/1999/html"> | ||
|
||
|
||
<script src="{% static 'sockpuppet/sockpuppet.js' %}"></script> | ||
<h2>Sign up for newsletter!</h2> | ||
<form id="morph-form"> | ||
{{ form }} | ||
<input type="submit" data-reflex="click->Subscription_Reflex#add_person" data-reflex-root="#morph"> | ||
<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> | ||
</body> |
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,23 @@ | ||
from django.forms import ModelForm | ||
from django.views.generic.edit import FormView | ||
|
||
from core.models import NewsletterSubscription | ||
|
||
|
||
class NewsletterSubscriptionForm(ModelForm): | ||
class Meta: | ||
model = NewsletterSubscription | ||
fields = ['name', 'email'] | ||
|
||
|
||
class YourReflexNameView(FormView): | ||
template_name = '_newsletter_signup.html' | ||
form_class = NewsletterSubscriptionForm | ||
|
||
def get_context_data(self, *args, **kwargs): | ||
context = super().get_context_data(*args, **kwargs) | ||
context['people'] = NewsletterSubscription.objects.all() | ||
return context | ||
|
||
|
||
view = YourReflexNameView.as_view() |