This commit is contained in:
xieshen 2020-10-21 11:42:46 +08:00
parent a80895d223
commit ec028bf23b
4 changed files with 195 additions and 3 deletions

View File

@ -0,0 +1,144 @@
{% extends 'dashboard/base/base.html' %}
{% load static %}
{% block title %}祁连山生态监测数据管理平台{% endblock %}
{% block css %}
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.1/css/bootstrap.min.css">
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet">
<link href="/static/django-summernote-0.8.11.4/django_summernote/static/summernote/summernote.css" rel="stylesheet">
<link href="/static/django-summernote-0.8.11.4/django_summernote/static/summernote/summernote-bs4.css"
rel="stylesheet">
<link href="/static/django-summernote-0.8.11.4/django_summernote/static/summernote/summernote-lite.css"
rel="stylesheet">
<link href="/static/django-summernote-0.8.11.4/django_summernote/static/summernote/django_summernote.css"
rel="stylesheet">
{% endblock %}
{% block content %}
<div class="page-sidebar ">
{% include 'dashboard/base/left.html' %}
</div>
<div class="container">
{% if messages %}
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert">
<span aria-hidden="true">&times;</span>
<span class="sr-only">Close</span>
</button>
{% for message in messages %}
{{ message }}.<br/>
{% endfor %}
</div>
{% endif %}
<div class="panel-heading" style="margin-top: 100px">
<h3 style="text-align: center;">编辑新闻</h3>
</div>
<form action="{% url 'news-management-update' news.id %}" method="post" enctype="multipart/form-data">{% csrf_token %}
<div class="panel-body col-md-12">
<div class="form-group col-md-6">
<label for="title">新闻标题</label>
<input type="text" class="form-control" id="title" placeholder="请填写新闻标题"
name="title" value="{{ news.title }}">
</div>
<div class="form-group col-md-6">
<label for="title">新闻分类</label>
<select class="form-control" name="type">
{% if news.type == '0' %}
<option value="政策依据">政策依据</option>
{% elif news.type == '1' %}
<option value="基层动态">基层动态</option>
{% elif news.type == '2' %}
<option value="外省动态">外省动态</option>
{% elif news.type == '3' %}
<option value="监测通报">监测通报</option>
{% elif news.type == '4' %}
<option value="舆情热点">舆情热点</option>
{% elif news.type == '5' %}
<option value="通知">通知</option>
{% elif news.type == '6' %}
<option value="重点新闻">重点新闻</option>
{% endif %}
{% for t in type %}
<option value="{{ t.choices }}">{{ t.choices }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="panel-body col-md-12">
<div class="form-group col-md-4">
<label for="title">新闻发布者</label>
<input type="text" class="form-control" id="author" placeholder="请填写新闻作者"
name="author" value="{{ news.author }}">
</div>
<div class="form-group col-md-4">
<label for="date">时间:</label>{{ news.date }}
<input type="date" class="form-control" id="source"
name="date">
</div>
<div class="form-group col-md-4">
<label for="source">来源</label>
<input type="text" class="form-control" id="source"
name="source" value="{{ news.source }}">
</div>
<div class="form-group col-md-12">
<label class="form-label" for="image">缩略图
{% if news.image %}
<img src="{{ news.image.url }}">
{% endif %}
<div class="controls">
<input type="file" name="image">
</div>
</label>
</div>
</div>
<div class="row">
<label for="country">正文</label>
<div>
<textarea id="summernote" name="content" class="input-block-level">{{ news.content }}</textarea>
</div>
<div style="margin-top: 20px;text-align: center;padding-bottom: 20px">
<button type="submit" class="btn btn-primary ">提交修改</button>
</div>
</div>
</form>
</div>
{% endblock %}
{% block add_js %}
<script src="/static/django-summernote-0.8.11.4/django_summernote/static/summernote/summernote.min.js"></script>
<script src="/static/django-summernote-0.8.11.4/django_summernote/static/summernote/summernote-bs4.min.js"></script>
<script src="/static/django-summernote-0.8.11.4/django_summernote/static/summernote/summernote-lite.min.js"></script>
<script src="/static/django-summernote-0.8.11.4/django_summernote/static/summernote/jquery.fileupload.js"></script>
<script src="/static/django-summernote-0.8.11.4/django_summernote/static/summernote/jquery.ui.widget.js"></script>
<script src="/static/django-summernote-0.8.11.4/django_summernote/static/summernote/jquery.iframe-transport.js"></script>
<script>
window.onload = function () {
$('#summernote').summernote({
lang: 'zh-CN',
minHeight: 300,
dialogsFade: true,
dialogsInBody: true,
disableDragAndDrop: false,
});
};
</script>
{# <script type="text/javascript" src="/extra_apps/DjangoUeditor/static/ueditor/ueditor.config.js"></script>#}
{# <script type="text/javascript" src="/extra_apps/DjangoUeditor/static/ueditor/ueditor.all.min.js"></script>#}
{# <script type="text/javascript" src="/extra_apps/DjangoUeditor/static/ueditor/ueditor.all.js"></script>#}
{##}
{##}
{# <script type="text/javascript">#}
{# var ue = UE.getEditor('container');#}
{# </script>#}
{% endblock %}

View File

@ -69,13 +69,15 @@
{% for n in news %}
<tr>
<td style="vertical-align: middle;text-align: left">{{ forloop.counter }}</td>
<td style="vertical-align: middle;text-align: center">{{ n.title }}</td>
<td style="vertical-align: middle;text-align: center"><a href="{% url 'news-management-detail' n.id %}">{{ n.title }}</a></td>
<td style="vertical-align: middle;text-align: center">{{ n.author }}</td>
<td style="vertical-align: middle;text-align: center">{{ n.type }}</td>
<td style="vertical-align: middle;text-align: center">{{ n.date }}</td>
<td style="vertical-align: middle;text-align: center">
<a href="{% url 'news-management-detail' n.id %}"
class="btn btn-primary btn-mini">查看</a>
{# <a href="{% url 'news-management-detail' n.id %}"#}
{# class="btn btn-primary btn-mini">查看</a>#}
<a href="{% url 'news-management-update' n.id %}"
class="btn btn-primary btn-mini">编辑</a>
<a href="{% url 'news-management-delete' n.id %}"
class="btn btn-danger btn-mini">删除</a>
</td>

View File

@ -55,6 +55,7 @@ urlpatterns = [
#新闻管理
path('news/management/',views.new_management,name='news-management'),
path('news/management/create/', views.news_management_create, name='news-management-create'),
path('news/management/updaye/<str:pk>/', views.news_management_update, name='news-management-update'),
path('news/management/detail/<str:pk>/', views.news_management_detail, name='news-management-detail'),
path('news/management/delete/<str:pk>/', views.news_management_delete, name='news-management-delete'),
]

View File

@ -1662,7 +1662,52 @@ def news_management_create(request):
o['choices'] = list(i)[1]
results.append(o)
return render(request, 'management/news-management-create.html', {'type': results})
@login_required
def news_management_update(request,pk):
news = News.objects.get(id=pk)
type = News.NEWMEDIA_NEWS_CHOICES
results = []
for i in type:
o = dict()
o['choices'] = list(i)[1]
results.append(o)
if request.method == 'POST':
type = request.POST.get('type')
title = request.POST.get('title')
author = request.POST.get('author')
content = request.POST.get('content')
source = request.POST.get('source')
t = None
if type == '政策依据':
t = '0'
elif type == "基层动态":
t = '1'
elif type == '外省动态':
t = '2'
elif type == '监测通报':
t = '3'
elif type == '舆情热点':
t = '4'
elif type == '通知':
t = '5'
elif type == '重点新闻':
t = '6'
if request.FILES.get('image'):
image = request.FILES.get('image')
if request.POST.get('date'):
date = request.POST.get('date')
News.objects.filter(id=pk).update(type=t, title=title, author=author, date=date, content=content, source=source, image=image)
else:
News.objects.filter(id=pk).update(type=t, title=title, author=author, content=content,
source=source, image=image)
else:
News.objects.filter(id=pk).update(type=t, title=title, author=author, content=content,
source=source)
messages.success(request,'编辑成功')
return HttpResponseRedirect('/management/news/management/')
return render(request,'management/news-management-update.html',{'news':news,'type':results})
@login_required
def news_management_detail(request, pk):