start taking more advantage of class based views
This commit is contained in:
+24
-1
@@ -8,6 +8,29 @@ class SuperuserRequiredMixin(UserPassesTestMixin):
|
||||
def test_func(self):
|
||||
return self.request.user.is_superuser
|
||||
|
||||
class CheckCanEditMixin():
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
print(self.object)
|
||||
print("1234", self.object.check_user_can_edit(self.request.user))
|
||||
context["can_edit"] = self.object.check_user_can_edit(self.request.user)
|
||||
|
||||
return context
|
||||
|
||||
|
||||
|
||||
class QuestionMixin():
|
||||
|
||||
def get_app_name(self):
|
||||
raise NotImplementedError("You must implement get_app_name in the derived class")
|
||||
|
||||
def get_base_template(self):
|
||||
return f"{self.get_app_name()}/base.html"
|
||||
|
||||
def get_link_headers(self):
|
||||
return f"{self.get_app_name()}/question_link_header.html"
|
||||
|
||||
class AuthorMixin():
|
||||
"""Mixin class for models that have authors
|
||||
|
||||
@@ -15,7 +38,7 @@ class AuthorMixin():
|
||||
|
||||
"""
|
||||
author = models.ManyToManyField(User) # Corrected typing
|
||||
|
||||
|
||||
def get_author_objects(self) -> List[User]: # Updated type hint
|
||||
"""Returns list of author objects"""
|
||||
authors = [i for i in self.author.all()]
|
||||
|
||||
Reference in New Issue
Block a user