You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.2 KiB

2 years ago
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.views import LoginView
from django.shortcuts import get_object_or_404
from django.urls import reverse_lazy
2 years ago
from django.views.generic import (CreateView, DeleteView, ListView,
RedirectView, TemplateView, UpdateView)
from django_scopes import scope, scopes_disabled
2 years ago
from scopedsites.models import Domain
from leftists.forms import LinkForm
from leftists.models import ShortLink
class ShortLinkRedirectView(RedirectView):
def get_redirect_url(self, *args, **kwargs):
sl = get_object_or_404(ShortLink, location=kwargs.get('link'))
sl.click()
return sl.to
class CoolerLoginView(LoginView):
redirect_authenticated_user = True
next_page = reverse_lazy('interface.overview')
class OverView(LoginRequiredMixin, TemplateView):
template_name = 'interface/overview.html'
def get_context_data(self, **kwargs):
with scopes_disabled():
ctx = super().get_context_data(**kwargs)
ds = Domain.objects.all()
ctx.setdefault('domains', ds)
links = []
for d in ds:
[links.append(l) for l in d.links.all()]
ctx.setdefault('links', links)
return ctx
2 years ago
class LinkListView(LoginRequiredMixin, ListView):
template_name = 'interface/linkedlist.html'
model = ShortLink
def get(self, request, *args, **kwargs):
with scopes_disabled():
d = Domain.objects.get(fqdn__contains=kwargs.get('domain'))
with scope(domain=d):
return super().get(request, *args, **kwargs)
2 years ago
class LinkCreateView(LoginRequiredMixin, CreateView):
template_name = 'interface/create_link.html'
2 years ago
model = ShortLink
form_class = LinkForm
success_url = reverse_lazy('interface.overview')
class LinkUpdateView(LoginRequiredMixin, UpdateView):
template_name = 'interface/basic_form.html'
model = ShortLink
form_class = LinkForm
success_url = reverse_lazy('interface.overview')
class LinkDeleteView(LoginRequiredMixin, DeleteView):
template_name = 'interface/delete_link.html'
model = ShortLink
success_url = reverse_lazy('interface.overview')