jumpserver/apps/common/views/msg.py

42 lines
1.5 KiB
Python
Raw Permalink Normal View History

#
from django.http import HttpResponse
from django.utils.decorators import method_decorator
2024-12-19 07:16:18 +00:00
from django.utils.translation import gettext_lazy as _
from django.views.decorators.cache import never_cache
from django.views.generic.base import TemplateView
from common.utils import bulk_get, FlashMessageUtil
@method_decorator(never_cache, name='dispatch')
class FlashMessageMsgView(TemplateView):
template_name = 'flash_message_standalone.html'
def get(self, request, *args, **kwargs):
code = request.GET.get('code')
if not code:
2024-12-19 07:16:18 +00:00
return HttpResponse(_('Not found the code'))
message_data = FlashMessageUtil.get_message_by_code(code)
if not message_data:
2024-12-19 07:16:18 +00:00
return HttpResponse(_('The message code provided is invalid or has expired'))
items = ('title', 'message', 'error', 'redirect_url', 'confirm_button', 'cancel_url')
title, msg, error, redirect_url, confirm_btn, cancel_url = bulk_get(message_data, items)
interval = message_data.get('interval', 3)
auto_redirect = message_data.get('auto_redirect', True)
has_cancel = message_data.get('has_cancel', False)
context = {
'title': title,
'message': msg,
'error': error,
'interval': interval,
'redirect_url': redirect_url,
'auto_redirect': auto_redirect,
'confirm_button': confirm_btn,
'has_cancel': has_cancel,
'cancel_url': cancel_url,
}
return self.render_to_response(context)