공지사항관리 기능 분리 및 개선
All checks were successful
Build And Test / build-and-push (push) Successful in 4m23s
All checks were successful
Build And Test / build-and-push (push) Successful in 4m23s
This commit is contained in:
72
board_notice/templates/board_notice/create_notice.html
Normal file
72
board_notice/templates/board_notice/create_notice.html
Normal file
@ -0,0 +1,72 @@
|
||||
{% extends "components/base.html" %}
|
||||
{% block title %}Create Notice{% endblock %}
|
||||
|
||||
{% block main_area %}
|
||||
<h1 class="pt-3">Create New Notice</h1>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<form method="POST" id="post-form">
|
||||
{% csrf_token %}
|
||||
<div class="mb-3">
|
||||
{{ form.title.label_tag }}
|
||||
{{ form.title }}
|
||||
</div>
|
||||
|
||||
<!-- 마크다운 에디터 -->
|
||||
<h2>Contents</h2>
|
||||
|
||||
<div class="col-md-12">
|
||||
{{ form.contents }}
|
||||
</div>
|
||||
<!-- 버튼 -->
|
||||
<div class="d-flex justify-content-end mt-4">
|
||||
<button type="submit" class="btn btn-primary me-2">Create Notice</button>
|
||||
<a href="{% url 'board_notice:notice_list' %}" class="btn btn-secondary">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div id="preview" class="border p-3 bg-light h-100 overflow-auto"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 마크다운 파서 및 스크립트 -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/markdown-it/dist/markdown-it.min.js"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github-dark.min.css">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
|
||||
<script>
|
||||
// 마크다운 파서 초기화
|
||||
const md = window.markdownit({
|
||||
highlight: function (str, lang) {
|
||||
if (lang && hljs.getLanguage(lang)) {
|
||||
try {
|
||||
return hljs
|
||||
.highlight(str, {language: lang})
|
||||
.value;
|
||||
} catch (__) {}
|
||||
}
|
||||
return ''; // 기본 HTML 이스케이프 처리
|
||||
}
|
||||
});
|
||||
|
||||
// content 필드와 미리보기 연결
|
||||
const textarea = document.getElementById("markdown-editor");
|
||||
const preview = document.getElementById("preview");
|
||||
|
||||
// 실시간 미리보기 업데이트
|
||||
textarea.addEventListener("input", function () {
|
||||
const markdownContent = textarea.value; // textarea 내용 가져오기
|
||||
const renderedContent = md.render(markdownContent); // 마크다운 -> HTML 변환
|
||||
preview.innerHTML = renderedContent;
|
||||
|
||||
// Highlight.js로 코드 블록 강조
|
||||
document
|
||||
.querySelectorAll("#preview pre code")
|
||||
.forEach((block) => {
|
||||
hljs.highlightElement(block);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
{% endblock %}
|
56
board_notice/templates/board_notice/notice_detail.html
Normal file
56
board_notice/templates/board_notice/notice_detail.html
Normal file
@ -0,0 +1,56 @@
|
||||
{% extends "components/base.html" %}
|
||||
{% block title %}Notice{% endblock %}
|
||||
|
||||
{% block main_area %}
|
||||
<!-- Title -->
|
||||
<h1 class="mt-4">{{ notice.title }}</h1>
|
||||
<!-- Author -->
|
||||
<div class="text-muted fst-italic mb-2">{{ notice.created_at }}
|
||||
<br>
|
||||
by.
|
||||
{{ notice.author | upper }}</div>
|
||||
<!-- Rendered Markdown Content -->
|
||||
<div>
|
||||
{{ notice.render_markdown|safe }}
|
||||
</div>
|
||||
<hr>
|
||||
|
||||
{% if request.user == notice.author %}
|
||||
<div class="d-flex mt-3">
|
||||
<a href="{% url 'board_notice:notice_list' %}" class="btn btn-secondary me-2">List</a>
|
||||
<a href="{% url 'board_notice:update_notice' notice.pk %}" class="btn btn-warning me-2">Edit</a>
|
||||
<form method="POST" action="{% url 'board_notice:delete_notice' notice.pk %}" class="d-inline" id="delete-form">
|
||||
{% csrf_token %}
|
||||
<button type="button" class="btn btn-danger" id="delete-button">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Highlight.js Styles -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github-dark.min.css">
|
||||
<!-- Highlight.js Script -->
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
|
||||
<script>
|
||||
// Initialize Highlight.js
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
document
|
||||
.querySelectorAll("pre code")
|
||||
.forEach((block) => {
|
||||
hljs.highlightElement(block);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<!-- Delete Notice -->
|
||||
<script>
|
||||
document
|
||||
.getElementById("delete-button")
|
||||
.addEventListener("click", function () {
|
||||
const confirmed = confirm("Are you sure you want to delete this Notice?");
|
||||
if (confirmed) {
|
||||
document
|
||||
.getElementById("delete-form")
|
||||
.submit();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
48
board_notice/templates/board_notice/notice_list.html
Normal file
48
board_notice/templates/board_notice/notice_list.html
Normal file
@ -0,0 +1,48 @@
|
||||
{% extends "components/base.html" %}
|
||||
|
||||
{% block title %}Notice{% endblock %}
|
||||
|
||||
{% block main_area %}
|
||||
<h2 class="fw-bold pt-3 pb-2 d-flex justify-content-between">
|
||||
공지사항
|
||||
|
||||
</h2>
|
||||
<!-- 공지사항 목록 -->
|
||||
|
||||
{% if notices %}
|
||||
<table class="table table-bordered table-hover">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th scope="col">글번호</th>
|
||||
<th scope="col">제목</th>
|
||||
<th scope="col">내용</th>
|
||||
<th scope="col">작성자</th>
|
||||
<th scope="col">작성일</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for record in notices %}
|
||||
<tr>
|
||||
<td>{{ record.pk }}</td>
|
||||
<td>
|
||||
<a href="{{ record.get_absolute_url }}">{{ record.title }}</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="{{ record.get_absolute_url }}">{{ record.contents|truncatechars:50 }}</a>
|
||||
</td>
|
||||
<td>{{ record.author }}</td>
|
||||
<td>{{ record.created_at|date:"Y-m-d H:i" }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p class="text-muted">현재 공지사항이 없습니다.</p>
|
||||
{% endif %}
|
||||
{% if request.user.is_authenticated %}
|
||||
<!-- 버튼 컨테이너 -->
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<a href="{% url 'board_notice:create_notice' %}" class="btn btn-primary">Create Notice</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
58
board_notice/templates/board_notice/update_notice.html
Normal file
58
board_notice/templates/board_notice/update_notice.html
Normal file
@ -0,0 +1,58 @@
|
||||
{% extends "components/base.html" %}
|
||||
{% block title %}Update Post{% endblock %}
|
||||
|
||||
{% block main_area %}
|
||||
<h1 class="pt-3">Update Post</h1>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<form method="POST" id="post-form">
|
||||
{% csrf_token %}
|
||||
<div class="mb-3">
|
||||
{{ form.title.label_tag }}
|
||||
{{ form.title }}
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
{{ form.summary.label_tag }}
|
||||
{{ form.summary }}
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
{{ form.tags.label_tag }}
|
||||
{{ form.tags }}
|
||||
</div>
|
||||
|
||||
<!-- 마크다운 에디터 -->
|
||||
<h2>Contents</h2>
|
||||
<div class="col-md-12">
|
||||
{{ form.contents }}
|
||||
</div>
|
||||
<!-- 버튼 -->
|
||||
<div class="d-flex justify-content-end mt-4">
|
||||
<button type="submit" class="btn btn-primary me-2">Save Changes</button>
|
||||
<a href="{% url 'blog:post_list' %}" class="btn btn-secondary">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div id="preview" class="border p-3 bg-light h-100 overflow-auto"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 마크다운 파서 및 스크립트 -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/markdown-it/dist/markdown-it.min.js"></script>
|
||||
<script>
|
||||
// 마크다운 파서 초기화
|
||||
const md = window.markdownit();
|
||||
|
||||
// content 필드와 미리보기 연결
|
||||
const textarea = document.getElementById("markdown-editor");
|
||||
const preview = document.getElementById("preview");
|
||||
|
||||
// 실시간 미리보기 업데이트
|
||||
textarea.addEventListener("input", function () {
|
||||
const markdownContent = textarea.value; // textarea 내용 가져오기
|
||||
preview.innerHTML = md.render(markdownContent); // 마크다운 -> HTML 변환
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
{% endblock %}
|
Reference in New Issue
Block a user