devicehub-django/user/views.py

40 lines
1.2 KiB
Python
Raw Normal View History

from django.http import HttpResponse
from django.shortcuts import render
2024-10-10 08:35:27 +00:00
from django.utils.translation import gettext_lazy as _
from django.views.generic.base import TemplateView
from dashboard.mixins import DashboardView
from django.views.generic.edit import (
FormView,
)
from user.forms import SettingsForm
from api.models import Token
2024-06-12 07:32:49 +00:00
2024-10-10 08:35:27 +00:00
class PanelView(DashboardView, TemplateView):
template_name = "panel.html"
title = _("User")
breadcrumb = "User / Panel"
subtitle = "User panel"
class SettingsView(DashboardView, FormView):
template_name = "settings.html"
title = _("Download Settings")
breadcrumb = "user / workbench / settings"
form_class = SettingsForm
def form_valid(self, form):
form.devices = self.get_session_devices()
data = render(self.request, "settings.ini", form.cleaned_data)
response = HttpResponse(data.content, content_type="application/text")
response['Content-Disposition'] = 'attachment; filename={}'.format("settings.ini")
return response
def get_form_kwargs(self):
tokens = Token.objects.filter(owner=self.request.user)
kwargs = super().get_form_kwargs()
kwargs['tokens'] = tokens
return kwargs