67 lines
2.2 KiB
Python
67 lines
2.2 KiB
Python
from django.shortcuts import render
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from django.views.generic import CreateView, ListView, UpdateView, DetailView, DeleteView
|
|
from .models import QuickLinks
|
|
from .forms import QlAddQlForm
|
|
from django.contrib import messages
|
|
|
|
# Create your views here.
|
|
class QlManagement(LoginRequiredMixin, ListView):
|
|
model = QuickLinks
|
|
|
|
# Adding active_link
|
|
# Loading only user same agency
|
|
# Change context and return for template-data
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
quicklinks = QuickLinks.objects.filter(agency__pk=self.request.user.profile.agency.pk).order_by('name')
|
|
context.update({'active_link' : 'quicklinks', 'quicklinks' : quicklinks})
|
|
return context
|
|
|
|
class QlAdd(LoginRequiredMixin, CreateView):
|
|
model = QuickLinks
|
|
success_url = '/ql'
|
|
form_class = QlAddQlForm
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
context.update({'active_link' : 'quicklinks'})
|
|
return context
|
|
|
|
def form_valid(self, form):
|
|
# Send message to the site
|
|
messages.success(self.request, f'Quicklink angelegt!')
|
|
# SAVE OBJECTS TO SIGNALE!
|
|
form.instance.agency = self.request.user.profile.agency
|
|
return super().form_valid(form)
|
|
|
|
class QlDeleteView(LoginRequiredMixin, DeleteView):
|
|
model = QuickLinks
|
|
success_url = '/ql'
|
|
template_name = 'quicklinks/ql_confirm_delete.html'
|
|
|
|
def delete(self, request, *args, **kwargs):
|
|
response = super(QlDeleteView, self).delete(request, *args, **kwargs)
|
|
messages.success(request, f'Quicklink wurde gelöscht!')
|
|
return response
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(QlDeleteView, self).get_context_data(**kwargs)
|
|
context['active_link'] = 'quicklinks'
|
|
return context
|
|
|
|
class QlUpdateView(LoginRequiredMixin, UpdateView):
|
|
model = QuickLinks
|
|
template_name = 'quicklinks/ql_update.html'
|
|
success_url = '/ql'
|
|
form_class = QlAddQlForm
|
|
|
|
def form_valid(self, form):
|
|
# Send message to the site
|
|
messages.success(self.request, f'Quicklink aktualisiert!')
|
|
return super().form_valid(form)
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(QlUpdateView, self).get_context_data(**kwargs)
|
|
context['active_link'] = 'quicklinks'
|
|
return context |