Revert "Merge branch 'notifications_refresh' into 'master'"

This reverts merge request !1215
This commit is contained in:
Ariel Rin 2020-06-04 11:21:50 +00:00
parent 3a984e8a4d
commit ae3f5a0f62
6 changed files with 12 additions and 63 deletions

View File

@ -1,4 +1,5 @@
from django.conf.urls import url from django.conf.urls import url
from django.contrib.auth.decorators import login_required
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from . import views from . import views
@ -23,9 +24,4 @@ urlpatterns = [
name='add_character' name='add_character'
), ),
url(r'^dashboard/$', views.dashboard, name='dashboard'), url(r'^dashboard/$', views.dashboard, name='dashboard'),
url(
r'^notifications_render/$',
views.notifications_render,
name='notifications_render'
),
] ]

View File

@ -6,13 +6,11 @@ from django.contrib.auth import login, authenticate
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core import signing from django.core import signing
from django.http import HttpResponse
from django.shortcuts import redirect, render
from django.urls import reverse from django.urls import reverse
from django.shortcuts import redirect, render
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from allianceauth.eveonline.models import EveCharacter from allianceauth.eveonline.models import EveCharacter
from esi.decorators import token_required from esi.decorators import token_required
from esi.models import Token from esi.models import Token
@ -61,14 +59,6 @@ def dashboard(request):
return render(request, 'authentication/dashboard.html', context) return render(request, 'authentication/dashboard.html', context)
@login_required
def notifications_render(request):
"""returns html to render the notifications item in the top menu"""
unread_count = request.user.notification_set.filter(viewed=False).count()
context = {'notifications': unread_count}
return render(request, 'allianceauth/notifications_menu_item.html', context)
@login_required @login_required
@token_required(scopes=settings.LOGIN_TOKEN_SCOPES) @token_required(scopes=settings.LOGIN_TOKEN_SCOPES)
def main_character_change(request, token): def main_character_change(request, token):

View File

@ -1,27 +0,0 @@
/*
Javascript for the base template
*/
$(function() {
var elem = document.getElementById("dataExport");
var notificationsRenderUrl = elem.getAttribute("data-notificationsRenderUrl");
// render the notifications item in the top menu
function render_notifications(){
$("#menu_item_notifications").load(
notificationsRenderUrl,
function(responseTxt, statusTxt, xhr){
if(statusTxt == "error")
console.log(
"Failed to load HTMl to render notifications item. Error: "
+ xhr.status
+ ": "
+ xhr.statusText
);
});
}
render_notifications()
// re-render notifications every x seconds
setInterval(render_notifications, 5000);
});

View File

@ -45,7 +45,6 @@
{% endif %} {% endif %}
{% include 'bundles/bootstrap-js.html' %} {% include 'bundles/bootstrap-js.html' %}
{% block extra_javascript %} {% block extra_javascript %}
<script src="{% static 'js/base.js' %}"></script>
{% endblock extra_javascript %} {% endblock extra_javascript %}
<script> <script>
{% block extra_script %} {% block extra_script %}

View File

@ -1,9 +0,0 @@
{% if notifications %}
<a href="{% url 'notifications:list' %}">Notifications
<span class="badge">{{ notifications }}</span>
</a>
{% else %}
<a href="{% url 'notifications:list' %}">
<i class="fa fa-bell-o"></i>
</a>
{% endif %}

View File

@ -20,11 +20,17 @@
<li> <li>
{% include 'allianceauth/night-toggle.html' %} {% include 'allianceauth/night-toggle.html' %}
</li> </li>
<li {% if notifications %}
class="{% navactive request 'notifications:' %}" id="menu_item_notifications" <li class="{% navactive request 'notifications:' %}">
> <a href="{% url 'notifications:list' %}">Notifications
{% include 'allianceauth/notifications_menu_item.html' %} <span class="badge">{{ notifications }}</span>
</a>
</li> </li>
{% else %}
<li><a href="{% url 'notifications:list' %}">
<i class="fa fa-bell-o"></i></a>
</li>
{% endif %}
{% if user.is_authenticated %} {% if user.is_authenticated %}
{% if user.is_staff %} {% if user.is_staff %}
<li><a href="{% url 'admin:index' %}">{% trans "Admin" %}</a></li> <li><a href="{% url 'admin:index' %}">{% trans "Admin" %}</a></li>
@ -58,9 +64,3 @@
</div> </div>
</div> </div>
</nav> </nav>
<!-- share data with JS part -->
<div
id="dataExport"
data-notificationsRenderUrl="{% url 'authentication:notifications_render' %}"
>
</div>