mirror of https://github.com/doccano/doccano.git
Casey
2 years ago
5 changed files with 61 additions and 8 deletions
Split View
Diff Options
-
10backend/data_export/celery_tasks.py
-
14backend/data_export/models.py
-
26backend/data_export/pipeline/comments.py
-
9backend/data_export/pipeline/dataset.py
-
10backend/data_export/pipeline/factories.py
@ -0,0 +1,26 @@ |
|||
import abc |
|||
from collections import defaultdict |
|||
from typing import Dict, List, Tuple |
|||
|
|||
from django.db.models import QuerySet |
|||
|
|||
from data_export.models import ( |
|||
ExportedExample, |
|||
ExportedComment, |
|||
) |
|||
|
|||
class Comments(abc.ABC): |
|||
comment_class = ExportedComment |
|||
column = "Comments" |
|||
fields: Tuple[str, ...] = ("example", "user") # To boost performance |
|||
|
|||
def __init__(self, examples: QuerySet[ExportedExample], user=None): |
|||
self.comment_groups = defaultdict(list) |
|||
comments = self.comment_class.objects.filter(example__in=examples) |
|||
if user: |
|||
comments = comments.filter(user=user) |
|||
for comment in comments.select_related(*self.fields): |
|||
self.comment_groups[comment.example.id].append(comment) |
|||
|
|||
def find_by(self, example_id: int) -> Dict[str, List[ExportedComment]]: |
|||
return {self.column: self.comment_groups[example_id]} |
Write
Preview
Loading…
Cancel
Save