优化了一些问题

master
newrain001 3 years ago
parent c349d55132
commit 11d32be605
  1. 7
      App/admin.py
  2. 14
      App/views.py
  3. 25
      templates/nav/videolist.html

@ -1,3 +1,10 @@
from django.contrib import admin from django.contrib import admin
# Register your models here. # Register your models here.
from .models import *
admin.site.register(User)
admin.site.register(Upload)
admin.site.register(Task)
admin.site.register(paper)
admin.site.register(thumbs)
admin.site.register(videoUpload)

@ -285,11 +285,15 @@ def videoView(request, id):
return render(request, 'nav/videoview.html', {'path': data.video_path}) return render(request, 'nav/videoview.html', {'path': data.video_path})
def videoList(request): def videoList(request):
video_type = request.GET.get('video_type', '全部内容')
if video_type == '全部内容':
data = videoUpload.objects.all().order_by('video_title', '-video_time')
else:
data = videoUpload.objects.filter(video_desc=video_type).all().order_by('video_title','-video_time')
desc = videoUpload.objects.all().values('video_desc').distinct() desc = videoUpload.objects.all().values('video_desc').distinct()
data = {} desc = [i['video_desc'] for i in desc]
for i in desc: desc.append('全部内容')
data[i["video_desc"]] = videoUpload.objects.filter(video_desc=i["video_desc"]).all().order_by('video_title') return render(request, 'nav/videolist.html', {'data': data, 'desc': desc, 'selected': video_type})
return render(request, 'nav/videolist.html', {'data':data })
def file_iterator(file_name, chunk_size=8192, offset=0, length=None): def file_iterator(file_name, chunk_size=8192, offset=0, length=None):
with open(file_name, "rb") as f: with open(file_name, "rb") as f:
@ -340,5 +344,5 @@ def videoDownload(request, id):
response = FileResponse(file) response = FileResponse(file)
response['Content-Type'] = 'application/octet-stream' response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="{}"'.format(quote(file_name)) response['Content-Disposition'] = 'attachment;filename="{}"'.format(quote(file_name))
messages.error(request, '下载成功') #messages.error(request, '下载成功')
return response return response

@ -7,12 +7,28 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<div class="main" style="padding-top: 80px"> <div class="main" style="padding-top: 80px">
<form action="" id="desc">
<select class="form-select form-select-lg mb-3" aria-label=".form-select-lg example" name="video_type">
{% for i in desc %}
{% if i == selected %}
<option selected value="{{ i }}">{{ i }}</option>
{% else %}
<option value="{{ i }}">{{ i }}</option>
{% endif %}
{% endfor %}
</select>
<button class="w-100 btn btn-lg btn-primary" type="submit">提交</button>
</form>
<script>
$(function func() {
var form = document.getElementById('desc');
form.submit();
})
</script>
<div class="dy-content"> <div class="dy-content">
{% for k,v in data.items %}
<h1>{{ k }}</h1>
<div class="dy-videos"> <div class="dy-videos">
<ul class="dy-video-list"> <ul class="dy-video-list">
{% for i in v %} {% for i in data %}
{% if forloop.counter|quyu:5 %} {% if forloop.counter|quyu:5 %}
<li data- class="dy-video-item dy-video-meta-left"> <li data- class="dy-video-item dy-video-meta-left">
{% else %} {% else %}
@ -43,10 +59,9 @@
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>
{% endfor %}
</div> </div>
</div> </div>
{% if messages %} {% if messages %}
<script> <script>
{% for msg in messages %} {% for msg in messages %}
alert('{{msg.message}}'); alert('{{msg.message}}');

Loading…
Cancel
Save