Refactor: 템플릿 없으면 배치된 근로자만 기본 리스트 출력

This commit is contained in:
user01
2026-05-25 00:55:26 +09:00
parent 8c3e53b017
commit 1114aa908c

29
app.py
View File

@@ -830,9 +830,7 @@ def export():
wp_filename = t.get('workplace_filename', '') wp_filename = t.get('workplace_filename', '')
base = os.path.splitext(wp_filename)[0] base = os.path.splitext(wp_filename)[0]
template_path = f'{base}_template.xlsx' if base else '' template_path = f'{base}_template.xlsx' if base else ''
if not template_path or not os.path.exists(template_path): if template_path and os.path.exists(template_path):
template_path = '선거참관인_배치_와꾸_.xlsx'
if os.path.exists(template_path):
wb = openpyxl.load_workbook(template_path) wb = openpyxl.load_workbook(template_path)
wp_workers = {} wp_workers = {}
for w in t['workers']: for w in t['workers']:
@@ -882,6 +880,31 @@ def export():
wn = wp_lookup[a_id]['name'] if a_id in wp_lookup else '' wn = wp_lookup[a_id]['name'] if a_id in wp_lookup else ''
wa = wp_lookup[a_id]['address'] if a_id in wp_lookup else '' wa = wp_lookup[a_id]['address'] if a_id in wp_lookup else ''
ws_extra.append([w['name'], w['phone'], w['dob'], w['hope'], w['address'], wn, wa]) ws_extra.append([w['name'], w['phone'], w['dob'], w['hope'], w['address'], wn, wa])
else:
# 템플릿 없으면 배치된 근로자만 기본 리스트 출력
ws1 = wb.active
ws1.title = '배치 현황'
ws1.append(['이름', '연락처', '생년월일', '희망사항', '주소', '배치근무지', '근무지주소'])
for w in t['workers']:
a_id = t['assignments'].get(w['id'])
if not a_id:
continue
wn = wp_lookup[a_id]['name'] if a_id in wp_lookup else ''
wa = wp_lookup[a_id]['address'] if a_id in wp_lookup else ''
ws1.append([w['name'], w['phone'], w['dob'], w['hope'], w['address'], wn, wa])
ws2 = wb.create_sheet('근무지별 배치')
ws2.append(['근무지명', '주소', '배치인원', '배치된근무자'])
addr_groups = {}
for wp in t['workplaces']:
key = wp['address']
if key not in addr_groups:
addr_groups[key] = {'names': [], 'workplace_ids': []}
addr_groups[key]['names'].append(wp['name'])
addr_groups[key]['workplace_ids'].append(wp['id'])
for addr, g in addr_groups.items():
combined_name = ', '.join(g['names'])
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)])
else: # all (전체) else: # all (전체)
ws1 = wb.active ws1 = wb.active