40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
from django.http import HttpResponse
|
|
from django.shortcuts import render
|
|
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
|
|
|
|
|
|
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
|
|
|