2024-10-11 11:46:21 +00:00
|
|
|
from decouple import config
|
2024-10-14 09:34:52 +00:00
|
|
|
from django.urls import reverse, reverse_lazy
|
2024-10-11 11:04:37 +00:00
|
|
|
from django.http import HttpResponse
|
2024-06-12 07:32:49 +00:00
|
|
|
from django.shortcuts import render
|
2024-09-18 16:01:46 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2024-10-10 08:35:27 +00:00
|
|
|
from django.views.generic.base import TemplateView
|
2024-09-25 10:51:08 +00:00
|
|
|
from dashboard.mixins import DashboardView
|
2024-10-11 11:04:37 +00:00
|
|
|
from django.views.generic.edit import (
|
|
|
|
FormView,
|
|
|
|
)
|
2024-09-18 16:01:46 +00:00
|
|
|
|
2024-10-11 11:04:37 +00:00
|
|
|
from user.forms import SettingsForm
|
|
|
|
from api.models import Token
|
2024-09-18 16:01:46 +00:00
|
|
|
|
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"
|
2024-10-11 11:04:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SettingsView(DashboardView, FormView):
|
|
|
|
template_name = "settings.html"
|
|
|
|
title = _("Download Settings")
|
|
|
|
breadcrumb = "user / workbench / settings"
|
|
|
|
form_class = SettingsForm
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
2024-10-11 11:46:21 +00:00
|
|
|
cleaned_data = form.cleaned_data.copy()
|
|
|
|
settings_tmpl = "settings.ini"
|
|
|
|
path = reverse("api:new_snapshot")
|
|
|
|
cleaned_data['url'] = self.request.build_absolute_uri(path)
|
|
|
|
|
|
|
|
if config("LEGACY", False):
|
|
|
|
cleaned_data['token'] = config.get('TOKEN_LEGACY', '')
|
|
|
|
cleaned_data['url'] = config.get('URL_LEGACY', '')
|
|
|
|
settings_tmpl = "settings_legacy.ini"
|
|
|
|
|
|
|
|
data = render(self.request, settings_tmpl, cleaned_data)
|
2024-10-11 11:04:37 +00:00
|
|
|
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
|
|
|
|
|