Commit 93d1e877 authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE

let the file be delete by any user

parent 6257feea
......@@ -1203,11 +1203,12 @@ class LiveInputVirusHostForm(forms.Form):
legend.append([m.name, m.value])
df_legend = pd.DataFrame(legend_name, columns=[str(_("Recommended responses scheme"))], index=legend_value)
filename = _('Template generated on %(date)s at %(time)s') % dict(
filename = 'Template generated on %(date)s at %(time)s' % dict(
date=timezone.now().strftime('%Y-%m-%d'),
time=timezone.now().strftime('%Hh%Mm%Ss'),
)
with pd.ExcelWriter(os.path.join(settings.MEDIA_ROOT, filename + ".xlsx")) as writer:
file_path = os.path.join(settings.MEDIA_ROOT, filename + ".xlsx")
with pd.ExcelWriter(file_path) as writer:
df_data = pd.DataFrame(
data=[["<response>"] * len(col_header)] * len(row_header),
columns=col_header,
......@@ -1215,6 +1216,7 @@ class LiveInputVirusHostForm(forms.Form):
)
df_data.to_excel(writer)
df_legend.to_excel(writer, startcol=1, startrow=len(row_header) + 3)
os.chmod(file_path, 0o777)
if len(col_header) > 4:
col_header = col_header[:4] + ['...', ]
......@@ -1226,14 +1228,15 @@ class LiveInputVirusHostForm(forms.Form):
data = [data] * 4 + [['...'] * len(data), ]
else:
data = [data, ] * len(row_header)
print(data)
with pd.ExcelWriter(os.path.join(settings.MEDIA_ROOT, filename + ".sample.xlsx")) as writer:
file_path = os.path.join(settings.MEDIA_ROOT, filename + ".sample.xlsx")
with pd.ExcelWriter(file_path) as writer:
df_data = pd.DataFrame(
data=data,
columns=col_header,
index=row_header,
)
df_data.to_excel(writer)
os.chmod(file_path, 0o777)
return dict(
file_url=settings.MEDIA_URL + filename + ".xlsx",
sample_path=os.path.join(settings.MEDIA_ROOT, filename + ".sample.xlsx"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment