bornhack-website/src/villages/mixins.py
Thomas Steen Rasmussen 00af109e2f
add flake8 and isort to pre-commit config, make flake8 and isort happy (#441)
* add flake8 to pre-commit config, and fixup many things to make flake8 happy

* add isort and sort all imports, add to pre-commit and requirements
2020-02-12 13:10:41 +01:00

18 lines
629 B
Python

from django.contrib import messages
from django.shortcuts import redirect
from django.urls import reverse
from django.views.generic.detail import SingleObjectMixin
class EnsureWritableCampMixin(SingleObjectMixin):
def dispatch(self, request, *args, **kwargs):
# do not permit view if camp is in readonly mode
if self.camp.read_only:
messages.error(request, "No thanks")
return redirect(
reverse("village_list", kwargs={"camp_slug": self.camp.slug})
)
# alright, continue with the request
return super().dispatch(request, *args, **kwargs)