diff --git a/README.md b/README.md
index 06d715a..878d076 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ By popular demand, I'm building a better anonkun. It doesn't do much right now t
Python 3.6+
PostgreSQL 10.4+
Redis 4.0.10+
-Python packages: `django psycopg2 channels channels_redis jinja2 argon2-cffi bleach requests python-magic django-taggit`
+Python packages: `django psycopg2 channels channels_redis jinja2 argon2-cffi bleach requests python-magic django-taggit django-user-messages`
## Install
```
diff --git a/jinja2/base.html b/jinja2/base.html
index 6d11e6a..6959ce4 100644
--- a/jinja2/base.html
+++ b/jinja2/base.html
@@ -23,8 +23,10 @@
↓
- {% for message in get_messages(request) %}
- - {{ message }}
+ {% for message in get_messages(request=request) %}
+ {% if "subscription" not in message.tags %}
+ - {{ message }}
+ {% endif %}
{% endfor %}
{% block content %}{% endblock %}
diff --git a/quest/jinja2/quest/quest_header.html b/quest/jinja2/quest/quest_header.html
index 4edd220..5ebe8d0 100644
--- a/quest/jinja2/quest/quest_header.html
+++ b/quest/jinja2/quest/quest_header.html
@@ -25,7 +25,7 @@
{% if request.user.is_authenticated %}
- Profile
+ {{ request.user.username }}
{% endif %}
{% if request.session.get("hide_chat") == True %}←{% else %}→{% endif %}
diff --git a/quest/jinja2/quest/quest_homepage.html b/quest/jinja2/quest/quest_homepage.html
index 114e28b..3f48d60 100644
--- a/quest/jinja2/quest/quest_homepage.html
+++ b/quest/jinja2/quest/quest_homepage.html
@@ -37,6 +37,12 @@
{% endif %}
+ {% if request.user.is_authenticated %}
+
+ {% endif %}
Pages
{% for page in pages %}
diff --git a/quest/urls.py b/quest/urls.py
index afae657..19fd333 100644
--- a/quest/urls.py
+++ b/quest/urls.py
@@ -10,6 +10,7 @@ app_name = 'quest'
urlpatterns = [
path('', views.index, name='index'),
path('/new_tag', views.new_tag, name='new_tag'),
+ path('/subscribe', views.subscribe, name='subscribe'),
path('/edit_quest', views.edit_quest, name='edit_quest'),
path('//edit_quest', views.edit_quest, name='edit_quest'),
path('', views.quest, name='quest'),
diff --git a/quest/views.py b/quest/views.py
index e1b590d..0eb1deb 100644
--- a/quest/views.py
+++ b/quest/views.py
@@ -5,6 +5,7 @@ Quest and quest accessory views.
from datetime import timedelta, datetime, timezone
import bleach
+from user_messages import api
from django.views.decorators.http import require_POST
from django.contrib import messages
from django.shortcuts import render, redirect
@@ -85,6 +86,7 @@ def edit_quest(request, quest_id, page_num='0'):
Edit quest page. Only available to the QM.
"""
quest = Quest.objects.get(id=quest_id)
+ prev_live = quest.live
if quest.owner != request.user:
return redirect('quest:quest', quest_id=quest_id, page_num=page_num)
if request.method == 'POST':
@@ -119,6 +121,15 @@ def edit_quest(request, quest_id, page_num='0'):
if data['live_time']:
data['live_time'] =data['live_time'].strftime('%Y-%m-%d %H:%M')
send_to_websocket('live', quest_id, data)
+ if prev_live == False and quest.live == True:
+ subscribers = quest.user_set.all()
+ for subscriber in subscribers:
+ api.info(
+ subscriber,
+ f"{quest.title} has gone live!",
+ extra_tags='subscription',
+ deliver_once=False
+ )
return redirect('quest:quest',quest_id=quest.id, page_num=page_num)
else:
messages.error(request, "Error")
@@ -176,3 +187,13 @@ def new_tag(request, quest_id):
quest.tags.add(tag)
return redirect('quest:quest', quest_id=quest_id, page_num='0')
+
+
+@require_POST
+def subscribe(request, quest_id):
+ """Endpoint for users to subscribe to a quest."""
+ if not request.user.is_authenticated:
+ return redirect('login:index')
+ request.user.subscriptions.add(Quest.objects.get(id=quest_id))
+ messages.success(request, "Subscribed")
+ return redirect('quest:quest', quest_id=quest_id, page_num='0')
diff --git a/titivillus/jinja2.py b/titivillus/jinja2.py
index 34bba17..c85594d 100644
--- a/titivillus/jinja2.py
+++ b/titivillus/jinja2.py
@@ -3,8 +3,8 @@
Custom Jinja2 environment.
"""
import jinja2
+from user_messages import api
from django.urls import reverse
-from django.contrib import messages
from django.utils.timezone import template_localtime
from django.contrib.staticfiles.storage import staticfiles_storage
@@ -21,7 +21,7 @@ def environment(**options):
'url': reverse,
'static': staticfiles_storage.url,
- 'get_messages': messages.get_messages,
+ 'get_messages': api.get_messages,
'localtime': template_localtime,
})
return env
diff --git a/titivillus/settings.py b/titivillus/settings.py
index 950493a..20b7cd3 100644
--- a/titivillus/settings.py
+++ b/titivillus/settings.py
@@ -34,6 +34,7 @@ INSTALLED_APPS = [
'django.contrib.postgres',
'channels',
'taggit',
+ 'user_messages',
'user.apps.UserConfig',
'homepage.apps.HomepageConfig',
'quest.apps.QuestConfig',
@@ -73,7 +74,8 @@ TEMPLATES = [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
- 'django.contrib.messages.context_processors.messages',
+ #'django.contrib.messages.context_processors.messages',
+ 'user_messages.context_processors.messages',
],
},
},
diff --git a/user/migrations/0003_user_subscriptions.py b/user/migrations/0003_user_subscriptions.py
new file mode 100644
index 0000000..1bc400b
--- /dev/null
+++ b/user/migrations/0003_user_subscriptions.py
@@ -0,0 +1,19 @@
+# Generated by Django 2.1.1 on 2018-10-12 13:26
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('quest', '0010_quest_banner_url'),
+ ('user', '0002_user_anonymize'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='user',
+ name='subscriptions',
+ field=models.ManyToManyField(to='quest.Quest'),
+ ),
+ ]
diff --git a/user/models.py b/user/models.py
index e47b15e..84fc26c 100644
--- a/user/models.py
+++ b/user/models.py
@@ -9,6 +9,7 @@ from django.contrib.auth.models import AbstractUser
from django.core.validators import MinLengthValidator, MaxLengthValidator
from .validators import CharValidator
+from quest.models import Quest
class User(AbstractUser):
"""
@@ -45,6 +46,7 @@ class User(AbstractUser):
help_text="Let's be honest, your name doesn't add anything to " \
+ "the conversation."
)
+ subscriptions = models.ManyToManyField(Quest)
def get_full_name(self):
return None