10
10
11
11
12
12
class SuppliedData (models .Model ):
13
+ """
14
+ The Database Model class to represent one set of supplied data sent to
15
+ the app by a user.
16
+ This can be one or more files (modelled by the SuppliedDataFile class).
17
+ """
18
+
13
19
id = models .UUIDField (primary_key = True , default = uuid .uuid4 , editable = False )
20
+ """id - an automatically assigned UUID."""
14
21
15
22
format = models .TextField ()
16
23
17
24
created = models .DateTimeField (auto_now_add = True , null = True )
25
+ """Date this supplied data was created. Not Null."""
26
+
18
27
expired = models .DateTimeField (null = True )
28
+ """Date this supplied data was expired.
29
+ Nullable for the situation when it hasn't been expired yet.
30
+
31
+ Upon expiration, the data on disk will be deleted (to preserve our users privacy)
32
+ but the database objects left so we have meta data to track usage.
33
+ """
34
+
19
35
processed = models .DateTimeField (null = True )
36
+ """Date this supplied data was expired.
37
+ Nullable for the situation when it hasn't been processed yet."""
20
38
error = models .TextField (null = True )
21
39
22
40
"""meta is for any extra information that specific cove implementations need.
41
+
23
42
This lets them store any info without needing changes to core libraries."""
24
43
meta = models .JSONField (null = False , default = dict )
25
44
@@ -29,10 +48,12 @@ def data_dir(self):
29
48
def storage_dir (self ):
30
49
"""For use with Django storage classes.
31
50
Returns directory any data about the SuppliedData should be stored in.
51
+
32
52
Example use:
33
- default_storage.exists(
34
- os.path.join(supplied_data.storage_dir(), "some_filename.json")
35
- )
53
+
54
+ default_storage.exists(
55
+ os.path.join(supplied_data.storage_dir(), "some_filename.json")
56
+ )
36
57
"""
37
58
return str (self .id )
38
59
@@ -109,15 +130,28 @@ def save_file_from_source_url(
109
130
110
131
111
132
class SuppliedDataFile (models .Model ):
133
+ """
134
+ The Database Model class to represent one file or one set of data
135
+ sent to the app by a user.
136
+ A submission by a user (modelled by the SuppliedData class)
137
+ may have one or more SuppliedDataFile's.
138
+ """
139
+
112
140
id = models .UUIDField (primary_key = True , default = uuid .uuid4 , editable = False )
141
+ """id - an automatically assigned UUID."""
142
+
113
143
supplied_data = models .ForeignKey (SuppliedData , on_delete = models .CASCADE )
144
+ """A foreign key that links back to the SuppliedData this file belongs to."""
145
+
114
146
filename = models .TextField ()
115
147
size = models .PositiveBigIntegerField (null = True )
116
148
content_type = models .TextField (null = True )
117
149
charset = models .TextField (null = True )
150
+
151
+ meta = models .JSONField (null = False , default = dict )
118
152
"""meta is for any extra information that specific cove implementations need.
119
153
This lets them store any info without needing changes to core libraries."""
120
- meta = models . JSONField ( null = False , default = dict )
154
+
121
155
source_method = models .TextField (null = True )
122
156
source_url = models .URLField (null = True )
123
157
@@ -140,9 +174,11 @@ def upload_url(self):
140
174
141
175
def storage_name (self ):
142
176
"""For use with Django storage classes.
143
- Returns full name in storage
177
+ Returns full name in storage.
178
+
144
179
Example use:
145
- default_storage.open(os.path.join(supplied_data_file.storage_name())
180
+
181
+ default_storage.open(supplied_data_file.storage_name())
146
182
"""
147
183
return os .path .join (
148
184
str (self .supplied_data .id ),
0 commit comments