Skip to content

Commit 24aab0c

Browse files
refactor arch table/services, file/arch models
1 parent 1d5e807 commit 24aab0c

File tree

11 files changed

+34
-34
lines changed

11 files changed

+34
-34
lines changed

backend-app/archive/serializers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from rest_framework.serializers import ModelSerializer, ChoiceField, SerializerMethodField
1+
from rest_framework.serializers import ModelSerializer, ChoiceField, SerializerMethodField, IntegerField
22
from .models import Archive
33

44

@@ -9,6 +9,7 @@ def to_representation(self, value: str) -> str: return self.choices[value]
99
class ArchiveSerializer(ModelSerializer):
1010
status = StatusChoiceField(choices=Archive.STATUSES)
1111
author = SerializerMethodField()
12+
file_count = IntegerField()
1213

1314
class Meta:
1415
model = Archive

backend-app/archive/services.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
def _get_archives(project: Project) -> tuple[dict[str, Any], int]:
2121
query = project.archive_set \
2222
.annotate(file_count=Count("file")) \
23-
.order_by("create_date")
23+
.order_by("-create_date")
2424
return ArchiveSerializer(query, many=True).data, HTTP_200_OK
2525

2626

@@ -41,14 +41,17 @@ def _make_archive(project: Project, request: Request) -> tuple[dict[str, Any], i
4141
.values("name") \
4242
.values_list("name", flat=True)
4343

44+
only_new = request_query.get("only_new", False)
45+
4446
filter_data = {
4547
"status": request_query.get("card", []),
46-
"only_new": request_query.get("downloaded", False),
48+
"only_new": only_new,
4749
"type": request_query.get("type", []),
4850
"attributes": list(attributes)
4951
}
5052

5153
files, _ = FileService()._get_files(project.id, request.user, request_query, True)
54+
if only_new: files = files.filter(archive__isnull=True)
5255

5356
# response = post(
5457
# "url",
@@ -71,7 +74,6 @@ def _make_archive(project: Project, request: Request) -> tuple[dict[str, Any], i
7174
author=request.user
7275
)
7376

74-
files.update(is_downloaded=True)
7577
archive.file.add(*files)
7678

7779
return ArchiveSerializer(archive).data, 201

backend-app/file/file_tests/models_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def test_create_file(self):
3636
"project",
3737
"author",
3838
"status",
39-
"is_downloaded",
4039
"validator",
4140
)
4241
.get(id=new_file.id)

backend-app/file/file_tests/serializers_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def test_file_serializer(self):
2727
'file_name',
2828
'file_type',
2929
'status',
30-
'is_downloaded',
3130
}
3231

3332
self.assertEqual(

backend-app/file/file_tests/services_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ def _get_query(
295295
filter["status"] = status
296296
if downloaded:
297297
query.set("downloaded", downloaded)
298-
filter["is_downloaded"] = False
299298
if author:
300299
query.set("author[]", author)
301300
filter["author__in"] = author

backend-app/file/file_tests/views_test.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,7 @@ def test_annotate_files(self):
278278
content_type="application/json",
279279
HTTP_AUTHORIZATION="Bearer " + self.case.user.emit_token()
280280
)
281-
self.assertEqual(
282-
self.case.project.file_set.filter(is_downloaded=True).count(),
283-
0
284-
)
281+
285282

286283
admin_request = self.client.post(
287284
"/api/files/annotation/",
@@ -311,7 +308,3 @@ def test_annotate_files(self):
311308
)
312309
self.assertEqual(internal_request.status_code, 202)
313310
self.assertEqual(internal_request.data["annotated"], 1)
314-
self.assertEqual(
315-
self.case.project.file_set.filter(is_downloaded=True).count(),
316-
1
317-
)

backend-app/file/models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class File(Model):
2424
file_name: CharField = CharField(max_length=255)
2525
file_type: CharField = CharField(max_length=10)
2626
status: CharField = CharField(max_length=1, choices=STATUSES, default='p')
27-
is_downloaded: BooleanField = BooleanField(default=False)
2827
upload_date: DateTimeField = DateTimeField(auto_now_add=True)
2928
update_date: DateTimeField = DateTimeField(auto_now_add=True, null=True)
3029

backend-app/file/services.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
Case,
1616
Prefetch
1717
)
18+
from django.db.models.query import QuerySet
1819
from rest_framework.request import QueryDict
1920
from rest_framework.views import Request
2021
from django.db import connection, transaction
@@ -35,7 +36,6 @@ class ViewSetServices:
3536
("status__in", "card[]", True),
3637
("file_type__in", "type[]", True),
3738
("status", "status", False),
38-
("is_downloaded", "downloaded", False),
3939
("author__in", "author[]", True),
4040
("upload_date__gte", "from", False),
4141
("upload_date__lte", "to", False)
@@ -116,7 +116,6 @@ def _get_param(self, filter_name: str, query_param: Any) -> Any:
116116
date_from_str = lambda d: tz.make_aware(dt.strptime(d, "%Y-%m-%d"))
117117

