예제 #1
0
    def create_page_user(self,
                         username,
                         password=None,
                         can_add_page=True,
                         can_change_page=True,
                         can_delete_page=True,
                         can_recover_page=True,
                         can_add_pageuser=True,
                         can_change_pageuser=True,
                         can_delete_pageuser=True,
                         can_add_pagepermission=True,
                         can_change_pagepermission=True,
                         can_delete_pagepermission=True,
                         grant_all=False):
        """
        Helper function for creating page user, through form on:
            /admin/cms/pageuser/add/
            
        Returns created user.
        """
        if grant_all:
            return self.create_page_user(username, password, True, True, True,
                                         True, True, True, True, True, True,
                                         True)

        if password is None:
            password = username

        data = {
            'can_add_page': can_add_page,
            'can_change_page': can_change_page,
            'can_delete_page': can_delete_page,
            'can_recover_page': can_recover_page,
            'can_add_pageuser': can_add_pageuser,
            'can_change_pageuser': can_change_pageuser,
            'can_delete_pageuser': can_delete_pageuser,
            'can_add_pagepermission': can_add_pagepermission,
            'can_change_pagepermission': can_change_pagepermission,
            'can_delete_pagepermission': can_delete_pagepermission,
        }
        if hasattr(self, 'user'):
            created_by = self.user
        else:
            created_by = User.objects.create_superuser(
                'superuser', '*****@*****.**', 'superuser')
        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            user = User.objects.create_user(username,
                                            '*****@*****.**',
                                            password)
            user.is_staff = True
            user.is_active = True
        page_user = PageUser(created_by=created_by)
        for field in [f.name for f in User._meta.local_fields]:
            setattr(page_user, field, getattr(user, field))
        user.save()
        page_user.save()
        save_permissions(data, page_user)
        return user
예제 #2
0
    def create_page_user(self,
                         username,
                         password=None,
                         can_add_page=True,
                         can_change_page=True,
                         can_delete_page=True,
                         can_recover_page=True,
                         can_add_pageuser=True,
                         can_change_pageuser=True,
                         can_delete_pageuser=True,
                         can_add_pagepermission=True,
                         can_change_pagepermission=True,
                         can_delete_pagepermission=True,
                         grant_all=False):
        """
        Helper function for creating page user, through form on:
            /admin/cms/pageuser/add/
            
        Returns created user.
        """
        if grant_all:
            return self.create_page_user(username, password, True, True, True,
                                         True, True, True, True, True, True,
                                         True)

        if password is None:
            password = username

        data = {
            'can_add_page': can_add_page,
            'can_change_page': can_change_page,
            'can_delete_page': can_delete_page,
            'can_recover_page': can_recover_page,
            'can_add_pageuser': can_add_pageuser,
            'can_change_pageuser': can_change_pageuser,
            'can_delete_pageuser': can_delete_pageuser,
            'can_add_pagepermission': can_add_pagepermission,
            'can_change_pagepermission': can_change_pagepermission,
            'can_delete_pagepermission': can_delete_pagepermission,
        }
        if hasattr(self, 'user'):
            created_by = self.user
        else:
            created_by = User.objects.create_superuser(
                'superuser', '*****@*****.**', 'superuser')
        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            user = User.objects.create_user(
                username, '*****@*****.**', password)
            user.is_staff = True
            user.is_active = True
        page_user = PageUser(created_by=created_by)
        for field in [f.name for f in User._meta.local_fields]:
            setattr(page_user, field, getattr(user, field))
        user.save()
        page_user.save()
        save_permissions(data, page_user)
        return user
