Feat: 내보내기 파일명을 탭이름_미배치/배치결과.xlsx로 변경, 중복 시 (숫자) 증가
This commit is contained in:
19
app.py
19
app.py
@@ -805,8 +805,17 @@ def export():
|
|||||||
wb = openpyxl.Workbook()
|
wb = openpyxl.Workbook()
|
||||||
wp_lookup = {wp['id']: wp for wp in t['workplaces']}
|
wp_lookup = {wp['id']: wp for wp in t['workplaces']}
|
||||||
tab_name = t['name']
|
tab_name = t['name']
|
||||||
fname = store.get('filename', 'export.xlsx')
|
|
||||||
base, ext = os.path.splitext(fname)
|
suffix_map = {'unassigned': '미배치', 'assigned': '배치결과', 'all': '배치결과'}
|
||||||
|
suffix = suffix_map.get(export_type, '배치결과')
|
||||||
|
|
||||||
|
def make_filename():
|
||||||
|
base = f'{tab_name}_{suffix}'
|
||||||
|
store.setdefault('export_seq', {})
|
||||||
|
key = base
|
||||||
|
seq = store['export_seq'].get(key, 0) + 1
|
||||||
|
store['export_seq'][key] = seq
|
||||||
|
return f'{base}.xlsx' if seq == 1 else f'{base} ({seq}).xlsx'
|
||||||
|
|
||||||
if export_type == 'unassigned':
|
if export_type == 'unassigned':
|
||||||
ws = wb.active
|
ws = wb.active
|
||||||
@@ -815,7 +824,6 @@ def export():
|
|||||||
for w in t['workers']:
|
for w in t['workers']:
|
||||||
if w['id'] not in t['assignments']:
|
if w['id'] not in t['assignments']:
|
||||||
ws.append([w['name'], w['hope'], w['address'], w['dob'], w['phone']])
|
ws.append([w['name'], w['hope'], w['address'], w['dob'], w['phone']])
|
||||||
dn = f'{base}_{tab_name}_미배치{ext}'
|
|
||||||
|
|
||||||
elif export_type == 'assigned':
|
elif export_type == 'assigned':
|
||||||
ws = wb.active
|
ws = wb.active
|
||||||
@@ -842,9 +850,8 @@ def export():
|
|||||||
aw = [w['name'] for w in t['workers'] if t['assignments'].get(w['id']) in g['workplace_ids']]
|
aw = [w['name'] for w in t['workers'] if t['assignments'].get(w['id']) in g['workplace_ids']]
|
||||||
if aw:
|
if aw:
|
||||||
ws2.append([combined_name, addr, len(aw), ', '.join(aw)])
|
ws2.append([combined_name, addr, len(aw), ', '.join(aw)])
|
||||||
dn = f'{base}_{tab_name}_배치결과{ext}'
|
|
||||||
|
|
||||||
else: # all (기존 동작)
|
else: # all (전체)
|
||||||
ws1 = wb.active
|
ws1 = wb.active
|
||||||
ws1.title = '배치 현황'
|
ws1.title = '배치 현황'
|
||||||
ws1.append(['이름', '연락처', '생년월일', '희망사항', '주소', '배치근무지', '근무지주소'])
|
ws1.append(['이름', '연락처', '생년월일', '희망사항', '주소', '배치근무지', '근무지주소'])
|
||||||
@@ -866,11 +873,11 @@ def export():
|
|||||||
combined_name = ', '.join(g['names'])
|
combined_name = ', '.join(g['names'])
|
||||||
aw = [w['name'] for w in t['workers'] if t['assignments'].get(w['id']) in g['workplace_ids']]
|
aw = [w['name'] for w in t['workers'] if t['assignments'].get(w['id']) in g['workplace_ids']]
|
||||||
ws2.append([combined_name, addr, len(aw), ', '.join(aw)])
|
ws2.append([combined_name, addr, len(aw), ', '.join(aw)])
|
||||||
dn = f'{base}_{tab_name}_배치결과{ext}'
|
|
||||||
|
|
||||||
buf = io.BytesIO()
|
buf = io.BytesIO()
|
||||||
wb.save(buf)
|
wb.save(buf)
|
||||||
buf.seek(0)
|
buf.seek(0)
|
||||||
|
dn = make_filename()
|
||||||
return send_file(buf, as_attachment=True, download_name=dn,
|
return send_file(buf, as_attachment=True, download_name=dn,
|
||||||
mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user