mirror of
https://github.com/ae-utbm/sith.git
synced 2026-09-26 14:14:20 +00:00
make CGU a Page instead of a File
This commit is contained in:
@@ -25,6 +25,7 @@ from io import StringIO
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import ClassVar, NamedTuple
|
from typing import ClassVar, NamedTuple
|
||||||
|
|
||||||
|
import itertools
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import Permission
|
from django.contrib.auth.models import Permission
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
@@ -125,18 +126,6 @@ class Command(BaseCommand):
|
|||||||
sas = SithFile.objects.create(
|
sas = SithFile.objects.create(
|
||||||
name="SAS", owner=root, id=settings.SITH_SAS_ROOT_DIR_ID
|
name="SAS", owner=root, id=settings.SITH_SAS_ROOT_DIR_ID
|
||||||
)
|
)
|
||||||
s = SithFile.objects.create(
|
|
||||||
name="CGU",
|
|
||||||
is_folder=False,
|
|
||||||
file=ContentFile(
|
|
||||||
content="Conditions générales d'utilisation", name="cgu.txt"
|
|
||||||
),
|
|
||||||
owner=root,
|
|
||||||
)
|
|
||||||
s.view_groups.add(settings.SITH_GROUP_PUBLIC_ID)
|
|
||||||
# Page needed for club creation
|
|
||||||
p = Page(name=settings.SITH_CLUB_ROOT_PAGE)
|
|
||||||
p.save(force_lock=True)
|
|
||||||
clubs = self._create_clubs()
|
clubs = self._create_clubs()
|
||||||
|
|
||||||
self.reset_index("club")
|
self.reset_index("club")
|
||||||
@@ -287,34 +276,7 @@ class Command(BaseCommand):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Adding syntax help page
|
self._create_pages(groups)
|
||||||
syntax_page = Page(name="Aide_sur_la_syntaxe")
|
|
||||||
syntax_page.save(force_lock=True)
|
|
||||||
PageRev.objects.create(
|
|
||||||
page=syntax_page,
|
|
||||||
title="Aide sur la syntaxe",
|
|
||||||
author=skia,
|
|
||||||
content=(self.ROOT_PATH / "core" / "fixtures" / "SYNTAX.md").read_text(),
|
|
||||||
)
|
|
||||||
services_page = Page(name="Services")
|
|
||||||
services_page.save(force_lock=True)
|
|
||||||
PageRev.objects.create(
|
|
||||||
page=services_page,
|
|
||||||
title="Services",
|
|
||||||
author=skia,
|
|
||||||
content="- [Eboutic](/eboutic)\n- Matmat\n- SAS\n- Weekmail\n- Forum",
|
|
||||||
)
|
|
||||||
|
|
||||||
index_page = Page(name="Index")
|
|
||||||
index_page.save(force_lock=True)
|
|
||||||
PageRev.objects.create(
|
|
||||||
page=index_page,
|
|
||||||
title="Wiki index",
|
|
||||||
author=root,
|
|
||||||
content="Welcome to the wiki page!",
|
|
||||||
)
|
|
||||||
|
|
||||||
groups.public.viewable_page.set([syntax_page, services_page, index_page])
|
|
||||||
|
|
||||||
self._create_subscription(root)
|
self._create_subscription(root)
|
||||||
self._create_subscription(skia)
|
self._create_subscription(skia)
|
||||||
@@ -585,6 +547,48 @@ class Command(BaseCommand):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _create_pages(self, groups: PopulatedGroups):
|
||||||
|
pages = Page.objects.bulk_create(
|
||||||
|
[Page(name=s, _full_name=s) for s in settings.SITH_CGU_PAGE.split("/")]
|
||||||
|
)
|
||||||
|
for parent, son in itertools.pairwise(pages):
|
||||||
|
son.parent = parent
|
||||||
|
son.save(force_lock=True)
|
||||||
|
cgu_page = pages[-1]
|
||||||
|
|
||||||
|
syntax_page = Page(name="Aide_sur_la_syntaxe")
|
||||||
|
syntax_page.save(force_lock=True)
|
||||||
|
services_page = Page(name="Services")
|
||||||
|
services_page.save(force_lock=True)
|
||||||
|
index_page = Page(name="Index")
|
||||||
|
index_page.save(force_lock=True)
|
||||||
|
|
||||||
|
page_revs = [
|
||||||
|
PageRev(page=cgu_page, title="Règlement informatique", content=""),
|
||||||
|
PageRev(
|
||||||
|
page=syntax_page,
|
||||||
|
title="Aide sur la syntaxe",
|
||||||
|
content=(
|
||||||
|
self.ROOT_PATH / "core" / "fixtures" / "SYNTAX.md"
|
||||||
|
).read_text(),
|
||||||
|
),
|
||||||
|
PageRev(
|
||||||
|
page=services_page,
|
||||||
|
title="Services",
|
||||||
|
content="- [Eboutic](/eboutic)\n- Matmat\n- SAS\n- Weekmail\n- Forum",
|
||||||
|
),
|
||||||
|
PageRev(
|
||||||
|
page=index_page, title="Wiki index", content="Welcome to the wiki page!"
|
||||||
|
),
|
||||||
|
]
|
||||||
|
for rev in page_revs:
|
||||||
|
rev.author_id = settings.SITH_ROOT_USER_ID
|
||||||
|
rev.revision = 1
|
||||||
|
PageRev.objects.bulk_create(page_revs)
|
||||||
|
groups.public.viewable_page.set(
|
||||||
|
[syntax_page, services_page, index_page, cgu_page]
|
||||||
|
)
|
||||||
|
|
||||||
def _create_products(self, groups: PopulatedGroups, clubs: PopulatedClubs):
|
def _create_products(self, groups: PopulatedGroups, clubs: PopulatedClubs):
|
||||||
beers_type, cotis_type, refill_type, verre_type = (
|
beers_type, cotis_type, refill_type, verre_type = (
|
||||||
ProductType.objects.bulk_create(
|
ProductType.objects.bulk_create(
|
||||||
@@ -745,6 +749,10 @@ class Command(BaseCommand):
|
|||||||
s.save()
|
s.save()
|
||||||
|
|
||||||
def _create_clubs(self) -> PopulatedClubs:
|
def _create_clubs(self) -> PopulatedClubs:
|
||||||
|
# Page needed for club creation
|
||||||
|
p = Page(name=settings.SITH_CLUB_ROOT_PAGE)
|
||||||
|
p.save(force_lock=True)
|
||||||
|
|
||||||
ae = Club.objects.create(
|
ae = Club.objects.create(
|
||||||
id=1, name="AE", address="6 Boulevard Anatole France, 90000 Belfort"
|
id=1, name="AE", address="6 Boulevard Anatole France, 90000 Belfort"
|
||||||
)
|
)
|
||||||
|
|||||||
+2
-4
@@ -1234,9 +1234,8 @@ class Page(models.Model):
|
|||||||
raise NotLocked("The page is not locked and thus can not be saved")
|
raise NotLocked("The page is not locked and thus can not be saved")
|
||||||
self.full_clean()
|
self.full_clean()
|
||||||
if not self.id:
|
if not self.id:
|
||||||
super().save(
|
# Save a first time to correctly set _full_name
|
||||||
*args, **kwargs
|
super().save(*args, **kwargs)
|
||||||
) # Save a first time to correctly set _full_name
|
|
||||||
# This reset the _full_name just before saving to maintain a coherent field quicker for queries than the
|
# This reset the _full_name just before saving to maintain a coherent field quicker for queries than the
|
||||||
# recursive method
|
# recursive method
|
||||||
# It also update all the children to maintain correct names
|
# It also update all the children to maintain correct names
|
||||||
@@ -1255,7 +1254,6 @@ class Page(models.Model):
|
|||||||
return Page.objects.filter(_full_name=name).first()
|
return Page.objects.filter(_full_name=name).first()
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""Cleans up only the name for the moment, but this can be used to make any treatment before saving the object."""
|
|
||||||
if "/" in self.name:
|
if "/" in self.name:
|
||||||
self.name = self.name.split("/")[-1]
|
self.name = self.name.split("/")[-1]
|
||||||
if (
|
if (
|
||||||
|
|||||||
+2
-2
@@ -110,7 +110,6 @@ class FutureDateTimeField(forms.DateTimeField):
|
|||||||
|
|
||||||
|
|
||||||
class CGUApprovalField(forms.BooleanField):
|
class CGUApprovalField(forms.BooleanField):
|
||||||
cgu_file_id = settings.SITH_CGU_FILE_ID
|
|
||||||
default_error_messages = {"required": _("You must approve the terms of service.")}
|
default_error_messages = {"required": _("You must approve the terms of service.")}
|
||||||
__label = None
|
__label = None
|
||||||
|
|
||||||
@@ -127,12 +126,13 @@ class CGUApprovalField(forms.BooleanField):
|
|||||||
|
|
||||||
def get_label(self):
|
def get_label(self):
|
||||||
if not self.__label:
|
if not self.__label:
|
||||||
|
url = reverse("core:page", kwargs={"page_name": settings.SITH_CGU_PAGE})
|
||||||
self.__label = mark_safe(
|
self.__label = mark_safe(
|
||||||
_(
|
_(
|
||||||
"I have read and I approve the "
|
"I have read and I approve the "
|
||||||
'<a href="%(url)s" target="_blank">Terms of Service</a>'
|
'<a href="%(url)s" target="_blank">Terms of Service</a>'
|
||||||
)
|
)
|
||||||
% {"url": reverse("core:page", kwargs={"page_name": self.cgu_file_id})}
|
% {"url": url}
|
||||||
)
|
)
|
||||||
return self.__label
|
return self.__label
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -372,6 +372,9 @@ SITH_PDF_CLUB_ID = env.int("SITH_PDF_CLUB_ID", default=2)
|
|||||||
# Main root for club pages
|
# Main root for club pages
|
||||||
SITH_CLUB_ROOT_PAGE = "clubs"
|
SITH_CLUB_ROOT_PAGE = "clubs"
|
||||||
|
|
||||||
|
SITH_CGU_PAGE = env.str("SITH_CGU_PAGE", default="legals/ri")
|
||||||
|
|
||||||
|
|
||||||
# Define the date in the year serving as
|
# Define the date in the year serving as
|
||||||
# reference for the subscriptions calendar (month, day)
|
# reference for the subscriptions calendar (month, day)
|
||||||
SITH_SEMESTER_START_AUTUMN = (8, 15) # 15 August
|
SITH_SEMESTER_START_AUTUMN = (8, 15) # 15 August
|
||||||
@@ -417,8 +420,6 @@ SITH_FORUM_PAGE_LENGTH = 30
|
|||||||
SITH_SAS_ROOT_DIR_ID = env.int("SITH_SAS_ROOT_DIR_ID", default=4)
|
SITH_SAS_ROOT_DIR_ID = env.int("SITH_SAS_ROOT_DIR_ID", default=4)
|
||||||
SITH_SAS_IMAGES_PER_PAGE = 60
|
SITH_SAS_IMAGES_PER_PAGE = 60
|
||||||
|
|
||||||
SITH_CGU_FILE_ID = env.int("SITH_CGU_FILE_ID", default=5)
|
|
||||||
|
|
||||||
SITH_PROFILE_DEPARTMENTS = [
|
SITH_PROFILE_DEPARTMENTS = [
|
||||||
("TC", _("TC")),
|
("TC", _("TC")),
|
||||||
("IMSI", _("IMSI")),
|
("IMSI", _("IMSI")),
|
||||||
|
|||||||
Reference in New Issue
Block a user