ticket_list_create.py 892 B

123456789101112131415161718192021
  1. from django.contrib.auth.mixins import LoginRequiredMixin
  2. from django.contrib import messages
  3. from django.urls import reverse_lazy
  4. from django.shortcuts import redirect
  5. from django.views import View
  6. from tickets.forms import TicketListForm
  7. from tickets.utils import SuperuserStaffRequiredMixin
  8. class TicketListCreateView(LoginRequiredMixin, SuperuserStaffRequiredMixin, View):
  9. def post(self, request):
  10. form = TicketListForm(request.user, request.POST)
  11. if form.is_valid():
  12. new_ticket_list = form.save()
  13. messages.success(self.request, f'The "{new_ticket_list.name}" list has been successfully created in {new_ticket_list.group}.')
  14. else:
  15. messages.error(self.request, "Failed to create the list. Maybe you specified an already existing list name in the group?")
  16. return redirect(reverse_lazy('tickets:ticket_list_list'))