def add_or_remove_user(self, *, challenge: Challenge, site): if self.cleaned_data["action"] == AdminsForm.ADD: challenge.add_admin(self.cleaned_data["user"]) send_new_admin_notification_email( challenge=challenge, new_admin=self.cleaned_data["user"], site=site, ) elif self.cleaned_data["action"] == AdminsForm.REMOVE: challenge.remove_admin(self.cleaned_data["user"])
def create_temp_page(title="temp_page", html=""): """ Create a quick mockup page which you can show, without needing to read anything from database """ site = Challenge() # any page requires a site, create on the fly here. site.short_name = "Temp" site.name = "Temporary page" site.skin = "" return Page(challenge=site, title=title, html=html)
def create_temp_page(title="temp_page", html=""): """ Create a quick mockup page which you can show, without needing to read anything from database """ challenge = Challenge() # any page requires a challenge challenge.short_name = "Temp" challenge.name = "Temporary page" challenge.skin = "" return Page(challenge=challenge, title=title, html=html)
def add_or_remove_user(self, *, challenge: Challenge, site): if self.cleaned_data["action"] == AdminsForm.ADD: challenge.add_admin(self.cleaned_data["user"]) send_new_admin_notification_email( challenge=challenge, new_admin=self.cleaned_data["user"], site=site, ) elif self.cleaned_data["action"] == AdminsForm.REMOVE: challenge.remove_admin(self.cleaned_data["user"])
def setup_challenge_groups(instance: Challenge = None, created: bool = False, *_, **__): if created: # Create the evaluation config Config.objects.create(challenge=instance) # Create the groups only on first save admins_group = Group.objects.create(name=instance.admin_group_name()) participants_group = Group.objects.create( name=instance.participants_group_name()) instance.admins_group = admins_group instance.participants_group = participants_group instance.save() instance.create_default_pages() assign_perm("change_challenge", admins_group, instance) # Create the datasets ImageSet.objects.create(phase=ImageSet.TESTING, challenge=instance) ImageSet.objects.create(phase=ImageSet.TRAINING, challenge=instance) # add current user to admins for this challenge try: instance.creator.groups.add(admins_group) except AttributeError: # No creator set pass send_challenge_created_email(instance)
def setup_challenge_groups( instance: Challenge = None, created: bool = False, *_, **__ ): if created: # Create the evaluation config Config.objects.create(challenge=instance) # Create the groups only on first save admins_group = Group.objects.create(name=instance.admin_group_name()) participants_group = Group.objects.create( name=instance.participants_group_name() ) instance.admins_group = admins_group instance.participants_group = participants_group instance.save() assign_perm("change_challenge", admins_group, instance) # Create the datasets ImageSet.objects.create(phase=ImageSet.TESTING, challenge=instance) ImageSet.objects.create(phase=ImageSet.TRAINING, challenge=instance) # add current user to admins for this challenge try: instance.creator.groups.add(admins_group) except AttributeError: # No creator set pass send_challenge_created_email(instance)
def _create_new_challenge(self, *, src_challenge, dest_name): new_challenge = Challenge( short_name=dest_name, **{f: getattr(src_challenge, f) for f in self.challenge_fields}, ) new_challenge.full_clean() new_challenge.save() return new_challenge
def can_access(user, path, *, challenge: Challenge): """ Does this user have permission to access folder path which is part of challenge named challenge_short_name? Override permission can be used to make certain folders servable through code even though this would not be allowed otherwise """ required = _required_permission(path) if required == ComicSiteModel.ALL: return True elif required == ComicSiteModel.REGISTERED_ONLY: return challenge.is_participant(user) elif required == ComicSiteModel.ADMIN_ONLY: return challenge.is_admin(user) elif required == ComicSiteModel.STAFF_ONLY: return user.is_staff else: return False
def add_or_remove_user(self, *, challenge: Challenge, site): if self.cleaned_data["action"] == AdminsForm.ADD: challenge.add_admin(self.cleaned_data["user"]) elif self.cleaned_data["action"] == AdminsForm.REMOVE: challenge.remove_admin(self.cleaned_data["user"])