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.
59 lines
1.8 KiB
59 lines
1.8 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 RedirectView, TemplateView, CreateView, UpdateView, DeleteView |
|
from django_scopes import scopes_disabled |
|
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 |
|
|
|
|
|
class LinkCreateView(LoginRequiredMixin, CreateView): |
|
template_name = 'interface/basic_form.html' |
|
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') |
|
|
|
|
|
|