Browse Source

Merge pull request #1138 from SwiftPredator/Enhancement/export_only_approved_dataset_option

Enhancement: Added option to export only approved datasets
pull/1160/head
Hiroki Nakayama 3 years ago
committed by GitHub
parent
commit
d5e757b5f0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 4 deletions
  1. 8
      app/api/views.py
  2. 8
      frontend/components/organisms/documents/DocumentExportForm.vue
  3. 5
      frontend/services/document.service.js
  4. 2
      frontend/store/documents.js

8
app/api/views.py

@ -374,9 +374,15 @@ class TextDownloadAPI(APIView):
def get(self, request, *args, **kwargs):
format = request.query_params.get('q')
only_approved = request.query_params.get('onlyApproved')
project = get_object_or_404(Project, pk=self.kwargs['project_id'])
documents = project.documents.all()
documents = (
project.documents.exclude(annotations_approved_by = None)
if only_approved == 'true'
else project.documents.all()
)
painter = self.select_painter(format)
# jsonl-textlabel format prints text labels while jsonl format prints annotations with label ids
# jsonl-textlabel format - "labels": [[0, 15, "PERSON"], ..]
# jsonl format - "annotations": [{"label": 5, "start_offset": 0, "end_offset": 2, "user": 1},..]

8
frontend/components/organisms/documents/DocumentExportForm.vue

@ -37,6 +37,12 @@
</v-sheet>
<h2>{{ $t('dataset.exportDataMessage2') }}</h2>
<v-text-field v-model="selectedFileName" placeholder="Name the file" />
<v-checkbox
v-model="onlyApproved"
label="Export only approved documents"
color="success"
hide-details
/>
</v-form>
</template>
</base-card>
@ -68,6 +74,7 @@ export default {
file: null,
selectedFormat: null,
selectedFileName: 'project_' + this.$route.params.id + '_dataset',
onlyApproved: false,
fileFormatRules,
uploadFileRules
}
@ -99,6 +106,7 @@ export default {
projectId: this.$route.params.id,
fileName: this.selectedFileName,
format: this.selectedFormat.type,
onlyApproved: this.onlyApproved,
suffix: this.selectedFormat.suffix
})
this.reset()

5
frontend/services/document.service.js

@ -29,7 +29,7 @@ class DocumentService {
return this.request.post(`/projects/${projectId}/docs/upload`, payload, config)
}
exportFile(projectId, format) {
exportFile(projectId, format, onlyApproved) {
const headers = {}
if (format === 'csv') {
headers.Accept = 'text/csv; charset=utf-8'
@ -41,7 +41,8 @@ class DocumentService {
const config = {
responseType: 'blob',
params: {
q: format
q: format,
onlyApproved
},
headers
}

2
frontend/store/documents.js

@ -122,7 +122,7 @@ export const actions = {
},
exportDocument({ commit }, data) {
commit('setLoading', true)
DocumentService.exportFile(data.projectId, data.format)
DocumentService.exportFile(data.projectId, data.format, data.onlyApproved)
.then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]))
const link = document.createElement('a')

Loading…
Cancel
Save