티스토리 뷰

INTRO

Python 3.10.0

Django     3.2.8

1. base_log.html을 이용한 persona-erp.html, register.html, password.html 단순화

2. temlates/base/base.html을 이용한 home/notice 통합

 

home/views.py

from django.shortcuts import render, redirect
from django.contrib import auth
from django.contrib.auth.models import User
from django.contrib.auth import authenticate
from django.contrib.auth.decorators import login_required
from home.models import Notice
from home.forms import NoticeForm


# Create your views here.
@login_required
def index(request):
	return render(request, 'home/index.html')

@login_required
def notice(request):
	notices = Notice.objects.all().order_by('-notice_id')
	context = {'notices':notices}
	return render(request, 'home/notices/notice.html', context)

@login_required
def notice_view(request,pk):
	notices = Notice.objects.all().order_by('-notice_id')
	notice_view  = Notice.objects.get(pk=pk)
	context = {'notices':notices, 'notice_view':notice_view}
	return render(request, 'home/notices/notice_view.html', context)

@login_required
def notice_new(request):
	notices = Notice.objects.all().order_by('-notice_id')
	if request.method == 'POST':
		form = NoticeForm(request.POST)
		if form.is_valid():
			notice_new = Notice()
			notice_new.author  = form.cleaned_data['author']
			notice_new.title   = form.cleaned_data['title']
			notice_new.article = form.cleaned_data['article']
			notice_new.save()
			return render(request, 'home/notices/notice.html',{'notices':notices})
	else:
		form = NoticeForm()
	context = {'form':form, 'notices':notices}
	return render(request, 'home/notices/notice_new.html', context)

@login_required
def notice_delete(request, pk):
	notice_del = Notice.objects.get(pk=pk)
	if notice_del.author == User.objects.get(username = request.user.get_username()):
		notice_del.delete()
		notices = Notice.objects.all().order_by('-notice_id')
		return render(request, 'home/notices/notice.html',{'notices':notices})
	else:
		return render(request,'home/errorforms/401.html')

@login_required
def notice_edit(request,pk):
	notices = Notice.objects.all().order_by('-notice_id')
	notice_edit = Notice.objects.get(pk=pk)
	if request.method == 'POST':
		form = NoticeForm(request.POST)
		if form.is_valid():
			notice_edit.author  = form.cleaned_data['author']
			notice_edit.title   = form.cleaned_data['title']
			notice_edit.article = form.cleaned_data['article']
			notice_edit.save()
			return render(request, 'home/notices/notice.html',{'notices':notices})
	else:
		form = NoticeForm(instance=notice_edit)
		notices = Notice.objects.all().order_by('-notice_id')
		context = {'form':form, 'notices':notices}
	return render(request, 'home/notices/notice_edit.html', context)

 

home/templates/home/index.html

{% extends 'base/base.html' %}
{% block main %}
<div class="container-fluid px-4">
    <!-- Main_Header -->
    <h1 class="mt-4">Dashboard</h1>
    <ol class="breadcrumb mb-4">
        <li class="breadcrumb-item active">Dashboard</li>
    </ol>

    <!-- Main_content_#1 -->
    <div class="row">
        <div class="col-xl-3 col-md-6">
            <div class="card bg-warning text-white mb-4">
                <div class="card-body">공지사항</div>
                <div class="card-footer d-flex align-items-center justify-content-between">
                    <a class="small text-white stretched-link" href="{% url 'home:notice' %}">View Details</a>
                    <div class="small text-white"><i class="fas fa-angle-right"></i></div>
                </div>
            </div>
        </div>
        <div class="col-xl-3 col-md-6">
            <div class="card bg-primary text-white mb-4">
                <div class="card-body">수주현황</div>
                <div class="card-footer d-flex align-items-center justify-content-between">
                    <a class="small text-white stretched-link" href="#">View Details</a>
                    <div class="small text-white"><i class="fas fa-angle-right"></i></div>
                </div>
            </div>
        </div>
        
        <div class="col-xl-3 col-md-6">
            <div class="card bg-success text-white mb-4">
                <div class="card-body">생산현황</div>
                <div class="card-footer d-flex align-items-center justify-content-between">
                    <a class="small text-white stretched-link" href="#">View Details</a>
                    <div class="small text-white"><i class="fas fa-angle-right"></i></div>
                </div>
            </div>
        </div>
        <div class="col-xl-3 col-md-6">
            <div class="card bg-danger text-white mb-4">
                <div class="card-body">품질현황</div>
                <div class="card-footer d-flex align-items-center justify-content-between">
                    <a class="small text-white stretched-link" href="#">View Details</a>
                    <div class="small text-white"><i class="fas fa-angle-right"></i></div>
                </div>
            </div>
        </div>
    </div>

    <!-- Main_content_#2 -->
    <div class="row">
        <div class="col-xl-6">
            <div class="card mb-4">
                <div class="card-header">
                    <i class="fas fa-chart-area me-1"></i>
                    출하현황
                </div>
                <div class="card-body"><canvas id="myAreaChart" width="100%" height="40"></canvas></div>
            </div>
        </div>
        <div class="col-xl-6">
            <div class="card mb-4">
                <div class="card-header">
                    <i class="fas fa-chart-bar me-1"></i>
                    매출현황
                </div>
                <div class="card-body"><canvas id="myBarChart" width="100%" height="40"></canvas></div>
            </div>
        </div>
    </div>

    <!-- Main_content_#3 -->
    <div class="card mb-4">
        <div class="card-header">
            <i class="fas fa-table me-1"></i>
            출하현황
        </div>
        <div class="card-body">
            <table id="datatablesSimple">
                <thead>
                    <tr>
                        <th>수주번호</th>
                        <th>고객사</th>
                        <th>관리번호</th>
                        <th>제품명</th>
                        <th>생산수량</th>
                        <th>출하일</th>
                        <th>출하대기</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>P0000001-20211130</td>
                        <td>A-Company</td>
                        <td>PE0000001</td>
                        <td>F-D-Parts-0001</td>
                        <td>10,000</td>
                        <td>20211205</td>
                        <td>Y</td>
                    </tr>
                    <tr>
                        <td>P0000002-20211130</td>
                        <td>B-Company</td>
                        <td>PE0000002</td>
                        <td>F-D-Parts-0002</td>
                        <td>5,000</td>
                        <td>20211207</td>
                        <td>N</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock main %}

