-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
95 lines (74 loc) · 2.44 KB
/
views.py
File metadata and controls
95 lines (74 loc) · 2.44 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import rest_framework.generics
import rest_framework.permissions
import rest_framework.response
import rest_framework.status
import rest_framework_simplejwt.tokens
import rest_framework_simplejwt.views
import business.constants
import business.models
import user.models
import user.serializers
class UserSignUpView(
rest_framework.generics.CreateAPIView,
):
serializer_class = user.serializers.SignUpSerializer
def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
user = serializer.save()
refresh = rest_framework_simplejwt.tokens.RefreshToken.for_user(user)
refresh['token_version'] = user.token_version
access_token = refresh.access_token
response_data = {
'access': str(access_token),
'refresh': str(refresh),
}
return rest_framework.response.Response(
response_data,
status=rest_framework.status.HTTP_200_OK,
)
class UserSignInView(
rest_framework_simplejwt.views.TokenObtainPairView,
):
serializer_class = user.serializers.SignInSerializer
class UserProfileView(
rest_framework.generics.RetrieveUpdateAPIView,
):
"""
Retrieve (GET) and partially update (PATCH)
detailed user profile information.
"""
http_method_names = ['get', 'patch', 'options', 'head']
serializer_class = user.serializers.UserProfileSerializer
permission_classes = [rest_framework.permissions.IsAuthenticated]
def get_object(self):
return self.request.user
def patch(self, request, *args, **kwargs):
return self.partial_update(request, *args, **kwargs)
class UserPromoDetailView(rest_framework.generics.RetrieveAPIView):
"""
Retrieve (GET) information about the promo without receiving a promo code.
"""
queryset = (
business.models.Promo.objects.select_related('company')
.prefetch_related(
'unique_codes',
)
.only(
'id',
'company__id',
'company__name',
'description',
'image_url',
'active',
'active_from',
'active_until',
'mode',
'used_count',
)
)
serializer_class = user.serializers.UserPromoDetailSerializer
permission_classes = [
rest_framework.permissions.IsAuthenticated,
]
lookup_field = 'id'