Fix page creation method for clubs

This commit is contained in:
Antoine Bartuccio 2017-09-19 14:48:56 +02:00
parent f4bc1b140c
commit 790d723d08
Signed by: klmp200
GPG Key ID: E7245548C53F904B
2 changed files with 8 additions and 8 deletions

View File

@ -112,24 +112,24 @@ class Club(models.Model):
public = Group.objects.filter(id=settings.SITH_GROUP_PUBLIC_ID).first() public = Group.objects.filter(id=settings.SITH_GROUP_PUBLIC_ID).first()
p = Page(name=self.unix_name) p = Page(name=self.unix_name)
p.parent = club_root p.parent = club_root
p.set_lock(root) p.save(force_lock=True)
if public: if public:
p.view_groups.add(public) p.view_groups.add(public)
p.save() p.save(force_lock=True)
if self.parent and self.parent.page: if self.parent and self.parent.page:
p.parent = self.parent.page p.parent = self.parent.page
self.page = p self.page = p
self.save() self.save()
elif self.page and self.page.name != self.unix_name: elif self.page and self.page.name != self.unix_name:
self.page.unset_lock() self.page.unset_lock()
self.page.set_lock(root) # self.page.set_lock(root)
self.page.name = self.unix_name self.page.name = self.unix_name
self.page.save() self.page.save(force_lock=True)
elif self.page and self.parent and self.parent.page and self.page.parent != self.parent.page: elif self.page and self.parent and self.parent.page and self.page.parent != self.parent.page:
self.page.unset_lock() self.page.unset_lock()
self.page.set_lock(root) # self.page.set_lock(root)
self.page.parent = self.parent.page self.page.parent = self.parent.page
self.page.save() self.page.save(force_lock=True)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
with transaction.atomic(): with transaction.atomic():

View File

@ -1007,8 +1007,8 @@ class Page(models.Model):
@property @property
def is_club_page(self): def is_club_page(self):
unauthorized_parent = Page.objects.filter(name=settings.SITH_CLUB_ROOT_PAGE).first() club_root_page = Page.objects.filter(name=settings.SITH_CLUB_ROOT_PAGE).first()
return unauthorized_parent is not None and (self == unauthorized_parent or unauthorized_parent in self.get_parent_list()) return club_root_page is not None and (self == club_root_page or club_root_page in self.get_parent_list())
def delete(self): def delete(self):
self.unset_lock_recursive() self.unset_lock_recursive()