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