Skip to content

Commit f777850

Browse files
committed
docs content - database models
1 parent b08076d commit f777850

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

docs/python-api/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ It does not document Python that is not intended for reuse by others (you can re
1313
process/base.rst
1414
process/common_tasks/download_data_task.rst
1515
process/common_tasks/task_with_state.rst
16+
models.rst
17+

docs/python-api/models.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Database Models
2+
===============
3+
4+
5+
.. autoclass:: libcoveweb2.models.SuppliedData
6+
:members:
7+
:exclude-members: DoesNotExist, MultipleObjectsReturned
8+
9+
.. autoclass:: libcoveweb2.models.SuppliedDataFile
10+
:members:
11+
:exclude-members: DoesNotExist, MultipleObjectsReturned
12+
13+

libcoveweb2/models.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,32 @@
1010

1111

1212
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+
1318
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
19+
"""id - an automatically assigned UUID."""
1420

1521
format = models.TextField()
1622

1723
created = models.DateTimeField(auto_now_add=True, null=True)
24+
"""Date this supplied data was created. Not Null."""
25+
1826
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+
1933
processed = models.DateTimeField(null=True)
34+
"""Date this supplied data was expired. Nullable for the situation when it hasn't been processed yet."""
2035
error = models.TextField(null=True)
2136

2237
"""meta is for any extra information that specific cove implementations need.
38+
2339
This lets them store any info without needing changes to core libraries."""
2440
meta = models.JSONField(null=False, default=dict)
2541

@@ -29,10 +45,12 @@ def data_dir(self):
2945
def storage_dir(self):
3046
"""For use with Django storage classes.
3147
Returns directory any data about the SuppliedData should be stored in.
48+
3249
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+
)
3654
"""
3755
return str(self.id)
3856

@@ -109,15 +127,26 @@ def save_file_from_source_url(
109127

110128

111129
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+
112135
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
136+
"""id - an automatically assigned UUID."""
137+
113138
supplied_data = models.ForeignKey(SuppliedData, on_delete=models.CASCADE)
139+
"""A foreign key that links back to the SuppliedData this file belongs to."""
140+
114141
filename = models.TextField()
115142
size = models.PositiveBigIntegerField(null=True)
116143
content_type = models.TextField(null=True)
117144
charset = models.TextField(null=True)
145+
146+
meta = models.JSONField(null=False, default=dict)
118147
"""meta is for any extra information that specific cove implementations need.
119148
This lets them store any info without needing changes to core libraries."""
120-
meta = models.JSONField(null=False, default=dict)
149+
121150
source_method = models.TextField(null=True)
122151
source_url = models.URLField(null=True)
123152

@@ -140,9 +169,11 @@ def upload_url(self):
140169

141170
def storage_name(self):
142171
"""For use with Django storage classes.
143-
Returns full name in storage
172+
Returns full name in storage.
173+
144174
Example use:
145-
default_storage.open(os.path.join(supplied_data_file.storage_name())
175+
176+
default_storage.open(supplied_data_file.storage_name())
146177
"""
147178
return os.path.join(
148179
str(self.supplied_data.id),

0 commit comments

Comments
 (0)