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.

63 lines
1.9 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)
2 years ago
from leftists.forms import LinkForm
from leftists.models import ShortLink, Domain
2 years ago
class ShortLinkRedirectView(RedirectView):
def get_redirect_url(self, *args, **kwargs):
return ShortLink.hit(self.request, kwargs.get("link"))
2 years ago
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):
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_queryset(self):
d = Domain.get_from_request(self.request)
return ShortLink.objects.filter(domain=d)
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')