Ejemplo n.º 1
0
def update_user(user: User, name: str, gender: int, introduction: str, photo):
    if photo:
        if user.photo:
            user.photo.delete()
        system.user_photo_storage(user, photo)

    user = user
    user.name = name
    user.gender = gender
    user.introduction = introduction

    user.save()

    return user
Ejemplo n.º 2
0
def create_users(reg_ids: list, privilege: int):
    queries = Q()

    for reg_id in reg_ids:
        queries |= Q(reg_id=reg_id)

    existed_users = User.objects.filter(queries)

    if existed_users:
        raise IllegalArgumentError("Existed user: {}".format(', '.join([user.reg_id for user in existed_users])))

    # bulk_create an object manager method which takes as input an array of objects created using the class constructor
    User.objects.bulk_create([User(reg_id=reg_id,
                                   privilege=privilege,
                                   password=make_password(reg_id)) for reg_id in reg_ids])

    return User.objects.filter(queries)
Ejemplo n.º 3
0
def has_perms(user: User, required_privilege: UserType):
    """
    Returns True if the user has the specified permission,
    where perm is in the format "<app label>.<permission codename>"
    """
    return user.has_perm(required_privilege)
Ejemplo n.º 4
0
def has_perms(user: User, required_privilege: UserType):
    return user.has_perm(required_privilege)
Ejemplo n.º 5
0
def has_perm(user: User, required_privilege: UserType):
    return user.has_perm(UserType[required_privilege])