Files
duty-calendar/server/personal.py
T
블리어 8112721fa8 당직근무 0.10.0 소스와 위젯 꾸미기 및 제작 매뉴얼 공개
위젯별 투명도와 밝은·어두운 색상 및 글자 크기와 표시 항목을 추가했다.
모든 위젯에 함께 적용하는 기본값과 개별 설정을 구분하고 크기에 따라 배치를 바꾼다.
포럼에 APK와 전체 소스 및 사용법과 제작 매뉴얼을 함께 배포한다.

앱 단위 검사 34개와 서버 검사 63개 및 웹 날짜·업데이트 검사 통과.
공개 소스에서 APK 빌드와 정적 검사 오류 0개 확인. 경고는 69개다.
Android 16 가상 기기에서 기존 앱 위에 설치하고 투명 위젯과 큰 글자 및 RemoteViews 검사를 확인했다.
실제 휴대폰과 다른 홈 화면 앱의 절전·크기 동작은 별도 확인이 필요하다.
회원 DB와 인증 정보 및 배포 서명 키와 내부 운영 기록은 공개 자료에 포함하지 않았다.
2026-11-20 10:00:42 +00:00

65 lines
3.9 KiB
Python

"""회원의 기념일과 표시 설정을 검증한다. 모든 조회와 쓰기의 소유 범위는 인증된 캘린더다."""
from datetime import date
import json
DISPLAY_FIELDS = ('dutyAsWeekday', 'showLunar', 'offAsHoliday')
REMINDER_MINUTES = (-1, 0, 10, 30, 60, 1440)
def validate_reminder(data):
value=data.get('reminderMinutes',-1)
if type(value) is not int or value not in REMINDER_MINUTES:
raise ValueError('알림 시간을 확인해 주세요.')
return value
def validate_event_options(data):
frequency=data.get('repeat','NONE');until=data.get('repeatUntil','')
if frequency not in ('NONE','DAILY','WEEKLY','MONTHLY','YEARLY') or not isinstance(until,str):
raise ValueError('일정 반복 종류와 종료일을 확인해 주세요.')
if until:
parsed=date.fromisoformat(until)
if parsed.isoformat()!=until or not 2000<=parsed.year<=2099 or parsed<date.fromisoformat(data['date']):
raise ValueError('반복 종료일은 시작 날짜 이후로 지정해 주세요.')
return {'repeat':frequency,'repeatUntil':until if frequency!='NONE' else '', 'reminderMinutes':validate_reminder(data)}
def validate_personal(kind, data):
if kind == 'preferences':
if any(type(data.get(key)) is not bool for key in DISPLAY_FIELDS):
raise ValueError('개인 표시 설정을 확인해 주세요.')
return {key: data[key] for key in DISPLAY_FIELDS}
if not isinstance(data.get('title'), str) or not 1 <= len(data['title'].strip()) <= 60:
raise ValueError('기념일 이름은 1~60자로 입력해 주세요.')
if data.get('category') not in ('BIRTHDAY', 'ANNIVERSARY') or data.get('calendar') not in ('SOLAR', 'LUNAR'):
raise ValueError('기념일 종류와 양력·음력을 선택해 주세요.')
if type(data.get('month')) is not int or not 1 <= data['month'] <= 12 or type(data.get('day')) is not int or not 1 <= data['day'] <= 31:
raise ValueError('기념일의 월과 일을 확인해 주세요.')
if type(data.get('leapMonth')) is not bool or (data['calendar'] == 'SOLAR' and data['leapMonth']):
raise ValueError('윤달은 음력 기념일에서만 선택할 수 있습니다.')
if data['calendar'] == 'SOLAR':
date(2000, data['month'], data['day'])
elif data['day'] > 30:
raise ValueError('음력 날짜는 1~30일로 입력해 주세요.')
if not isinstance(data.get('notes'), str) or len(data['notes']) > 1000:
raise ValueError('메모는 1000자까지 입력할 수 있습니다.')
return {**{key: data[key].strip() if key == 'title' else data[key] for key in ('title','category','calendar','month','day','leapMonth','notes')}, 'reminderMinutes':validate_reminder(data)}
def mirror_display(conn, calendar, kind, data):
"""구버전의 근무표 안 표시 항목과 별도 개인 설정을 같은 트랜잭션에서 맞춘다.
반대 항목도 버전을 올려 오래된 기기가 새 선택을 덮어쓰지 못하게 한다.
기존 회원에게 일괄 기본값을 넣지 않는다. 실제 저장한 선택만 복제한다.
"""
if kind not in ('rotation', 'preferences'):
return
target = 'rotation' if kind == 'preferences' else 'preferences'
current = conn.execute('SELECT data,version FROM items WHERE calendar=? AND id=? AND deleted=0', (calendar,target)).fetchone()
# 구버전의 기존 근무 저장만으로 별도 설정을 새로 만들지 않는다.
if not current:
return
saved = json.loads(current['data'])
values = {key: data[key] for key in DISPLAY_FIELDS if type(data.get(key)) is bool}
if not values or all(saved.get(key) == value for key,value in values.items()):
return
saved.update(values)
conn.execute('UPDATE items SET data=?,version=version+1 WHERE calendar=? AND id=?', (json.dumps(saved,ensure_ascii=False),calendar,target))
conn.execute('UPDATE calendars SET revision=revision+1 WHERE id=?', (calendar,))