mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
views: A view to dismiss notifications
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
2a8c8c42ca
commit
afe179d91d
@ -17,12 +17,12 @@
|
||||
"""
|
||||
Django URLconf file containing all urls
|
||||
"""
|
||||
from django.conf.urls import url
|
||||
|
||||
from captcha import views as cviews
|
||||
from plinth.modules.sso.views import CaptchaLoginView
|
||||
from django.conf.urls import url
|
||||
from stronghold.decorators import public
|
||||
|
||||
from plinth.modules.sso.views import CaptchaLoginView
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
@ -45,4 +45,8 @@ urlpatterns = [
|
||||
|
||||
# locked url from django-axes
|
||||
url(r'locked/$', public(CaptchaLoginView.as_view()), name='locked_out'),
|
||||
|
||||
# Notifications
|
||||
url(r'^notification/(?P<id>[a-z0-9-]+)/dismiss/$',
|
||||
views.notification_dismiss, name='notification_dismiss')
|
||||
]
|
||||
|
||||
@ -22,6 +22,7 @@ import time
|
||||
|
||||
from django.contrib import messages
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.http import Http404, HttpResponseRedirect
|
||||
from django.template.response import TemplateResponse
|
||||
from django.urls import reverse
|
||||
from django.utils.http import is_safe_url
|
||||
@ -41,6 +42,16 @@ from . import forms, frontpage
|
||||
REDIRECT_FIELD_NAME = 'next'
|
||||
|
||||
|
||||
def _get_redirect_url_from_param(request):
|
||||
"""Return the redirect URL from 'next' GET/POST param."""
|
||||
redirect_to = request.GET.get(REDIRECT_FIELD_NAME, '')
|
||||
redirect_to = request.POST.get(REDIRECT_FIELD_NAME, redirect_to)
|
||||
if is_safe_url(url=redirect_to, allowed_hosts={request.get_host()}):
|
||||
return redirect_to
|
||||
|
||||
return reverse('index')
|
||||
|
||||
|
||||
@public
|
||||
def index(request):
|
||||
"""Serve the main index page."""
|
||||
@ -100,13 +111,7 @@ class LanguageSelectionView(FormView):
|
||||
|
||||
def get_success_url(self):
|
||||
"""Return the URL in the next parameter or home page."""
|
||||
redirect_to = self.request.GET.get(REDIRECT_FIELD_NAME, '')
|
||||
redirect_to = self.request.POST.get(REDIRECT_FIELD_NAME, redirect_to)
|
||||
if is_safe_url(url=redirect_to,
|
||||
allowed_hosts={self.request.get_host()}):
|
||||
return redirect_to
|
||||
|
||||
return reverse('index')
|
||||
return _get_redirect_url_from_param(self.request)
|
||||
|
||||
|
||||
class AppView(FormView):
|
||||
@ -254,3 +259,15 @@ class SetupView(TemplateView):
|
||||
return self.render_to_response(self.get_context_data())
|
||||
|
||||
return super(SetupView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
def notification_dismiss(request, id):
|
||||
"""Dismiss a notification."""
|
||||
from .notification import Notification
|
||||
notes = Notification.list(key=id, user=request.user)
|
||||
if not notes:
|
||||
raise Http404
|
||||
|
||||
notes[0].dismiss()
|
||||
|
||||
return HttpResponseRedirect(_get_redirect_url_from_param(request))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user