-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathservices.py
31 lines (20 loc) · 891 Bytes
/
services.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from typing import List, Optional
from django.db import transaction
from styleguide_example.common.services import model_update
from styleguide_example.users.models import BaseUser
@transaction.atomic
def user_create(
*, email: str, is_active: bool = True, is_admin: bool = False, password: Optional[str] = None
) -> BaseUser:
user = BaseUser.objects.create_user(email=email, is_active=is_active, is_admin=is_admin, password=password)
return user
@transaction.atomic
def user_update(*, user: BaseUser, data) -> BaseUser:
non_side_effect_fields: List[str] = [
# "first_name",
# "last_name"
]
user, has_updated = model_update(instance=user, fields=non_side_effect_fields, data=data)
# Side-effect fields update here (e.g. username is generated based on first & last name)
# ... some additional tasks with the user ...
return user