frontend of subscription system started

This commit is contained in:
iou1name 2018-10-12 13:54:58 -04:00
parent 7dd1c9bf30
commit f58b0c0a04
5 changed files with 19 additions and 4 deletions

View File

@ -17,6 +17,10 @@
<div id="header" class="header" style="{% if request.session.get("hide_header") == True %}display:none;{% else %}display:flex;{% endif %}">
<span><a onclick="toggle_header();" href="javascript:void(0);"></a></span>
<span><a href="{{ url('homepage:index') }}">Home</a></span>
{% if request.user.is_authenticated %}
<span id="profileLink"><a href="{{ url('user:profile', args=[request.user.id]) }}">{{ request.user.username }}</a></span>
<span id="subscriptions">{{ get_sub_msgs(request=request)|length }}</span>
{% endif %}
{% block header %}{% endblock %}
</div>
<div id="headerHidden" class="header" style="{% if request.session.get("hide_header") == True %}display:flex;{% else %}display:none;{% endif %}">

View File

@ -24,8 +24,5 @@
Live in: <span id="liveCountdown"></span> (<span id="liveTime">{% if quest.live_time %}{{ localtime(quest.live_time).strftime('%Y-%m-%d %H:%M') }}{% endif %}</span>)
</span>
<span id="space"></span>
{% if request.user.is_authenticated %}
<span id="profileLink"><a href="{{ url('user:profile', args=[request.user.id]) }}">{{ request.user.username }}</a></span>
{% endif %}
<span id="toggleChat"><a onclick="toggle_chat()" href="javascript:void(0);">{% if request.session.get("hide_chat") == True %}←{% else %}→{% endif %}</a></span>

View File

@ -40,7 +40,7 @@
{% if request.user.is_authenticated %}
<form id="subscribe" method="post" action="{{ url('quest:subscribe', kwargs={'quest_id': quest_id}) }}">
{{ csrf_input }}
<a onclick="document.getElementById('subscribe').submit()">Subscribe</a>
<a href="javascript:void(0);" onclick="document.getElementById('subscribe').submit()">Subscribe</a>
</form>
{% endif %}
<h3>Pages</h3>

View File

@ -55,6 +55,10 @@ a:hover {
padding-left: 0;
}
#subscriptions {
background-color: orange;
}
#headerHidden {
width: 1em;
border-right: 1px solid #ccc;

View File

@ -8,6 +8,15 @@ from django.urls import reverse
from django.utils.timezone import template_localtime
from django.contrib.staticfiles.storage import staticfiles_storage
def get_sub_msgs(**kwargs):
"""Returns all messages 'subscription' in the tag."""
messages = api.get_messages(**kwargs)
sub_msgs = []
for message in messages:
if 'subscription' in message.tags:
sub_msgs.append(messages)
return sub_msgs
def environment(**options):
"""
Custom Jinja2 environment.
@ -23,5 +32,6 @@ def environment(**options):
'static': staticfiles_storage.url,
'get_messages': api.get_messages,
'localtime': template_localtime,
'get_sub_msgs': get_sub_msgs,
})
return env