(self, *, instance=None, raise_exception=True)
| 1206 | knowledge_id = serializers.UUIDField(required=True, label=_("knowledge id")) |
| 1207 | |
| 1208 | def is_valid(self, *, instance=None, raise_exception=True): |
| 1209 | super().is_valid(raise_exception=True) |
| 1210 | workspace_id = self.data.get("workspace_id") |
| 1211 | query_set = QuerySet(Knowledge).filter(id=self.data.get("knowledge_id")) |
| 1212 | if workspace_id: |
| 1213 | query_set = query_set.filter(workspace_id=workspace_id) |
| 1214 | if not query_set.exists(): |
| 1215 | raise AppApiException(500, _("Knowledge id does not exist")) |
| 1216 | files = instance.get("file") |
| 1217 | knowledge = Knowledge.objects.filter(id=self.data.get("knowledge_id")).first() |
| 1218 | for f in files: |
| 1219 | if f.size > 1024 * 1024 * knowledge.file_size_limit: |
| 1220 | raise AppApiException( |
| 1221 | 500, |
| 1222 | _("The maximum size of the uploaded file cannot exceed {}MB").format(knowledge.file_size_limit), |
| 1223 | ) |
| 1224 | |
| 1225 | def parse(self, instance): |
| 1226 | self.is_valid(instance=instance, raise_exception=True) |
no test coverage detected