m1m02530125 Claude Sonnet 4.6 commited on
Commit
55415eb
·
1 Parent(s): a4e9a81

祝日を日曜と同じ色で表示する(jpholiday連携)

Browse files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

requirements.txt CHANGED
@@ -5,4 +5,5 @@ reportlab>=4.0.0
5
  PyInstaller>=6.0.0
6
  flask>=3.0.0
7
  gunicorn>=21.0.0
 
8
  psycopg2-binary>=2.9.0
 
5
  PyInstaller>=6.0.0
6
  flask>=3.0.0
7
  gunicorn>=21.0.0
8
+ jpholiday>=0.1.0
9
  psycopg2-binary>=2.9.0
routes/schedule.py CHANGED
@@ -4,6 +4,14 @@ from db import repositories as repo
4
  from models.schedule import ShiftAssignment
5
  from utils.constants import TimeSlot, Position, EmploymentType
6
 
 
 
 
 
 
 
 
 
7
 
8
  def _compute_staffing(assignments, employees, dates, constraints) -> dict:
9
  """
@@ -172,6 +180,8 @@ def index(period_id):
172
 
173
  needs_regen = repo.get_period_gen_status(period_id).get("needs_regen", False)
174
 
 
 
175
  # 社員デフォルト勤務時間(ポジション別・設定画面で変更可能)
176
  def _ft_time(pos_key, slot_key):
177
  s = repo.get_app_setting(f"ft_{pos_key}_{slot_key}_start",
@@ -205,6 +215,7 @@ def index(period_id):
205
  needs_regen=needs_regen,
206
  today=today,
207
  ft_times=ft_times,
 
208
  TimeSlot=TimeSlot,
209
  Position=Position,
210
  )
 
4
  from models.schedule import ShiftAssignment
5
  from utils.constants import TimeSlot, Position, EmploymentType
6
 
7
+ try:
8
+ import jpholiday as _jpholiday
9
+ def _is_holiday(d) -> bool:
10
+ return bool(_jpholiday.is_holiday(d))
11
+ except ImportError:
12
+ def _is_holiday(d) -> bool:
13
+ return False
14
+
15
 
16
  def _compute_staffing(assignments, employees, dates, constraints) -> dict:
17
  """
 
180
 
181
  needs_regen = repo.get_period_gen_status(period_id).get("needs_regen", False)
182
 
183
+ holidays = {d.isoformat() for d in dates if _is_holiday(d)}
184
+
185
  # 社員デフォルト勤務時間(ポジション別・設定画面で変更可能)
186
  def _ft_time(pos_key, slot_key):
187
  s = repo.get_app_setting(f"ft_{pos_key}_{slot_key}_start",
 
215
  needs_regen=needs_regen,
216
  today=today,
217
  ft_times=ft_times,
218
+ holidays=holidays,
219
  TimeSlot=TimeSlot,
220
  Position=Position,
221
  )
templates/schedule/index.html CHANGED
@@ -107,12 +107,15 @@
107
  display: flex; gap: 6px; margin-top: .5rem; padding-top: .4rem;
108
  border-top: 1px solid #334155;
109
  }