118118
match filter_name:
119-
case "is_downloaded": return False
120119
case "upload_date__gte": return date_from_str(query_param)
121120
case "upload_date__lte": return date_from_str(query_param)
122121
case _: return query_param
@@ -127,7 +126,7 @@ def _get_files(
127126
request_user: CustomUser,
128127
request_query: QueryDict,
129128
as_query: bool = False
130-
) -> tuple[dict[str, Any], int]:
129+
) -> tuple[dict[str, Any] | QuerySet, int]:
131130
filters = self._form_filters(project_id, request_user, request_query)
132131
orders = self._form_orders(request_query)
133132

frontend-app/src/components/FilesDownload/DownloadTable.jsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default function DownloadTable({ data, onDownload }) {
1515
<th>author</th>
1616
<th>status</th>
1717
<th>create date</th>
18+
<th>file count</th>
1819
<th>result size</th>
1920
<th>result message</th>
2021
<th>requested</th>
@@ -24,21 +25,25 @@ export default function DownloadTable({ data, onDownload }) {
2425
<tbody>
2526
{
2627
data.map((item) => (
27-
<tr key={item.id}>
28+
<tr key={item.id} className={"downloads__row__" + item.status.toLowerCase()}>
2829
<td>{item.id}</td>
2930
<td>{item.author}</td>
3031
<td>{item.status.toLowerCase()}</td>
3132
<td>{item.create_date}</td>
33+
<td>{item.file_count}</td>
3234
<td>{item.result_size}</td>
3335
<td>{item.result_message}</td>
3436
<td>{formatFilterJSON(item.filters)}</td>
35-
<td onClick={() => onDownload(item.id)} className="downloads__table__button">
36-
<button type="button">
37-
<svg width="24" height="24" viewBox="0 0 24 24">
38-
<path d="M14.14 13H13V3a1 1 0 0 0-2 0v10H9.86a1 1 0 0 0-.69 1.5l2.14 3.12a.82.82 0 0 0 1.38 0l2.14-3.12a1 1 0 0 0-.69-1.5" />
39-
<path d="M19 22H5a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h3a1 1 0 0 1 0 2H5v11h14V9h-3a1 1 0 0 1 0-2h3a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2" />
40-
</svg>
41-
</button>
37+
<td className="downloads__table__button">
38+
{
39+
item.status === "SUCCESS" &&
40+
<button type="button" onClick={() => onDownload(item.result_id)}>
41+
<svg width="24" height="24" viewBox="0 0 24 24">
42+
<path d="M14.14 13H13V3a1 1 0 0 0-2 0v10H9.86a1 1 0 0 0-.69 1.5l2.14 3.12a.82.82 0 0 0 1.38 0l2.14-3.12a1 1 0 0 0-.69-1.5" />
43+
<path d="M19 22H5a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h3a1 1 0 0 1 0 2H5v11h14V9h-3a1 1 0 0 1 0-2h3a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2" />
44+
</svg>
45+
</button>
46+
}
4247
</td>
4348
</tr>
4449
))

frontend-app/src/components/FilesDownload/index.jsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export default function FilesDownload({ pathID, attributes }) {
5959

6060
try {
6161
var payload = { ...filterData };
62-
if (newCheckBox.current.checked) payload.downloaded = false;
62+
if (newCheckBox.current.checked) payload.only_new = true;
6363

6464
await api.post(`/api/projects/archive/${pathID}/`, payload, {
6565
headers: { Authorization: "Bearer " + localStorage.getItem("dtcAccess") },
@@ -132,10 +132,8 @@ export default function FilesDownload({ pathID, attributes }) {
132132
>{loading ? <Load isInline /> : <span>request</span>}</button>
133133
</div>
134134
{
135-
downloads.length
136-
? <DownloadTable data={downloads} onDownload={(id) => { console.log(id); }}/>
137-
: "No Data"
135+
downloads.length &&
136+
<DownloadTable data={downloads} onDownload={(id) => { console.log(id); }}/>
138137
}
139-
140138
</>;
141139
}

0 commit comments

Comments
 (0)