예제 #3
0
파일: api.py 프로젝트: goutnet/django-cms
def create_page_user(created_by,
                     user,
                     can_add_page=True,
                     can_view_page=True,
                     can_change_page=True,
                     can_delete_page=True,
                     can_recover_page=True,
                     can_add_pageuser=True,
                     can_change_pageuser=True,
                     can_delete_pageuser=True,
                     can_add_pagepermission=True,
                     can_change_pagepermission=True,
                     can_delete_pagepermission=True,
                     grant_all=False):
    """
    Creates a page user.

    See docs/extending_cms/api_reference.rst for more info
    """
    from cms.admin.forms import save_permissions
    if grant_all:
        # just be lazy
        return create_page_user(created_by, user, True, True, True, True, True,
                                True, True, True, True, True, True)

    # validate created_by
    assert isinstance(created_by, get_user_model())

    data = {
        'can_add_page': can_add_page,
        'can_view_page': can_view_page,
        'can_change_page': can_change_page,
        'can_delete_page': can_delete_page,
        'can_recover_page': can_recover_page,
        'can_add_pageuser': can_add_pageuser,
        'can_change_pageuser': can_change_pageuser,
        'can_delete_pageuser': can_delete_pageuser,
        'can_add_pagepermission': can_add_pagepermission,
        'can_change_pagepermission': can_change_pagepermission,
        'can_delete_pagepermission': can_delete_pagepermission,
    }
    user.is_staff = True
    user.is_active = True
    page_user = PageUser(created_by=created_by)
    for field in [f.name for f in get_user_model()._meta.local_fields]:
        setattr(page_user, field, getattr(user, field))
    user.save()
    page_user.save()
    save_permissions(data, page_user)
    return user
예제 #4
0
파일: api.py 프로젝트: evildmp/django-cms
def create_page_user(created_by, user,
                     can_add_page=True, can_view_page=True,
                     can_change_page=True, can_delete_page=True,
                     can_recover_page=True, can_add_pageuser=True,
                     can_change_pageuser=True, can_delete_pageuser=True,
                     can_add_pagepermission=True,
                     can_change_pagepermission=True,
                     can_delete_pagepermission=True, grant_all=False):
    """
    Creates a page user.

    See docs/extending_cms/api_reference.rst for more info
    """
    from cms.admin.forms import save_permissions
    if grant_all:
        # just be lazy
        return create_page_user(created_by, user, True, True, True, True,
                                True, True, True, True, True, True, True)

    # validate created_by
    assert isinstance(created_by, get_user_model())

    data = {
        'can_add_page': can_add_page,
        'can_view_page': can_view_page,
        'can_change_page': can_change_page,
        'can_delete_page': can_delete_page,
        'can_recover_page': can_recover_page,
        'can_add_pageuser': can_add_pageuser,
        'can_change_pageuser': can_change_pageuser,
        'can_delete_pageuser': can_delete_pageuser,
        'can_add_pagepermission': can_add_pagepermission,
        'can_change_pagepermission': can_change_pagepermission,
        'can_delete_pagepermission': can_delete_pagepermission,
    }
    user.is_staff = True
    user.is_active = True
    page_user = PageUser(created_by=created_by)
    for field in [f.name for f in get_user_model()._meta.local_fields]:
        setattr(page_user, field, getattr(user, field))
    user.save()
    page_user.save()
    save_permissions(data, page_user)
    return user
예제 #5
0
def create_page_user(created_by, user,
                     can_add_page=True, can_view_page=True,
                     can_change_page=True, can_delete_page=True, 
                     can_recover_page=True, can_add_pageuser=True,
                     can_change_pageuser=True, can_delete_pageuser=True,
                     can_add_pagepermission=True,
                     can_change_pagepermission=True,
                     can_delete_pagepermission=True, grant_all=False):
    """
    Creates a page user.
    
    See docs/extending_cms/api_reference.rst for more info
    """
    if grant_all:
        # just be lazy
        return create_page_user(created_by, user, True, True, True, True,
                                True, True, True, True, True, True, True)
    
    # validate created_by
    assert isinstance(created_by, auth.get_user_model())
    
    data = {
        'can_add_page': can_add_page, 
        'can_view_page': can_view_page, 
        'can_change_page': can_change_page, 
        'can_delete_page': can_delete_page, 
        'can_recover_page': can_recover_page, 
        'can_add_pageuser': can_add_pageuser, 
        'can_change_pageuser': can_change_pageuser, 
        'can_delete_pageuser': can_delete_pageuser, 
        'can_add_pagepermission': can_add_pagepermission,
        'can_change_pagepermission': can_change_pagepermission,
        'can_delete_pagepermission': can_delete_pagepermission,
    }
    user.is_staff = True
    user.is_active = True
    user.save()
    page_user = PageUser(user, created_by=created_by)
    page_user.save()
    save_permissions(data, page_user)
    return user