{% load static %}
{% block js %}
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js" crossorigin="anonymous"></script>
    <script src="{% static 'assets/demo/chart-area-demo.js' %}"></script>
    <script src="{% static 'assets/demo/chart-bar-demo.js' %}"></script>
    <script src="{% static 'assets/demo/chart-pie-demo.js' %}"></script>
    <script src="https://cdn.jsdelivr.net/npm/simple-datatables@latest" crossorigin="anonymous"></script>
    <script src="{% static 'js/datatables-simple-demo.js' %}"></script>
{% endblock js %}

 

 

templates/base hyperlink 및 include 경로 수정

- templates/base/topbar.html

<nav class="sb-topnav navbar navbar-expand navbar-dark bg-dark">
    <!-- Navbar Brand-->
    <a class="navbar-brand ps-3" href="{% url 'home:index' %}">PERSONA-ERP</a>
    <!-- Sidebar Toggle-->
    <button class="btn btn-link btn-sm order-1 order-lg-0 me-4 me-lg-0" id="sidebarToggle" href="#!"><i class="fas fa-bars"></i></button>
    <!-- Navbar-->
    <ul class="navbar-nav ms-auto ms-md-0 me-3 me-lg-4">
        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" id="navbarDropdown" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false"><i class="fas fa-user fa-fw"></i></a>
            <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
                <!-- <li><a class="dropdown-item" href="#!">Settings</a></li>
                <li><a class="dropdown-item" href="#!">Activity Log</a></li> -->
                <!-- <li><hr class="dropdown-divider" /></li> -->
                <li><a class="dropdown-item" href="{% url 'logout' %}">Log-Out</a></li>
            </ul>
        </li>
    </ul>
    <!-- Navbar Search-->
    <form class="d-none d-md-inline-block form-inline ms-auto me-0 me-md-3 my-2 my-md-0">
        <div class="input-group">
            <input class="form-control" type="text" placeholder="Search for..." aria-label="Search for..." aria-describedby="btnNavbarSearch" />
            <button class="btn btn-primary" id="btnNavbarSearch" type="button"><i class="fas fa-search"></i></button>
        </div>
    </form>
</nav>

 

- templates/base/base.html

{% load static %}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
        <meta name="description" content="" />
        <meta name="author" content="" />
        <title>{% block title %}{{ section.title }}{% endblock %}</title>
        <link href="https://cdn.jsdelivr.net/npm/simple-datatables@latest/dist/style.css" rel="stylesheet" />
        <link href="{% static 'css/styles.css' %}" rel="stylesheet" />
        <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/js/all.min.js" crossorigin="anonymous"></script>
    </head>

    <body class="sb-nav-fixed">
        <!-- Topbar -->
        {% include 'base/topbar.html' %}
        <div id="layoutSidenav">
        <!-- Sidebar -->
        {% include 'base/sidebar.html' %}

            <!-- Main_Contents -->
            <div id="layoutSidenav_content">
                <main>
                {% block main %}
                {% endblock main %}
                </main>

                <!-- Footer -->
                {% include 'base/footer.html' %}
            </div>
        </div>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
        <script src="{% static 'js/scripts.js' %}"></script>
        {% block js %}
        {% endblock js %}
    </body>
</html>

 

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함