MCPcopy
hub / github.com/1Panel-dev/MaxKB / export

Method export

apps/knowledge/serializers/document.py:271–310  ·  view source on GitHub ↗
(self, with_valid=True)

Source from the content-addressed store, hash-verified

269 )
270
271 def export(self, with_valid=True):
272 if with_valid:
273 self.is_valid(raise_exception=True)
274 language = get_language()
275 if self.data.get("type") == "csv":
276 file = open(
277 os.path.join(
278 PROJECT_DIR, "apps", "knowledge", "template", f"csv_template_{language}.csv"
279 ),
280 "rb",
281 )
282 content = file.read()
283 file.close()
284 return HttpResponse(
285 content,
286 status=200,
287 headers={
288 "Content-Type": "text/csv",
289 "Content-Disposition": 'attachment; filename="csv_template.csv"',
290 },
291 )
292 elif self.data.get("type") == "excel":
293 file = open(
294 os.path.join(
295 PROJECT_DIR, "apps", "knowledge", "template", f"excel_template_{language}.xlsx"
296 ),
297 "rb",
298 )
299 content = file.read()
300 file.close()
301 return HttpResponse(
302 content,
303 status=200,
304 headers={
305 "Content-Type": "application/vnd.ms-excel",
306 "Content-Disposition": 'attachment; filename="excel_template.xlsx"',
307 },
308 )
309 else:
310 return None
311
312 def table_export(self, with_valid=True):
313 if with_valid:

Callers 4

getMethod · 0.45
getMethod · 0.45
getMethod · 0.45
postMethod · 0.45

Calls 5

readMethod · 0.80
openFunction · 0.50
is_validMethod · 0.45
getMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected