|
1 | 1 | import io |
| 2 | +import json |
2 | 3 | import os |
3 | 4 | import re |
4 | 5 | import traceback |
|
9 | 10 | import openpyxl |
10 | 11 | import uuid_utils.compat as uuid |
11 | 12 | from celery_once import AlreadyQueued |
| 13 | +from django.contrib.postgres.fields import JSONField |
12 | 14 | from django.core import validators |
13 | 15 | from django.db import transaction, models |
14 | | -from django.db.models import QuerySet |
| 16 | +from django.db.models import QuerySet, Func, F, Value |
15 | 17 | from django.db.models.aggregates import Max |
16 | | -from django.db.models.functions import Substr, Reverse |
| 18 | +from django.db.models.fields.json import KeyTextTransform |
| 19 | +from django.db.models.functions import Substr, Reverse, Coalesce, Cast |
17 | 20 | from django.http import HttpResponse |
18 | 21 | from django.utils.translation import gettext_lazy as _, gettext, get_language, to_locale |
19 | 22 | from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE |
@@ -1256,6 +1259,19 @@ def batch_edit_hit_handling(self, instance: Dict, with_valid=True): |
1256 | 1259 | if directly_return_similarity is not None: |
1257 | 1260 | update_dict['directly_return_similarity'] = directly_return_similarity |
1258 | 1261 | QuerySet(Document).filter(id__in=document_id_list).update(**update_dict) |
| 1262 | + allow_download = instance.get('allow_download') |
| 1263 | + if allow_download is not None: |
| 1264 | + # 我需要修改meta meta是存在Document的字段 是一个json字段 但是allow_download可能不存在 |
| 1265 | + Document.objects.filter(id__in=document_id_list).update( |
| 1266 | + meta=Func( |
| 1267 | + F("meta"), |
| 1268 | + Value(["allow_download"]), |
| 1269 | + Value(json.dumps(allow_download)), # 转成 "true"/"false" |
| 1270 | + Value(True), # create_missing = true |
| 1271 | + function="jsonb_set", |
| 1272 | + output_field=JSONField(), |
| 1273 | + ) |
| 1274 | + ) |
1259 | 1275 |
|
1260 | 1276 | def batch_refresh(self, instance: Dict, with_valid=True): |
1261 | 1277 | if with_valid: |
|
0 commit comments