Skip to content

Commit 59fa99e

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

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-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: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,35 @@
1010

1111

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

1522
format = models.TextField()
1623

1724
created = models.DateTimeField(auto_now_add=True, null=True)
25+
"""Date this supplied data was created. Not Null."""
26+
1827
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+
1935
processed = models.DateTimeField(null=True)
36+
"""Date this supplied data was expired.
37+
Nullable for the situation when it hasn't been processed yet."""
2038
error = models.TextField(null=True)
2139

2240
"""meta is for any extra information that specific cove implementations need.
41+
2342
This lets them store any info without needing changes to core libraries."""
2443
meta = models.JSONField(null=False, default=dict)
2544

@@ -29,10 +48,12 @@ def data_dir(self):
2948
def storage_dir(self):
3049
"""For use with Django storage classes.
3150
Returns directory any data about the SuppliedData should be stored in.
51+
3252
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+
)
3657
"""
3758
return str(self.id)
3859

@@ -109,15 +130,28 @@ def save_file_from_source_url(
109130

110131

111132
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+
112140
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
141+
"""id - an automatically assigned UUID."""
142+
113143
supplied_data = models.ForeignKey(SuppliedData, on_delete=models.CASCADE)
144+
"""A foreign key that links back to the SuppliedData this file belongs to."""
145+
114146
filename = models.TextField()
115147
size = models.PositiveBigIntegerField(null=True)
116148
content_type = models.TextField(null=True)
117149
charset = models.TextField(null=True)
150+
151+
meta = models.JSONField(null=False, default=dict)
118152
"""meta is for any extra information that specific cove implementations need.
119153
This lets them store any info without needing changes to core libraries."""
120-
meta = models.JSONField(null=False, default=dict)
154+
121155
source_method = models.TextField(null=True)
122156
source_url = models.URLField(null=True)
123157

@@ -140,9 +174,11 @@ def upload_url(self):
140174

141175
def storage_name(self):
142176
"""For use with Django storage classes.
143-
Returns full name in storage
177+
Returns full name in storage.
178+
144179
Example use:
145-
default_storage.open(os.path.join(supplied_data_file.storage_name())
180+
181+
default_storage.open(supplied_data_file.storage_name())
146182
"""
147183
return os.path.join(
148184
str(self.supplied_data.id),

0 commit comments

Comments
 (0)