允许导出未核对课表
This commit is contained in:
+1
-1
@@ -50,7 +50,7 @@
|
|||||||
| `GET /api/timetables/export?format=json` | 完整结构,适合程序和AI读取 |
|
| `GET /api/timetables/export?format=json` | 完整结构,适合程序和AI读取 |
|
||||||
| `GET /api/timetables/export?format=csv` | 每个课表20行,便于表格整理 |
|
| `GET /api/timetables/export?format=csv` | 每个课表20行,便于表格整理 |
|
||||||
|
|
||||||
默认 `confirmed_only=true`,只导出已核对课表;传 `false` 可包含草稿。管理员密钥正确时导出全部成员,密钥错误或缺失时拒绝下载。JSON 中 `structure.cells` 每项包含 `day=1..5`、`slot`、`status=busy/free/unknown`、`courses`、`confidence`、`source` 和 `eligible`。时段时间见顶层 `slots`,记录的 `week_type` 为 `odd` / `even`。时间戳为 Unix 毫秒。
|
默认 `confirmed_only=false`,未核对课表和已核对课表都会导出;传 `true` 可只导出已核对课表。管理员密钥正确时导出全部成员,密钥错误或缺失时拒绝下载。JSON 中 `structure.cells` 每项包含 `day=1..5`、`slot`、`status=busy/free/unknown`、`courses`、`confidence`、`source` 和 `eligible`。时段时间见顶层 `slots`,记录的 `week_type` 为 `odd` / `even`。时间戳为 Unix 毫秒。
|
||||||
|
|
||||||
**排班时必须使用 `eligible=true` 的时段**,即课表已确认且该时段明确为空闲;没有上传、未核对、未知时段都不能视为有空。JSON 包含核对时间及整理结果,不以原图下载链接的可访问性判断空闲。CSV 为 UTF-8 BOM,保护可能被电子表格当作公式的文本内容。
|
**排班时必须使用 `eligible=true` 的时段**,即课表已确认且该时段明确为空闲;没有上传、未核对、未知时段都不能视为有空。JSON 包含核对时间及整理结果,不以原图下载链接的可访问性判断空闲。CSV 为 UTF-8 BOM,保护可能被电子表格当作公式的文本内容。
|
||||||
|
|
||||||
|
|||||||
Vendored
+2
-2
@@ -185,7 +185,7 @@
|
|||||||
<div class="page-head center-subhead"><div><h3>收取进度</h3><p class="muted" id="timetable-summary" role="status"></p></div></div>
|
<div class="page-head center-subhead"><div><h3>收取进度</h3><p class="muted" id="timetable-summary" role="status"></p></div></div>
|
||||||
<div class="filters center-toolbar"><input id="timetable-q" type="search" aria-label="搜索课表成员" placeholder="搜索姓名 / 部门" /><select id="timetable-filter" aria-label="课表提交状态"><option value="all">全部成员</option><option value="complete">单双周已交齐</option><option value="incomplete">尚未交齐</option><option value="missing">均未提交</option></select><button id="timetable-refresh" class="btn">刷新</button></div>
|
<div class="filters center-toolbar"><input id="timetable-q" type="search" aria-label="搜索课表成员" placeholder="搜索姓名 / 部门" /><select id="timetable-filter" aria-label="课表提交状态"><option value="all">全部成员</option><option value="complete">单双周已交齐</option><option value="incomplete">尚未交齐</option><option value="missing">均未提交</option></select><button id="timetable-refresh" class="btn">刷新</button></div>
|
||||||
<div id="timetable-members" class="card-list"></div>
|
<div id="timetable-members" class="card-list"></div>
|
||||||
<details class="center-export center-subhead"><summary>导出排班数据</summary><p class="muted" id="timetable-export-note"></p><div class="filters"><label>格式<select id="timetable-export-format"><option value="json">JSON</option><option value="csv">CSV</option></select></label><label class="checkline"><input id="timetable-confirmed-only" type="checkbox" checked /> 仅导出已核对课表</label><label class="timetable-admin-key-field">管理员密钥<input id="timetable-admin-key" type="password" autocomplete="off" autocapitalize="none" spellcheck="false" placeholder="输入后导出全部课表" required /></label><button id="timetable-export" class="btn primary">下载数据</button></div><p class="muted" id="timetable-export-status" role="status"></p></details>
|
<details class="center-export center-subhead"><summary>导出排班数据</summary><p class="muted" id="timetable-export-note"></p><div class="filters"><label>格式<select id="timetable-export-format"><option value="json">JSON</option><option value="csv">CSV</option></select></label><label class="checkline"><input id="timetable-confirmed-only" type="checkbox" /> 仅导出已核对课表</label><label class="timetable-admin-key-field">管理员密钥<input id="timetable-admin-key" type="password" autocomplete="off" autocapitalize="none" spellcheck="false" placeholder="输入后导出全部课表" required /></label><button id="timetable-export" class="btn primary">下载数据</button></div><p class="muted" id="timetable-export-status" role="status"></p></details>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
<main id="mine-view" class="view hidden">
|
<main id="mine-view" class="view hidden">
|
||||||
@@ -322,7 +322,7 @@
|
|||||||
|
|
||||||
<div id="toast" class="toast hidden" role="status" aria-live="polite"></div>
|
<div id="toast" class="toast hidden" role="status" aria-live="polite"></div>
|
||||||
|
|
||||||
<script src="/js/app.js?v=35"></script>
|
<script src="/js/app.js?v=36"></script>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1215,7 +1215,7 @@
|
|||||||
const label = `${weekLabel(week)}:${item.submitted ? item.confirmed ? '已核对' : '已交待核对' : '未交'}`;
|
const label = `${weekLabel(week)}:${item.submitted ? item.confirmed ? '已核对' : '已交待核对' : '未交'}`;
|
||||||
return item.submitted && person.can_read ? `<button class="btn sm" data-timetable-view="${week}" data-user-id="${person.id}">${label}</button>` : `<span class="tag ${item.submitted ? 'attended' : ''}">${label}</span>`;
|
return item.submitted && person.can_read ? `<button class="btn sm" data-timetable-view="${week}" data-user-id="${person.id}">${label}</button>` : `<span class="tag ${item.submitted ? 'attended' : ''}">${label}</span>`;
|
||||||
}).join('')}</div></article>`).join('') || '<div class="empty">没有符合筛选条件的成员。</div>';
|
}).join('')}</div></article>`).join('') || '<div class="empty">没有符合筛选条件的成员。</div>';
|
||||||
$('#timetable-export-note').textContent = '输入管理员密钥后可导出全部课表。只有已核对课表中的空闲时段可列为可值班,待确认不能当作空闲。';
|
$('#timetable-export-note').textContent = '输入管理员密钥后可导出全部课表;未核对课表也会包含。只有已核对课表中的空闲时段可列为可值班,待确认不能当作空闲。';
|
||||||
} catch (error) { if (version === timetableRequest) toast(error.message, true); }
|
} catch (error) { if (version === timetableRequest) toast(error.message, true); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -153,14 +153,14 @@ def install(app, get_db, current_user, file_root, collector_emails, admin_key):
|
|||||||
async def schema(viewer=Depends(current_user)):
|
async def schema(viewer=Depends(current_user)):
|
||||||
return {'schema_version': 1, 'week_types': {'odd': '单周', 'even': '双周'}, 'days': ocr.DAYS, 'slots': ocr.SLOTS,
|
return {'schema_version': 1, 'week_types': {'odd': '单周', 'even': '双周'}, 'days': ocr.DAYS, 'slots': ocr.SLOTS,
|
||||||
'states': {'busy': '有课', 'free': '无课', 'unknown': '待确认'},
|
'states': {'busy': '有课', 'free': '无课', 'unknown': '待确认'},
|
||||||
'export': {'url': '/api/timetables/export?format=json&confirmed_only=true', 'header': 'X-Timetable-Admin-Key',
|
'export': {'url': '/api/timetables/export?format=json&confirmed_only=false', 'header': 'X-Timetable-Admin-Key',
|
||||||
'scope': '管理员密钥验证通过后导出全部课表'},
|
'scope': '管理员密钥验证通过后导出全部课表'},
|
||||||
'privacy': '登录且管理员密钥正确时可导出全部课表;不包含邮箱、手机号和管理员密钥',
|
'privacy': '登录且管理员密钥正确时可导出全部课表;不包含邮箱、手机号和管理员密钥',
|
||||||
'eligibility': '仅已确认课表中的free时段可列为可值班;unknown不能当作空闲',
|
'eligibility': '仅已确认课表中的free时段可列为可值班;unknown不能当作空闲',
|
||||||
'scope': '按当前值班时间整理周一至周五的四个时段;完整识别文字另存raw_text,夜间和周末未参与可值班判断'}
|
'scope': '按当前值班时间整理周一至周五的四个时段;完整识别文字另存raw_text,夜间和周末未参与可值班判断'}
|
||||||
|
|
||||||
@app.get('/api/timetables/export')
|
@app.get('/api/timetables/export')
|
||||||
async def export(request: Request, format: Literal['json', 'csv'] = 'json', confirmed_only: bool = True,
|
async def export(request: Request, format: Literal['json', 'csv'] = 'json', confirmed_only: bool = False,
|
||||||
db=Depends(get_db), viewer=Depends(current_user)):
|
db=Depends(get_db), viewer=Depends(current_user)):
|
||||||
expected = admin_key()
|
expected = admin_key()
|
||||||
supplied = request.headers.get('X-Timetable-Admin-Key', '')
|
supplied = request.headers.get('X-Timetable-Admin-Key', '')
|
||||||
|
|||||||
@@ -141,15 +141,17 @@ class TimetableTests(ApiTestCase):
|
|||||||
self.assertEqual(result.status_code,422)
|
self.assertEqual(result.status_code,422)
|
||||||
duplicate = [item['structure']['cells'][0]]*20
|
duplicate = [item['structure']['cells'][0]]*20
|
||||||
self.assertEqual((await self.client.patch(path,headers=headers,json={'revision':item['revision'],'cells':duplicate})).status_code,422)
|
self.assertEqual((await self.client.patch(path,headers=headers,json={'revision':item['revision'],'cells':duplicate})).status_code,422)
|
||||||
self.assertEqual((await self.client.get('/api/timetables/export',headers=self.export_headers(owner))).json()['records'],[])
|
unconfirmed = (await self.client.get('/api/timetables/export',headers=self.export_headers(owner))).json()['records']
|
||||||
|
self.assertEqual(len(unconfirmed),3)
|
||||||
|
self.assertTrue(all(record['confirmed_at'] is None for record in unconfirmed))
|
||||||
result = await self.confirm(owner,item); self.assertEqual(result.status_code,200,result.text)
|
result = await self.confirm(owner,item); self.assertEqual(result.status_code,200,result.text)
|
||||||
data = await self.client.get('/api/timetables/export',headers=self.export_headers(owner))
|
data = await self.client.get('/api/timetables/export?confirmed_only=true',headers=self.export_headers(owner))
|
||||||
self.assertEqual(len(data.json()['records']),1); self.assertNotIn(owner['user']['email'],data.text)
|
self.assertEqual(len(data.json()['records']),1); self.assertNotIn(owner['user']['email'],data.text)
|
||||||
self.assertEqual(data.headers['cache-control'],'no-store')
|
self.assertEqual(data.headers['cache-control'],'no-store')
|
||||||
csv_response = await self.client.get('/api/timetables/export?format=csv',headers=self.export_headers(owner))
|
csv_response = await self.client.get('/api/timetables/export?format=csv&confirmed_only=true',headers=self.export_headers(owner))
|
||||||
rows = list(csv.DictReader(io.StringIO(csv_response.content.decode('utf-8-sig'))))
|
rows = list(csv.DictReader(io.StringIO(csv_response.content.decode('utf-8-sig'))))
|
||||||
self.assertEqual(len(rows),20); self.assertEqual(sum(row['eligible']=='True' for row in rows),19)
|
self.assertEqual(len(rows),20); self.assertEqual(sum(row['eligible']=='True' for row in rows),19)
|
||||||
all_records = (await self.client.get('/api/timetables/export?confirmed_only=false',headers=self.export_headers(owner))).json()['records']
|
all_records = (await self.client.get('/api/timetables/export',headers=self.export_headers(owner))).json()['records']
|
||||||
self.assertEqual(len(all_records),3)
|
self.assertEqual(len(all_records),3)
|
||||||
|
|
||||||
async def test_recognition_failure_preserves_image_for_manual_correction(self):
|
async def test_recognition_failure_preserves_image_for_manual_correction(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user