views.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from django.shortcuts import get_object_or_404
  4. from django.views.generic.edit import UpdateView
  5. from django.conf import settings
  6. from django.contrib.messages.views import SuccessMessageMixin
  7. from django.contrib.auth.decorators import login_required
  8. from django.utils.decorators import method_decorator
  9. from coin.members.models import Member
  10. from .models import HousingConfiguration
  11. class HousingView(SuccessMessageMixin, UpdateView):
  12. model = HousingConfiguration
  13. fields = ['ipv4_endpoint', 'ipv6_endpoint', 'comment']
  14. success_message = "Configuration enregistrée avec succès !"
  15. @method_decorator(login_required)
  16. def dispatch(self, *args, **kwargs):
  17. return super(HousingView, self).dispatch(*args, **kwargs)
  18. def get_form(self, form_class=None):
  19. return None
  20. def get_object(self):
  21. if self.request.user.is_superuser:
  22. return get_object_or_404(HousingConfiguration, pk=self.kwargs.get("pk"))
  23. # For normal users, ensure the Housing belongs to them.
  24. return get_object_or_404(HousingConfiguration, pk=self.kwargs.get("pk"),
  25. offersubscription__member=self.request.user)