ftp_deploy.server.views.notification: 38 total statements, 100.0% covered

Generated: Sun 2014-03-16 19:26 GMT

Source file: /var/www/service.dev/service/ftp_deploy/server/views/notification.py

Stats: 32 executed, 0 missed, 6 excluded, 24 ignored

  1. from django.views.generic import ListView, UpdateView, DeleteView, DetailView, CreateView
  2. from django.core.urlresolvers import reverse_lazy, reverse
  3. from django.contrib import messages
  4. from braces.views import JSONResponseMixin, LoginRequiredMixin
  5. from ftp_deploy.models import Notification
  6. from ftp_deploy.server.forms import NotificationForm
  7. class NotificationView(LoginRequiredMixin, ListView):
  8. model = Notification
  9. template_name = 'ftp_deploy/notification/notification.html'
  10. context_object_name = 'notifications'
  11. class NotificationAddView(LoginRequiredMixin, CreateView):
  12. """View for add notifications"""
  13. model = Notification
  14. form_class = NotificationForm
  15. success_url = reverse_lazy('ftpdeploy_notification')
  16. template_name = "ftp_deploy/notification/form.html"
  17. def form_valid(self, form):
  18. messages.add_message(self.request, messages.SUCCESS, 'Notification has been added.')
  19. return super(NotificationAddView, self).form_valid(form)
  20. class NotificationEditView(LoginRequiredMixin, UpdateView):
  21. """View for edit notifications"""
  22. model = Notification
  23. form_class = NotificationForm
  24. success_url = reverse_lazy('ftpdeploy_notification')
  25. template_name = "ftp_deploy/notification/form.html"
  26. def get_context_data(self, **kwargs):
  27. context = super(NotificationEditView, self).get_context_data(**kwargs)
  28. emails = self.get_object().get_email_list()
  29. context['emails'] = emails
  30. return context
  31. def form_valid(self, form):
  32. messages.add_message(self.request, messages.SUCCESS, 'Notification has been updated.')
  33. return super(NotificationEditView, self).form_valid(form)
  34. class NotificationDeleteView(LoginRequiredMixin, DeleteView):
  35. """View for delete services"""
  36. model = Notification
  37. success_url = reverse_lazy('ftpdeploy_notification')
  38. template_name = "ftp_deploy/notification/delete.html"
  39. def delete(self, request, *args, **kwargs):
  40. messages.add_message(request, messages.SUCCESS, 'Notification has been removed.')
  41. return super(NotificationDeleteView, self).delete(request, *args, **kwargs)