-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathotypes.py
More file actions
184 lines (141 loc) · 5.08 KB
/
otypes.py
File metadata and controls
184 lines (141 loc) · 5.08 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import json
from functools import cached_property
from typing import Dict, List, Optional, Union
import strawberry
from strawberry.fastapi import BaseContext
from strawberry.types import Info as _Info
from strawberry.types.info import RootValueType
from models import CCRecruitment, Mails, PyObjectId, StorageFile
# custom context class
class Context(BaseContext):
"""
Class provides user metadata and cookies from request headers, has
methods for doing this.
"""
@cached_property
def user(self) -> Union[Dict, None]:
if not self.request:
return None
user = json.loads(self.request.headers.get("user", "{}"))
return user
@cached_property
def cookies(self) -> Union[Dict, None]:
if not self.request:
return None
cookies = json.loads(self.request.headers.get("cookies", "{}"))
return cookies
Info = _Info[Context, RootValueType]
"""custom info Type for user metadata"""
PyObjectIdType = strawberry.scalar(
PyObjectId, serialize=str, parse_value=lambda v: PyObjectId(v)
)
"""A scalar Type for serializing PyObjectId, used for id field"""
@strawberry.experimental.pydantic.type(model=Mails)
class MailReturnType:
"""
Type used for returning the subject and uid of a mail.
Attributes:
uid (str): UID of the sender.
subject (str): Subject of the mail.
"""
uid: strawberry.auto
subject: strawberry.auto
@strawberry.experimental.pydantic.input(model=Mails)
class MailInput:
"""
Input used for taking subject, body and to recipients of a mail.
Attributes:
subject (str): Subject of the mail.
body (str): Body of the mail.
to_recipients (List[str]): List of to recipients.
cc_recipients (Optional[List[str]]): List of CC recipients.
Defaults to None.
uid (Optional[str]): UID of the sender. Defaults to None.
html_body (Optional[bool]): Whether the body is in HTML format.
Defaults to False
"""
subject: strawberry.auto
body: strawberry.auto
to_recipients: strawberry.auto
cc_recipients: Optional[List[str]] = strawberry.UNSET
uid: Optional[str] = strawberry.UNSET
html_body: Optional[bool] = False
@strawberry.experimental.pydantic.input(model=CCRecruitment)
class CCRecruitmentInput:
"""
Input used for taking in answers of the recruitment form.
Attributes:
uid (str): User ID of the applicant.
email (str): Email of the applicant.
teams (List[models.Team]): List of teams the applicant is applying for.
design_experience (str): Design experience of the applicant. Defaults
to None.
why_this_position (str): Why the applicant wants this position.
why_cc (str): Why the applicant wants to join CC.
ideas1 (str): Reasons for not participating in an event.
ideas (str): Ideas the applicant has for CC.
other_bodies (str | None): Other bodies the applicant is a part of.
Defaults to None.
good_fit (str): Why the applicant is a good fit for CC.
"""
uid: strawberry.auto
email: strawberry.auto
teams: strawberry.auto
design_experience: strawberry.auto
why_this_position: strawberry.auto
why_cc: strawberry.auto
ideas1: strawberry.auto
ideas: strawberry.auto
other_bodies: strawberry.auto
good_fit: strawberry.auto
@strawberry.experimental.pydantic.type(model=CCRecruitment, all_fields=True)
class CCRecruitmentType:
"""
Type used for returning the answers of the recruitment form.
Attributes:
fields (models.CCRecruitment): All fields of the CCRecruitment model.
"""
pass
# signed url object type
@strawberry.type
class SignedURL:
"""
Type used for returning the signed url of a file.
Attributes:
url (str): The signed URL.
"""
url: str
@strawberry.input
class SignedURLInput:
"""
Input used for taking details regarding size, name and format of a file.
Attributes:
static_file (bool): Whether the file is static or not.
Defaults to False.
filename (str): Name of the file. Defaults to None.
max_size_mb (float): Size of the file in MB. Defaults to 0.3.
"""
static_file: bool = False
filename: str | None = None
max_size_mb: float = 0.3
# StorageFile Types
@strawberry.experimental.pydantic.input(model=StorageFile)
class StorageFileInput:
"""
Input used for taking details regarding the file's title, name and type.
Attributes:
title (str): Title of the file.
filename (str): Name of the file.
filetype (str): Type of the file.
"""
title: strawberry.auto
filename: strawberry.auto
filetype: strawberry.auto
@strawberry.experimental.pydantic.type(model=StorageFile, all_fields=True)
class StorageFileType:
"""
Input used for taking all the details regarding the file.
Attributes:
fields (models.StorageFile): All fields of the StorageFile model.
"""
pass