feat(안내문 발송): DM 수동 보내기 — 이름 지우기·본문 편집·저장한 본문 목록
- 이름 목록: × 한 명씩 빼기·[전체 삭제], 이름 넣기는 목록에 더함
- 본문: 바로 고침(plaintext-only), {이름} 자리 = 분홍 칩, 이름 누르면 고친 글 + 이름 복사
- 저장한 본문(본문 오른쪽): 설정 DM 문구 + 저장한 것, 고르기·[저장]·[새 본문으로 저장]·× 지우기
- outreach_db 마이그레이션 002 outreach_dm_bodies + POST/PUT/DELETE /outreach/api/dm-bodies
(002 미적용이면 목록 안내만, API 503)
- 캐시 버전 20261030c, 단위·API·실제 PG·브라우저 테스트
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -22,9 +22,13 @@
|
||||
[DM 보내기] = 그 사람 이름이 든 문구 복사 + `https://ig.me/m/계정` 새 탭(누르는 순간 — 문구는 리스트 데이터에 미리 담음) → 붙여 넣어 보낸 뒤 [보냄](`dm-sent`, 기록).
|
||||
**DM 문구** = 설정 `dm_body`(글, `store.dm_text`, 최대 1000자 `DM_MAX`, `{이름}`, 별표만 뺌) — 비어 있으면 메일 본문 글 + 끝 문구. "이름 필요"도 구분별(`needs_name(t, kind)`).
|
||||
- **탭**(2026-10-30, `templates/outreach/_tabs.html`) — [발송 리스트](`/outreach/`) [DM 수동 보내기](`/outreach/dm`) + 맨 오른쪽 설정 톱니.
|
||||
- **DM 수동 보내기 탭** `/outreach/dm`(`dm.html`, 저장 없음 — 브라우저만) — 왼쪽 = 이름 넣기(붙여 넣기·.txt/.csv 첫 칸, 머리글 "이름"·빈 줄·같은 이름 뺌) + 이름 목록,
|
||||
오른쪽 = 본문. 이름을 누르면 본문 `{이름}` 이 그 이름으로 바뀌고 바로 클립보드 복사 + 짧은 안내(1.6초). 문구 = 설정 DM 문구
|
||||
(`dm_template` = `store.dm_text(template, NAME_TAG)`, 리스트 줄 [DM 보내기]와 같은 글). xlsx 는 이름 칸 복사해 붙여 넣기. JS `outreach.js initDm`.
|
||||
- **DM 수동 보내기 탭** `/outreach/dm`(`dm.html`, JS `outreach.js initDm`) — 3단:
|
||||
왼쪽 = 이름 넣기(붙여 넣기·.txt/.csv 첫 칸, 머리글 "이름"·빈 줄·이미 있는 이름 뺌, 넣을 때마다 목록에 더함) + 이름 목록(× 한 명씩·[전체 삭제], 브라우저만 — 저장 안 함),
|
||||
가운데 = 본문(`contenteditable="plaintext-only"`, 바로 고침, `{이름}` 자리 = 분홍 칩 — 직접 `{이름}` 이라 써도 됨), 오른쪽 = 저장한 본문 목록
|
||||
(맨 위 "설정 DM 문구(기본)" = `dm_template` = `store.dm_text(template, NAME_TAG)`, 그 아래 저장한 것 — 누르면 불러옴(고친 글 있으면 확인)·× 하나씩 지우기).
|
||||
이름을 누르면 칩이 그 이름으로 바뀌고 고친 글 + 이름을 바로 클립보드 복사 + 짧은 안내(1.6초). 글자 수 = 이름 넣은 글 기준, 1000자(`DM_MAX`) 넘으면 빨강.
|
||||
**저장한 본문** = outreach_db 마이그레이션 002 `outreach_dm_bodies`(모듈 권한자 모두 같은 목록, 제목 = 첫 글 줄 40자 `store.dm_saved_body`, 1000자까지):
|
||||
`POST /outreach/api/dm-bodies`(새 본문으로 저장)·`PUT …/{id}`(고른 본문 [저장])·`DELETE …/{id}` — 모두 `{items}` 돌려줌. 002 미적용이면 목록 안내만, API 503.
|
||||
- 설정 = 탭 줄 맨 오른쪽 톱니(`.otr-gear`, 공용 `vendor/material-symbols`). `.otr .erp-card[hidden]` — 공용 `.erp-card` display:flex 가 hidden 을 덮어
|
||||
[리스트 추가] 창이 늘 열려 있던 것 고침(2026-10-30).
|
||||
- **설정** `/outreach/settings`(모듈 권한자 누구나) — **세로 2단**: 왼쪽 메일(제목·"(광고)"·보내는 이름·본문 서식 편집기·끝 문구·본문 아래 사진),
|
||||
|
||||
@@ -10,6 +10,7 @@ from __future__ import annotations
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from psycopg.errors import UndefinedTable
|
||||
from psycopg.rows import dict_row
|
||||
from psycopg.types.json import Jsonb
|
||||
from psycopg_pool import ConnectionPool
|
||||
@@ -211,6 +212,36 @@ class OutreachDBStore:
|
||||
"WHERE status = '발송중'")
|
||||
return cur.rowcount
|
||||
|
||||
# ── DM 수동 보내기 탭의 저장한 본문(마이그레이션 002) ──────────
|
||||
def list_dm_bodies(self) -> list[dict[str, Any]] | None:
|
||||
"""새로 고친 것부터. 표가 없으면(002 미적용) None — 화면이 저장 목록만 숨긴다."""
|
||||
try:
|
||||
with self._pool.connection() as conn:
|
||||
rows = conn.execute("SELECT id, title, body, created_by, updated_by, updated_at FROM outreach_dm_bodies "
|
||||
"ORDER BY updated_at DESC, id DESC").fetchall()
|
||||
except UndefinedTable:
|
||||
return None
|
||||
return [{**dict(r), "id": int(r["id"]), "updated_at": _iso(r["updated_at"])} for r in rows]
|
||||
|
||||
def save_dm_body(self, body: Any, *, by: str, body_id: int | None = None) -> int:
|
||||
"""새로 저장(body_id 없음) 또는 그 본문 고치기. 저장한 id. 없는 id = KeyError."""
|
||||
title, text = store.dm_saved_body(body)
|
||||
by = (by or "").lower()
|
||||
with self._pool.connection() as conn:
|
||||
if body_id is None:
|
||||
return int(conn.execute(
|
||||
"INSERT INTO outreach_dm_bodies (title, body, created_by, updated_by) VALUES (%s, %s, %s, %s) RETURNING id",
|
||||
(title, text, by, by)).fetchone()["id"])
|
||||
row = conn.execute("UPDATE outreach_dm_bodies SET title = %s, body = %s, updated_by = %s, updated_at = now() "
|
||||
"WHERE id = %s RETURNING id", (title, text, by, body_id)).fetchone()
|
||||
if row is None:
|
||||
raise KeyError(body_id)
|
||||
return int(row["id"])
|
||||
|
||||
def delete_dm_body(self, body_id: int) -> None:
|
||||
with self._pool.connection() as conn:
|
||||
conn.execute("DELETE FROM outreach_dm_bodies WHERE id = %s", (body_id,))
|
||||
|
||||
def list_logs(self, *, limit: int = 200) -> list[dict[str, Any]]:
|
||||
with self._pool.connection() as conn:
|
||||
rows = conn.execute("SELECT * FROM outreach_logs ORDER BY sent_at DESC, id DESC LIMIT %s", (limit,)).fetchall()
|
||||
|
||||
@@ -141,18 +141,63 @@ def index(request: Request) -> Any:
|
||||
|
||||
@router.get("/dm", response_class=HTMLResponse)
|
||||
def dm_page(request: Request) -> Any:
|
||||
"""DM 수동 보내기 탭(2026-10-30) — 이름 목록 | 이름이 들어간 DM 문구(화면이 {이름} 을 바꿔 복사, 저장 없음)."""
|
||||
"""DM 수동 보내기 탭(2026-10-30) — 이름 목록 | 고칠 수 있는 본문(화면이 {이름} 을 바꿔 복사) | 저장한 본문 목록."""
|
||||
got = _page(request)
|
||||
if not isinstance(got, tuple):
|
||||
return got
|
||||
st, user = got
|
||||
return _render(request, "outreach/dm.html", user, {
|
||||
"page_title": "안내문 발송", "page_subtitle": "DM 수동 보내기", "active_tab": "dm",
|
||||
# {이름} 을 그대로 둔 DM 문구(리스트 줄 [DM 보내기]와 같은 글)
|
||||
# {이름} 을 그대로 둔 DM 문구(리스트 줄 [DM 보내기]와 같은 글) + 저장한 본문 목록(002 미적용 = None)
|
||||
"dm_template": store.dm_text(st.get_template(), store.NAME_TAG),
|
||||
"dm_bodies": st.list_dm_bodies(), "dm_max": store.DM_MAX,
|
||||
})
|
||||
|
||||
|
||||
_DM_BODIES_MIGRATION_MSG = "본문 저장 표가 없습니다 — outreach_db 마이그레이션 002(scripts/sql/outreach_db_002_dm_bodies.sql)를 적용하세요."
|
||||
|
||||
|
||||
def _dm_body_save(request: Request, payload: dict[str, Any], body_id: int | None) -> JSONResponse:
|
||||
from psycopg.errors import UndefinedTable # noqa: WPS433
|
||||
|
||||
user = _user(request)
|
||||
st = _db(request)
|
||||
try:
|
||||
saved = st.save_dm_body(payload.get("body"), by=user.get("email", ""), body_id=body_id)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc))
|
||||
except KeyError:
|
||||
raise HTTPException(status_code=404, detail="저장한 본문이 없습니다(다른 사람이 지웠을 수 있음).")
|
||||
except UndefinedTable:
|
||||
raise HTTPException(status_code=503, detail=_DM_BODIES_MIGRATION_MSG)
|
||||
return JSONResponse({"id": saved, "items": st.list_dm_bodies() or []})
|
||||
|
||||
|
||||
@router.post("/api/dm-bodies")
|
||||
def api_dm_body_add(request: Request, payload: dict[str, Any] = Body(...)) -> JSONResponse:
|
||||
"""DM 수동 보내기 — 본문 새로 저장(제목 = 첫 줄)."""
|
||||
return _dm_body_save(request, payload, None)
|
||||
|
||||
|
||||
@router.put("/api/dm-bodies/{body_id:int}")
|
||||
def api_dm_body_update(request: Request, body_id: int, payload: dict[str, Any] = Body(...)) -> JSONResponse:
|
||||
"""DM 수동 보내기 — 고른 저장 본문 고치기."""
|
||||
return _dm_body_save(request, payload, body_id)
|
||||
|
||||
|
||||
@router.delete("/api/dm-bodies/{body_id:int}")
|
||||
def api_dm_body_delete(request: Request, body_id: int) -> JSONResponse:
|
||||
from psycopg.errors import UndefinedTable # noqa: WPS433
|
||||
|
||||
_user(request)
|
||||
st = _db(request)
|
||||
try:
|
||||
st.delete_dm_body(body_id)
|
||||
except UndefinedTable:
|
||||
raise HTTPException(status_code=503, detail=_DM_BODIES_MIGRATION_MSG)
|
||||
return JSONResponse({"items": st.list_dm_bodies() or []})
|
||||
|
||||
|
||||
@router.get("/settings", response_class=HTMLResponse)
|
||||
def settings_page(request: Request) -> Any:
|
||||
got = _page(request)
|
||||
|
||||
@@ -195,6 +195,17 @@ def dm_text(template: dict[str, Any], name: str) -> str:
|
||||
return re.sub(r"\*\*(.+?)\*\*", r"\1", fill(dm, name))
|
||||
|
||||
|
||||
def dm_saved_body(value: Any) -> tuple[str, str]:
|
||||
"""DM 수동 보내기 탭에 저장할 본문 → (제목, 본문). 제목 = 첫 글 줄 40자(목록 표시용). 비었거나 너무 길면 ValueError."""
|
||||
body = str(value or "").replace("\r\n", "\n").strip()
|
||||
if not body:
|
||||
raise ValueError("본문을 쓰세요.")
|
||||
if len(body) > DM_MAX:
|
||||
raise ValueError(f"본문은 {DM_MAX}자까지입니다(인스타 DM 한도) — 지금 {len(body)}자.")
|
||||
title = next((ln.strip() for ln in body.split("\n") if ln.strip()), "")
|
||||
return (title[:40] + ("…" if len(title) > 40 else "")), body
|
||||
|
||||
|
||||
# ── 메일 본문 HTML ─────────────────────────────────────────
|
||||
_URL_RE = re.compile(r"https?://[^\s<>\"']+")
|
||||
_ALLOWED_TAGS = {"p", "br", "strong", "b", "em", "i", "u", "s", "strike", "span", "a", "ul", "ol", "li",
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{% extends "erp_base.html" %}
|
||||
|
||||
{#- DM 수동 보내기 탭(2026-10-30) — 왼쪽 = 이름 넣기(붙여 넣기·.txt/.csv 첫 칸) + 이름 목록, 오른쪽 = 설정의 DM 문구.
|
||||
이름을 누르면 오른쪽 문구의 {이름} 이 그 이름으로 바뀌고 바로 클립보드에 복사(리스트에는 저장하지 않음 — 리스트 줄의 [DM 보내기]와 같은 글). -#}
|
||||
{#- DM 수동 보내기 탭(2026-10-30) — 왼쪽 = 이름 넣기(붙여 넣기·.txt/.csv 첫 칸) + 이름 목록(한 명씩·전체 지우기),
|
||||
가운데 = 본문(고칠 수 있음, {이름} 자리는 분홍 이름 칩), 오른쪽 = 저장한 본문 목록(고르기·하나씩 지우기, outreach_db 002).
|
||||
이름을 누르면 본문의 {이름} 이 그 이름으로 바뀌고 바로 클립보드에 복사. 이름 목록은 저장하지 않음(브라우저만). -#}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/vendor/material-symbols/material-symbols.css" />
|
||||
<link rel="stylesheet" href="/static/outreach.css?v=20261030b" />{% endblock %}
|
||||
<link rel="stylesheet" href="/static/outreach.css?v=20261030c" />{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="otr otr-dm-page" id="otr-dm">
|
||||
@@ -17,19 +18,34 @@
|
||||
<div class="otr-add-actions">
|
||||
<button type="button" class="erp-btn erp-btn-primary" id="otr-dm-load">이름 넣기</button>
|
||||
<label class="erp-btn erp-btn-outline otr-dm-file">파일 올리기<input type="file" id="otr-dm-file" accept=".txt,.csv,text/plain,text/csv" hidden /></label>
|
||||
<span class="erp-muted" id="otr-dm-sum"></span>
|
||||
</div>
|
||||
<div class="otr-dm-listhead"><span class="erp-muted" id="otr-dm-sum">0명</span>
|
||||
<button type="button" class="erp-btn erp-btn-outline erp-btn-sm otr-danger" id="otr-dm-clear" disabled>전체 삭제</button></div>
|
||||
<ul class="otr-dm-names" id="otr-dm-names" aria-label="이름 목록"></ul>
|
||||
</div>
|
||||
|
||||
<div class="erp-card otr-dm-right">
|
||||
<div class="otr-add-head"><b>본문</b>
|
||||
<span class="erp-muted">왼쪽 이름을 누르면 그 이름이 들어간 글이 복사됩니다 — 인스타 DM 창에 붙여 넣으세요. 문구는 <a href="/outreach/settings">설정</a>의 DM 문구.</span></div>
|
||||
<div class="otr-dm-body" id="otr-dm-body" aria-live="polite"></div>
|
||||
<div class="otr-add-head"><b>본문 <span class="otr-dm-cur" id="otr-dm-cur"></span></b>
|
||||
<span class="erp-muted">바로 고칠 수 있습니다. 분홍 글자 = <code>{이름}</code> 자리(왼쪽 이름을 누르면 바뀌고 복사됨, 새 자리는 <code>{이름}</code> 이라고 쓰면 됨).</span></div>
|
||||
<div class="otr-add-actions otr-dm-actions">
|
||||
<button type="button" class="erp-btn erp-btn-primary" id="otr-dm-save" disabled title="오른쪽 목록에서 고른 본문을 이 글로 바꿉니다">저장</button>
|
||||
<button type="button" class="erp-btn erp-btn-outline" id="otr-dm-saveas">새 본문으로 저장</button>
|
||||
<span class="erp-muted" id="otr-dm-count"></span>
|
||||
</div>
|
||||
<div class="otr-dm-body" id="otr-dm-body" contenteditable="plaintext-only" spellcheck="false" role="textbox" aria-multiline="true" aria-label="본문"></div>
|
||||
</div>
|
||||
|
||||
<div class="erp-card otr-dm-saved">
|
||||
<div class="otr-add-head"><b>저장한 본문</b><span class="erp-muted">누르면 가운데 본문으로 불러옵니다.</span></div>
|
||||
{% if dm_bodies is none %}
|
||||
<p class="otr-msg">본문 저장 표가 아직 없습니다 — 관리자가 outreach_db 마이그레이션 002(<code>scripts/sql/outreach_db_002_dm_bodies.sql</code>)를 적용하면 저장할 수 있습니다.</p>
|
||||
{% endif %}
|
||||
<ul class="otr-dm-names otr-dm-bodies" id="otr-dm-bodies" aria-label="저장한 본문 목록"></ul>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<script type="application/json" id="otr-data">{{ {"dm_template": dm_template} | tojson }}</script>
|
||||
<script type="application/json" id="otr-data">{{ {"dm_template": dm_template, "dm_bodies": dm_bodies, "dm_max": dm_max} | tojson }}</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}<script src="/static/outreach.js?v=20261030b" defer></script>{% endblock %}
|
||||
{% block scripts %}<script src="/static/outreach.js?v=20261030c" defer></script>{% endblock %}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
{#- 안내문 발송(2026-10-27) — 리스트(주소 + 이름) → 메일은 [선택한 메일 보내기](본인 Gmail, 한 사람에 한 통), 인스타는 [DM 보내기](문구 복사 + DM 창)
|
||||
→ 보낸 뒤 [보냄]. 주소를 보고 메일/DM 을 정한다(store.detect). 본문 {이름} = 그 줄 이름. -#}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/vendor/material-symbols/material-symbols.css" />
|
||||
<link rel="stylesheet" href="/static/outreach.css?v=20261030b" />{% endblock %}
|
||||
<link rel="stylesheet" href="/static/outreach.css?v=20261030c" />{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="otr" id="otr" data-needs-name="{{ '1' if needs_name else '' }}">
|
||||
@@ -100,4 +100,4 @@
|
||||
<script type="application/json" id="otr-data">{{ {"rows": rows} | tojson }}</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}<script src="/static/outreach.js?v=20261030b" defer></script>{% endblock %}
|
||||
{% block scripts %}<script src="/static/outreach.js?v=20261030c" defer></script>{% endblock %}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
편집기 = Quill(/static/vendor/quill). 입력 칸은 form="otr-set-form" 으로 위 막대의 저장 폼에 묶는다(사진 폼과 겹치지 않게). -#}
|
||||
{% block head_extra %}
|
||||
<link rel="stylesheet" href="/static/vendor/quill/quill.snow.css" />
|
||||
<link rel="stylesheet" href="/static/outreach.css?v=20261030b" />
|
||||
<link rel="stylesheet" href="/static/outreach.css?v=20261030c" />
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
@@ -89,5 +89,5 @@
|
||||
|
||||
{% block scripts %}
|
||||
<script src="/static/vendor/quill/quill.js"></script>
|
||||
<script src="/static/outreach.js?v=20261030b" defer></script>
|
||||
<script src="/static/outreach.js?v=20261030c" defer></script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user