Beispiel #1
0
    def create_user(self, *args, is_staff=True, **kwargs):
        namespace = str(uuid.uuid4())
        email = kwargs.get('email', self.email)
        user = User.objects.create(*args,
                                   is_staff=is_staff,
                                   email=email,
                                   **kwargs)
        role = {k: v for v, k in UserProfile.ROLES}
        profile = UserProfile.objects.create(user=user,
                                             role=self.user_role,
                                             gsoc_year=self.user_gsoc_year,
                                             suborg_full_name=self.user_suborg)
        if self.user_role != role.get('Student', 3):
            return user

        # setup blog
        blogname = f"{user.username}'s Blog"
        app_config = NewsBlogConfig.objects.create(namespace=namespace)
        app_config.app_title = blogname
        app_config.save()
        profile.app_config = app_config
        profile.save()
        blog_list_page = Page.objects.\
            filter(application_namespace='blogs_list').\
            filter(publisher_is_draft=True).first()
        page = api.create_page(blogname,
                               get_cms_setting('TEMPLATES')[0][0],
                               'en',
                               published=True,
                               publication_date=timezone.now(),
                               apphook=app_config.cmsapp,
                               apphook_namespace=namespace,
                               parent=blog_list_page)
        su = User.objects.filter(is_superuser=True).first()
        api.publish_page(page, su, 'en')

        permissions = list()
        permissions.append(
            Permission.objects.filter(codename='add_article').first())
        permissions.append(
            Permission.objects.filter(codename='change_article').first())
        permissions.append(
            Permission.objects.filter(codename='delete_article').first())
        permissions.append(
            Permission.objects.filter(codename='view_article').first())
        user.user_permissions.set(permissions)

        mark_urlconf_as_changed()
        return user
Beispiel #2
0
    def create_user(
        self,
        *args,
        is_staff=True,
        reminder_disabled=False,
        github_handle=None,
        **kwargs,
    ):
        namespace = str(uuid.uuid4())
        email = kwargs.get("email", self.email)
        user, status = User.objects.get_or_create(*args,
                                                  is_staff=is_staff,
                                                  email=email,
                                                  **kwargs)
        if not status:
            profiles = user.userprofile_set.all()
            for _ in profiles:
                github_handle = profile.github_handle

        role = {k: v for v, k in UserProfile.ROLES}
        profile = UserProfile.objects.create(
            user=user,
            role=self.user_role,
            gsoc_year=self.user_gsoc_year,
            suborg_full_name=self.user_suborg,
            reminder_disabled=reminder_disabled,
            github_handle=github_handle,
        )
        if self.user_role != role.get("Student", 3):
            return user

        # setup blog
        blogname = f"{user.username}'s Blog"
        app_config = NewsBlogConfig.objects.create(namespace=namespace)
        app_config.app_title = blogname
        app_config.save()
        profile.app_config = app_config
        profile.save()
        blog_list_page = (Page.objects.filter(
            application_namespace="blogs_list").filter(
                publisher_is_draft=True).first())
        page = api.create_page(
            blogname,
            get_cms_setting("TEMPLATES")[0][0],
            "en",
            published=True,
            publication_date=timezone.now(),
            apphook=app_config.cmsapp,
            apphook_namespace=namespace,
            parent=blog_list_page,
        )
        su = User.objects.filter(is_superuser=True).first()
        page = api.publish_page(page, su, "en")

        PagePermission.objects.create(user=user, page=page)

        permissions = list()
        permissions.append(
            Permission.objects.filter(codename="add_article").first())
        permissions.append(
            Permission.objects.filter(codename="change_article").first())
        permissions.append(
            Permission.objects.filter(codename="delete_article").first())
        permissions.append(
            Permission.objects.filter(codename="view_article").first())
        permissions.append(
            Permission.objects.filter(codename="add_pagenotification").first())
        permissions.append(
            Permission.objects.filter(
                codename="change_pagenotification").first())
        permissions.append(
            Permission.objects.filter(
                codename="delete_pagenotification").first())
        permissions.append(
            Permission.objects.filter(
                codename="view_pagenotification").first())
        user.user_permissions.set(permissions)

        mark_urlconf_as_changed()
        return user
Beispiel #3
0
def trigger_server_restart(**kwargs):
    """
    Marks the URLs as stale so that they can be reloaded.
    """
    mark_urlconf_as_changed()
Beispiel #4
0
def trigger_server_restart(**kwargs):
    """
    Marks the URLs as stale so that they can be reloaded.
    """
    mark_urlconf_as_changed()