Compare commits
No commits in common. "bee761e0c4962518a0c4531ed36bd8fff47dca6b" and "67d5aecd977b66c92931f88db63111c729b10c35" have entirely different histories.
bee761e0c4
...
67d5aecd97
9 changed files with 6 additions and 96 deletions
|
|
@ -57,16 +57,12 @@ def email2name(email):
|
||||||
name = " ".join([part.capitalize() for part in name.split(" ")])
|
name = " ".join([part.capitalize() for part in name.split(" ")])
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def is_subscribed(email):
|
|
||||||
url = settings.LISTMONK_API + 'subscribers'
|
|
||||||
auth = (settings.LISTMONK_USER, settings.LISTMONK_PASSWORD)
|
|
||||||
exists = url + '?' + "list_id=&query=email='%s'&page=1&order_by=id&order=desc" % email
|
|
||||||
return bool(len(requests.get(exists, auth=auth).json()['data']['results']))
|
|
||||||
|
|
||||||
def add_email(email):
|
def add_email(email):
|
||||||
url = settings.LISTMONK_API + 'subscribers'
|
url = settings.LISTMONK_API + 'subscribers'
|
||||||
auth = (settings.LISTMONK_USER, settings.LISTMONK_PASSWORD)
|
auth = (settings.LISTMONK_USER, settings.LISTMONK_PASSWORD)
|
||||||
if not is_subscribed(email):
|
exists = url + '?' + "list_id=&query=email='%s'&page=1&order_by=id&order=desc" % email
|
||||||
|
if not len(requests.get(exists, auth=auth).json()['data']['results']):
|
||||||
data = {
|
data = {
|
||||||
"email": email,
|
"email": email,
|
||||||
"name": email2name(email),
|
"name": email2name(email),
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,13 @@
|
||||||
import json
|
|
||||||
|
|
||||||
from brake.decorators import ratelimit
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth import get_user_model
|
|
||||||
from django.db.models.functions import ExtractWeek, ExtractYear
|
from django.db.models.functions import ExtractWeek, ExtractYear
|
||||||
from django.shortcuts import redirect, render
|
from django.shortcuts import render
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.timezone import datetime, timedelta
|
from django.utils.timezone import datetime, timedelta
|
||||||
from django.core.validators import validate_email
|
|
||||||
import django.contrib.auth
|
|
||||||
|
|
||||||
from ..item import models
|
from ..item import models
|
||||||
from ..item.views import get_weeks, format_week, get_monday, get_byline
|
from ..item.views import get_weeks, format_week, get_monday, get_byline
|
||||||
from ..item.utils import render_to_json
|
|
||||||
from ..utils import default_context
|
|
||||||
|
|
||||||
from . import utils
|
|
||||||
|
|
||||||
|
|
||||||
User = get_user_model()
|
|
||||||
|
|
||||||
|
|
||||||
def week(year, month, day):
|
def week(year, month, day):
|
||||||
|
|
@ -45,40 +32,3 @@ def week(year, month, day):
|
||||||
context['week_link'] = settings.URL + '/_' + monday
|
context['week_link'] = settings.URL + '/_' + monday
|
||||||
context['items'] = archive_week
|
context['items'] = archive_week
|
||||||
return render_to_string("weekly_email.html", context)
|
return render_to_string("weekly_email.html", context)
|
||||||
|
|
||||||
|
|
||||||
@ratelimit(method="POST", block=True, rate="5/m")
|
|
||||||
def subscribe(request):
|
|
||||||
context = default_context(request)
|
|
||||||
response = {}
|
|
||||||
request_type = 'json'
|
|
||||||
if request.method == "POST":
|
|
||||||
if "email" in request.POST:
|
|
||||||
data = request.POST
|
|
||||||
request_type = 'html'
|
|
||||||
else:
|
|
||||||
data = json.loads(request.body)
|
|
||||||
if not response:
|
|
||||||
try:
|
|
||||||
validate_email(data["email"])
|
|
||||||
except ValidationError as e:
|
|
||||||
response['error'] = 'please enter a valid email address.'
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
if utils.is_subscribed(data["email"]):
|
|
||||||
pass
|
|
||||||
elif not utils.add_email(data["email"]):
|
|
||||||
response['error'] = 'failed to add email to weekly digest.'
|
|
||||||
except:
|
|
||||||
response['error'] = 'failed to add your email, please try again later.'
|
|
||||||
|
|
||||||
if request_type == 'html':
|
|
||||||
if 'error' in response:
|
|
||||||
context['error'] = response['error']
|
|
||||||
return render(request, 'subscribe.html', context)
|
|
||||||
else:
|
|
||||||
context["subscribed"] = True
|
|
||||||
return render(request, 'subscribe.html', context)
|
|
||||||
return render_to_json(response)
|
|
||||||
else:
|
|
||||||
return render(request, 'subscribe.html', context)
|
|
||||||
|
|
|
||||||
|
|
@ -250,7 +250,7 @@ nav.overlay {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.login, .register, .subscribe, .digest{
|
.login, .register {
|
||||||
margin-top: 16px;
|
margin-top: 16px;
|
||||||
margin-left: 24px;
|
margin-left: 24px;
|
||||||
textarea,
|
textarea,
|
||||||
|
|
@ -276,9 +276,6 @@ nav.overlay {
|
||||||
border: solid 1px lightgreen;
|
border: solid 1px lightgreen;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
.error {
|
|
||||||
color: red;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,6 @@ window.VideoPlayer = function(options) {
|
||||||
height: 32px;
|
height: 32px;
|
||||||
}
|
}
|
||||||
.mx-controls .controls .position {
|
.mx-controls .controls .position {
|
||||||
cursor: pointer;
|
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
.mx-controls .toggle svg {
|
.mx-controls .toggle svg {
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,6 @@
|
||||||
</header>
|
</header>
|
||||||
<div class="about">
|
<div class="about">
|
||||||
{{ overlay.content | safe }}
|
{{ overlay.content | safe }}
|
||||||
<div class="digest">
|
|
||||||
{% include "subscribe_form.html" %}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{% if now %}
|
{% if now %}
|
||||||
<div class="now">
|
<div class="now">
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block head %}
|
{% block head %}
|
||||||
<title>Register - {{ settings.SITENAME }}</title>
|
<title>Login - {{ settings.SITENAME }}</title>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="register">
|
<div class="register">
|
||||||
|
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
{% extends "base.html" %}
|
|
||||||
{% block head %}
|
|
||||||
<title>Subscribe - {{ settings.SITENAME }}</title>
|
|
||||||
{% endblock %}
|
|
||||||
{% block content %}
|
|
||||||
<div class="subscribe">
|
|
||||||
{% if subscribed %}
|
|
||||||
Thank you for subscribing to our weekly email digest.
|
|
||||||
<script>
|
|
||||||
setTimeout(function() {
|
|
||||||
document.location.href = '/'
|
|
||||||
}, 3000)
|
|
||||||
</script>
|
|
||||||
{% else %}
|
|
||||||
You can subscribe to a weekly email digest with all clips, edits, sirens and phantoms published in the week.
|
|
||||||
{% include "subscribe_form.html" %}
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
<form method="POST" action="{% url 'subscribe' %}">
|
|
||||||
{% csrf_token %}
|
|
||||||
<input name="email" type="email" placeholder="your email" required></input>
|
|
||||||
<button id="subscribe">Subscribe to weekly digest</button>
|
|
||||||
<div class="error">{{ error }}</div>
|
|
||||||
</form>
|
|
||||||
|
|
@ -20,7 +20,6 @@ from django.urls import path, re_path
|
||||||
from .item import views as item_views
|
from .item import views as item_views
|
||||||
from .user import views as user_views
|
from .user import views as user_views
|
||||||
from .page import views as page_views
|
from .page import views as page_views
|
||||||
from .listmonk import views as email_views
|
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
|
@ -32,7 +31,6 @@ urlpatterns = [
|
||||||
path('login/', user_views.login, name='login'),
|
path('login/', user_views.login, name='login'),
|
||||||
path('logout/', user_views.logout, name='logout'),
|
path('logout/', user_views.logout, name='logout'),
|
||||||
path('register/', user_views.register, name='register'),
|
path('register/', user_views.register, name='register'),
|
||||||
path('subscribe/', email_views.subscribe, name='subscribe'),
|
|
||||||
path('comment/publish/', item_views.publish_comment, name='publish-comment'),
|
path('comment/publish/', item_views.publish_comment, name='publish-comment'),
|
||||||
path('comment/', item_views.comment, name='comment'),
|
path('comment/', item_views.comment, name='comment'),
|
||||||
path('_<int:year>-<int:month>-<int:day>/', item_views.archive, name='archive'),
|
path('_<int:year>-<int:month>-<int:day>/', item_views.archive, name='archive'),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue