Skip to content

Commit 99c20cc

Browse files
committed
Améliore _get_sha (mixin + typage)
1 parent 288f104 commit 99c20cc

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

zds/tutorialv2/views/display/shared_content.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,17 @@ def __init__(self, user, content: PublishableContent, versioned_content: Version
2323
self.validation_actions.enabled = False
2424

2525

26-
class ContentSharedView(ContentBaseView):
26+
class GetShaMixin:
27+
def _get_sha(self) -> str | None:
28+
if self.link.type == "DRAFT":
29+
return self.content.sha_draft
30+
elif self.link.type == "BETA" and self.content.in_beta():
31+
return self.content.sha_beta
32+
else:
33+
return None
34+
35+
36+
class ContentSharedView(GetShaMixin, ContentBaseView):
2737
must_be_author = False
2838
authorized_for_all = True
2939
sha = None
@@ -56,16 +66,8 @@ def get_base_url(self):
5666
url = reverse("content:shareable-link-view", kwargs=route_parameters)
5767
return url
5868

59-
def _get_sha(self):
60-
if self.link.type == "DRAFT":
61-
return self.content.sha_draft
62-
elif self.link.type == "BETA" and self.content.in_beta():
63-
return self.content.sha_beta
64-
else:
65-
return None
66-
6769

68-
class ContainerSharedView(ContainerBaseView):
70+
class ContainerSharedView(GetShaMixin, ContainerBaseView):
6971
must_be_author = False
7072
authorized_for_all = True
7173

@@ -91,11 +93,3 @@ def get_base_url(self):
9193
route_parameters = {"id": self.link.id}
9294
url = reverse("content:shareable-link-view", kwargs=route_parameters)
9395
return url
94-
95-
def _get_sha(self):
96-
if self.link.type == "DRAFT":
97-
return self.content.sha_draft
98-
elif self.link.type == "BETA" and self.content.in_beta():
99-
return self.content.sha_beta
100-
else:
101-
return None

0 commit comments

Comments
 (0)