110
- /* 土日ヘッダーの文字色:背景が薄いため濃色に */
111
  .sched-grid thead th.sat { color: #1e40af !important; }
112
  .sched-grid thead th.sun { color: #be123c !important; }
113
  /* 今日 + 土日が重なるケースの文字保証 */
114
  .sched-grid thead th.today-col.sat,
115
  .sched-grid thead th.today-col.sun { color: white !important; }
 
 
 
116
  .chip-hall { background: #dbeafe; color: #1e40af; border-radius: 4px; padding: 1px 5px; font-size: .75rem; }
117
  .chip-kitchen { background: #dcfce7; color: #166534; border-radius: 4px; padding: 1px 5px; font-size: .75rem; }
118
  .chip-empty { color: #cbd5e1; }
@@ -307,13 +310,15 @@
307
  {% for d in dates %}
308
  {% set dow = d.weekday() %}
309
  {% set ds_h = d.isoformat() %}
 
310
  {% set st = staffing.get((ds_h, slot, pos), {}) %}
311
  {% set hdr_cls = 'short-staff' if st.get('short_staff') else 'short-leader' if st.get('short_leader') else '' %}
312
  {% set is_today = ds_h == today %}
313
- <th class="text-center {{ 'sat' if dow == 5 else 'sun' if dow == 6 else '' }} {{ hdr_cls }} {{ 'today-col' if is_today else '' }}"
 
314
  style="cursor:pointer" onclick="openTimeline('{{ ds_h }}')">
315
  {{ '★ ' if is_today else '' }}{{ d.strftime('%m/%d') }}<br>
316
- <small>{{ ['月','火','水','木','金','土','日'][dow] }}</small>
317
  {% if st %}
318
  {% set badge_cls = 'count-short' if st.short_staff else 'count-leader' if st.short_leader else 'count-ok' %}
319
  <span class="count-badge {{ badge_cls }}">{{ st.count }}/{{ st.min }}</span>
@@ -329,7 +334,9 @@
329
  {% for d in dates %}
330
  {% set ds = d|string %}
331
  {% set dow = d.weekday() %}
332
- <td class="text-center {{ 'sat' if dow == 5 else 'sun' if dow == 6 else '' }}" style="min-width:70px">
 
 
333
  <span class="note-cell d-block small text-muted" style="cursor:pointer;min-height:18px"
334
  data-date="{{ ds }}" data-period="{{ period.id }}"
335
  onclick="editNote(this)">{{ notes.get(ds, '') or '' }}</span>
@@ -345,6 +352,7 @@
345
  {% for d in dates %}
346
  {% set ds = d|string %}
347
  {% set dow = d.weekday() %}
 
348
  {% set day_assignments = asgn_map.get(ds, {}).get(slot, []) %}
349
  {% set emp_asgn = day_assignments | selectattr('employee_id', 'equalto', emp.id) | selectattr('position.value', 'equalto', pos) | list | first %}
350
  {# 社員はポジション別デフォルトスロット時間を使用(設定画面で変更可) #}
@@ -352,7 +360,7 @@
352
  {% set default_slot_time = ft_times.get(pos, ft_times['hall'])[slot] %}
353
  {% set req_time = time_map.get((emp.id, ds, slot), '') %}
354
  {% set display_time = req_time if req_time else (default_slot_time if is_ft else '') %}
355
- <td class="text-center {{ 'sat' if dow == 5 else 'sun' if dow == 6 else '' }} {{ 'today-col' if ds == today else '' }} assign-cell"
356
  style="cursor:pointer"
357
  data-emp-id="{{ emp.id }}"
358
  data-emp-name="{{ emp.name }}"
 
107
  display: flex; gap: 6px; margin-top: .5rem; padding-top: .4rem;
108
  border-top: 1px solid #334155;
109
  }
110
+ /* 土日・祝日ヘッダーの文字色:背景が薄いため濃色に */
111
  .sched-grid thead th.sat { color: #1e40af !important; }
112
  .sched-grid thead th.sun { color: #be123c !important; }
113
  /* 今日 + 土日が重なるケースの文字保証 */
114
  .sched-grid thead th.today-col.sat,
115
  .sched-grid thead th.today-col.sun { color: white !important; }
116
+ /* 祝日は sun クラスと共有だが、土曜祝日は sun 色を優先 */
117
+ .sat.sun { background: #fff1f2 !important; }
118
+ .sched-grid thead th.sat.sun { color: #be123c !important; }
119
  .chip-hall { background: #dbeafe; color: #1e40af; border-radius: 4px; padding: 1px 5px; font-size: .75rem; }
120
  .chip-kitchen { background: #dcfce7; color: #166534; border-radius: 4px; padding: 1px 5px; font-size: .75rem; }
121
  .chip-empty { color: #cbd5e1; }
 
310
  {% for d in dates %}
311
  {% set dow = d.weekday() %}
312
  {% set ds_h = d.isoformat() %}
313
+ {% set is_holiday = ds_h in holidays %}
314
  {% set st = staffing.get((ds_h, slot, pos), {}) %}
315
  {% set hdr_cls = 'short-staff' if st.get('short_staff') else 'short-leader' if st.get('short_leader') else '' %}
316
  {% set is_today = ds_h == today %}
317
+ {% set day_cls = 'sun' if (dow == 6 or is_holiday) else 'sat' if dow == 5 else '' %}
318
+ <th class="text-center {{ day_cls }} {{ hdr_cls }} {{ 'today-col' if is_today else '' }}"
319
  style="cursor:pointer" onclick="openTimeline('{{ ds_h }}')">
320
  {{ '★ ' if is_today else '' }}{{ d.strftime('%m/%d') }}<br>
321
+ <small>{{ ['月','火','水','木','金','土','日'][dow] }}{{ '(祝)' if is_holiday else '' }}</small>
322
  {% if st %}
323
  {% set badge_cls = 'count-short' if st.short_staff else 'count-leader' if st.short_leader else 'count-ok' %}
324
  <span class="count-badge {{ badge_cls }}">{{ st.count }}/{{ st.min }}</span>
 
334
  {% for d in dates %}
335
  {% set ds = d|string %}
336
  {% set dow = d.weekday() %}
337
+ {% set is_holiday = ds in holidays %}
338
+ {% set day_cls = 'sun' if (dow == 6 or is_holiday) else 'sat' if dow == 5 else '' %}
339
+ <td class="text-center {{ day_cls }}" style="min-width:70px">
340
  <span class="note-cell d-block small text-muted" style="cursor:pointer;min-height:18px"
341
  data-date="{{ ds }}" data-period="{{ period.id }}"
342
  onclick="editNote(this)">{{ notes.get(ds, '') or '' }}</span>
 
352
  {% for d in dates %}
353
  {% set ds = d|string %}
354
  {% set dow = d.weekday() %}
355
+ {% set is_holiday = ds in holidays %}
356
  {% set day_assignments = asgn_map.get(ds, {}).get(slot, []) %}
357
  {% set emp_asgn = day_assignments | selectattr('employee_id', 'equalto', emp.id) | selectattr('position.value', 'equalto', pos) | list | first %}
358
  {# 社員はポジション別デフォルトスロット時間を使用(設定画面で変更可) #}
 
360
  {% set default_slot_time = ft_times.get(pos, ft_times['hall'])[slot] %}
361
  {% set req_time = time_map.get((emp.id, ds, slot), '') %}
362
  {% set display_time = req_time if req_time else (default_slot_time if is_ft else '') %}
363
+ <td class="text-center {{ 'sun' if (dow == 6 or is_holiday) else 'sat' if dow == 5 else '' }} {{ 'today-col' if ds == today else '' }} assign-cell"
364
  style="cursor:pointer"
365
  data-emp-id="{{ emp.id }}"
366
  data-emp-name="{{ emp.name }}"