Added a basic notification system. Long processes will call the notification API, and the notification events are registered. For now, notifications are pushed to the client by polling (client polls every second for new events). A basic status message is now displayed when the sync process starts and ends.

This commit is contained in:
2018-11-04 23:32:18 +02:00
parent 7a87ad648a
commit 57c2265f71
9 changed files with 205 additions and 2 deletions

View File

@ -13,6 +13,7 @@ from YtManagerApp.management.videos import get_videos
from YtManagerApp.models import Subscription, SubscriptionFolder, VIDEO_ORDER_CHOICES, VIDEO_ORDER_MAPPING
from YtManagerApp.utils import youtube
from YtManagerApp.views.controls.modal import ModalMixin
from YtManagerApp.management.notification_manager import get_current_notification_id
class VideoFilterForm(forms.Form):
@ -94,7 +95,8 @@ def __tree_sub_id(sub_id):
def index(request: HttpRequest):
if request.user.is_authenticated:
context = {
'filter_form': VideoFilterForm()
'filter_form': VideoFilterForm(),
'current_notification_id': get_current_notification_id(),
}
return render(request, 'YtManagerApp/index.html', context)
else:

View File

@ -0,0 +1,12 @@
from django.contrib.auth.decorators import login_required
from django.http import HttpRequest, JsonResponse
from YtManagerApp.management.notification_manager import get_notifications
@login_required
def ajax_get_notifications(request: HttpRequest, last_id: int):
user = request.user
notifications = get_notifications(user, last_id)
notifications = list(notifications)
return JsonResponse(notifications, safe=False)