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.
62 lines
1.9 KiB
62 lines
1.9 KiB
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 |
|
from django.views.generic import (CreateView, DeleteView, ListView, |
|
RedirectView, TemplateView, UpdateView) |
|
|
|
from leftists.forms import LinkForm |
|
from leftists.models import ShortLink, Domain |
|
|
|
|
|
class ShortLinkRedirectView(RedirectView): |
|
def get_redirect_url(self, *args, **kwargs): |
|
return ShortLink.hit(self.request, kwargs.get("link")) |
|
|
|
|
|
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 |
|
|
|
|
|
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) |
|
|
|
|
|
class LinkCreateView(LoginRequiredMixin, CreateView): |
|
template_name = 'interface/create_link.html' |
|
model = ShortLink |
|
form_class = LinkForm |
|
success_url = reverse_lazy('interface.overview') |
|
|
|
|
|
class LinkUpdateView(LoginRequiredMixin, UpdateView): |
|
template_name = 'interface/create_link.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')
|
|
|