def index(request: HttpRequest): menu = apps['ui.menu'] menu_items = menu.search_visible_items(request) menu_id = menu_items[0] context = { 'current_menu': menu_id, 'root_menu': menu_items, } if settings.USE_I18N: from .i18n import javascript_catalog context['i18n_js_catalog'] = javascript_catalog( request, packages=apps.addons.keys()) return render(request, '/web/index.jinja2', context)
def index(request: HttpRequest, template_name='/admin/index.jinja2', **context): menu_items = json.dumps(apps['ui.menu'].search_visible_items(request)) context.update({ 'menu': menu_items, 'user_info': json.dumps(request.user.user_info()), 'settings': settings, }) if settings.USE_I18N: from .i18n import javascript_catalog context['i18n_js_catalog'] = javascript_catalog( request, packages=apps.addons.keys()) return render(request, template_name, context)
def login(request: HttpRequest, **kwargs): if request.method == 'POST': if request.is_json(): data = request.json else: data = request.POST username = data['username'] password = data['password'] next_url = data.get( 'next', request.GET.get('next', kwargs.get('next', '/web/'))) # check if db exists u = auth.authenticate(username=username, password=password) if u and u.is_authenticated: auth.login(request, u) if request.is_json(): return JsonResponse({ 'ok': True, 'user_id': u.id, 'redirect': next_url, 'message': gettext('Login successful, please wait...'), }) return HttpResponseRedirect(next_url) if request.is_json(): return JsonResponse({ 'error': True, 'message': gettext('Invalid username and password.'), }) messages.error(request, gettext('Invalid username and password.')) from .i18n import javascript_catalog context = { 'i18n_js_catalog': javascript_catalog(request, packages=apps.addons.keys()), 'settings': settings, } return render(request, 'admin/login.jinja2', context, using=request.COOKIES.get('db'))
def manifest_json(request, template_name='pwa/manifest.json'): return render(request, template_name, content_type='text/json')
def service_worker_js(request, template_name='pwa/service-worker.js'): return render(request, template_name, content_type='application/javascript')