讲师信息
标签: django
讲师列表页
课程讲师获取所有讲师信息,其中添加分页功能,添加一个hot讲师排行,并对于人气进行排序
{% extends 'common/base.html' %}
{% load staticfiles %}
{% block custom_bread %}
<section>
<div class="wp">
<ul class="crumbs">
<li><a href="index.html">首页</a>></li>
<li>课程讲师</li>
</ul>
</div>
</section>
{% endblock %}
{% block custom_content %}
<section>
<div class="wp butler_list_box list">
<div class='left'>
<div class="butler_list layout">
<div class="head">
<ul class="fl tab_header">
<li class="{% ifequal sort '' %}active{% endifequal %}"><a href="?sort=">全部</a> </li>
<li class="{% ifequal sort 'hot' %}active{% endifequal %}"><a href="?sort=hot">人气 ↓</a></li>
</ul>
<div class="fr butler-num">共<span class="key">{{ teachers_count }}</span>人 </div>
</div>
{% for teacher in all_teachers.object_list %}
<dl class="des">
<dt>
<a href="/org/teacher/detail/1/">
<div class="picpic">
<img width="100" height="100" class="scrollLoading" src="{{ MEDIA_URL }}{{ teacher.image }}"/>
</div>
</a>
<div class="btn">
<div class="fr btn2 bdsharebuttonbox"
data-text="授课教师-{{ teacher.name }}-慕学在线"
data-desc="我在#慕课网#发现了教师“{{ teacher.name }}”,对学习中的小伙伴很有帮助,一起来看看吧。"
data-comment="{{ teacher.name }}金牌讲师,从业年限:{{ teacher.work_years }}年"
>
<span class="fl">分享</span>
<a href="#" class="bds_more" data-cmd="more"></a>
</div>
</div>
</dt>
<dd>
<a href="/org/teacher/detail/1/">
<h1>{{ teacher.name }}<span class="key picbig">金牌讲师</span></h1>
</a>
<ul class="cont">
<li>工作年限:<span>{{ teacher.work_years }}年</span></li>
<li>工作职位:<span>{{ teacher.work_position }}</span></li>
<li>就职公司:<span>{{ teacher.work_company }} </span></li>
<li>年龄:<span>{{ teacher.age }}岁</span></li>
<li>教学特点:<span>{{ teacher.points }}</span></li>
</ul>
</dd>
<a class="buy buyservice" href="/org/teacher/detail/1/"><br/>查看<br/>详情</a>
</dl>
{% endfor %}
</div>
<div class="pageturn">
<ul class="pagelist">
{% if all_teachers.has_previous %}
<li class="long"><a href="?{{ all_teachers.previous_page_number.querystring }}">上一页</a></li>
{% endif %}
{% for page in all_teachers.pages %}
{% if page %}
{% ifequal page all_teachers.number %}
<li class="active"><a href="">{{ page }}</a></li>
{% else %}
<li><a href="?{{ page.querystring }}" class="page">{{ page }}</a></li>
{% endifequal %}
{% else %}
<li class="none"><a href="">...</a></li>
{% endif %}
{% endfor %}
{% if all_teachers.has_next %}
<li class="long"><a href="?{{ all_teachers.next_page_number.querystring }}">下一页</a></li>
{% endif %}
</ul>
</div>
</div>
<div class="right layout">
<div class="head">讲师排行榜</div>
{% for teacher in hot_teachers %}
<dl class="des">
<span class="num fl">1</span>
<a href="/diary/hk_detail/6/">
<dt>
<img width="50" height="50" class="scrollLoading" src="{{ MEDIA_URL }}{{ teacher.image }}"/>
</dt>
</a>
<dd>
<a href="/diary/hk_detail/6/">
<h1 title="bobby">{{ teacher.name }}</h1>
</a>
<p>工作年限:<span>{{ teacher.work_years }}年</span></p>
</dd>
</dl>
{% endfor %}
</div>
</div>
</section>
{% endblock %}
class TeacherListView(View):
def get(self, request):
all_teachers = Teacher.objects.all()
hot_teachers = all_teachers.order_by('-click_nums')[:5]
# 人气排序
sort = request.GET.get('sort', '')
if sort:
all_teachers = all_teachers.order_by('-fav_nums')
# 分页功能展示
try:
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
p = Paginator(all_teachers, 5, request=request)
all_teachers_p = p.page(page)
teachers_count = all_teachers.count()
return render(request, 'teachers-list.html', {
'all_teachers': all_teachers_p,
'teachers_count': teachers_count,
'hot_teachers': hot_teachers,
'sort': sort
})
讲师详情页
讲师详情页根据讲师详情页进行跳转具体教室,并展示详情页信息。
{% extends 'common/base.html' %}
{% load staticfiles %}
{% block custom_bread %}
<section>
<div class="wp">
<ul class="crumbs">
<li><a href="index.html">首页</a>></li>
<li>课程讲师</li>
</ul>
</div>
</section>
{% endblock %}
{% block custom_content %}
<section>
<div class="wp butler-detail-box butler-diaryd-box clearfix">
<div class="fl list">
<div class="left layout">
<div class="butler_detail_list clearfix">
<div class="brief">
<dl class="des">
<dt>
<div class="picpic">
<img width="100" height="100" src="{{ MEDIA_URL }}{{ teacher.image }}"/>
</div>
<div class="btn">
<span class="fl btn1 collectionbtn" id="jsLeftBtn">
{% if has_teacher_fav %}已收藏{% else %}收藏{% endif %}
</span>
<span class="fr btn2 shareBtn bdsharebuttonbox"
data-text="授课教师-{{ teacher.name }}-慕学网"
data-desc="我在#慕课网#发现了"
data-comment="{{ teacher.name }},工作年限:{{ teacher.work_years }}年;学历:本科;所在公司:{{ teacher.work_company }} ;经典案例:django入门和深入;flask入门"
data-url="/diary/hk_detail/10/">
<span class="fl">分享</span>
<a href="#" class="bds_more" data-cmd="more"></a>
</span>
</div>
</dt>
<dd>
<a href="/diary/hk_detail/10/">
<h1>{{ teacher.name }}<span class="key picbig">金牌讲师</span></h1>
</a>
<ul class="cont">
<li>工作年限:<span>{{ teacher.work_years }}年</span></li>
<li>就职公司:<span>{{ teacher.work_company }}</span></li>
<li>工作职位:<span>{{ teacher.work_position }} </span></li>
<li>教学特点:<span>{{ teacher.points }}</span></li>
</ul>
</dd>
</dl>
</div>
</div>
<div class="butler_detail_cont clearfix">
<div class="head">
<ul class="tab_header">
<li class="active"><a href="/diary/hk_detail/10/">全部课程</a> </li>
</ul>
</div>
<div class="companycenter">
<div class="group_list brief">
{% for course in all_courses %}
<div class="module1_5 box">
<a href="course-detail.html">
<img width="214" height="190" class="scrollLoading" src="{{ MEDIA_URL }}{{ course.image }}"/>
</a>
<div class="des">
<a href="course-detail.html"><h2>{{ course.name }}</h2></a>
<span class="fl">时长:<i class="key">{{ course.learn_time }}</i></span>
<span class="fr">学习人数:{{ course.students }}</span>
</div>
<div class="bottom">
<span class="fl">{{ course.course_org.name }}</span>
<span class="star fr notlogin" data-favid="15">{{ course.course_org.fav_nums }}</span>
</div>
</div>
{% endfor %}
</div>
</div>
<!--<div class="pageturn">-->
<!--<ul class="pagelist">-->
<!--<li class="active"><a href="?page=1">1</a></li>-->
<!--</ul>-->
<!--</div>-->
</div>
</div>
<div class="right layout">
<div class="butler_detail_list">
<div class="right butler-company-box">
<div class="head">
<h1></h1>
<p>知名高校,权威教学</p>
</div>
<div class="pic">
<a href="org-detail-homepage.html">
<img width="150" height="80" src="{{ MEDIA_URL }}{{ teacher.org.image }}"/>
</a>
</div>
<a href="org-detail-homepage.html">
<h2 class="center">{{ teacher.org.name }}</h2>
</a>
<p class="center tell">地址:{{ teacher.org.address }}</p>
<a class="btn" id="jsRightBtn">{% if has_org_fav %}已收藏{% else %}收藏{% endif %}</a>
</div>
</div>
<div class="butler_detail_cont">
<div class="butler_list_box">
<div class="right layout">
<div class="head">讲师排行榜</div>
{% for teacher in hot_teachers %}
<dl class="des">
<span class="num fl">1</span>
<a href="{% url 'org:teacher_detail' teacher.id %}">
<dt>
<img width="50" height="50" class="scrollLoading" src="{{ MEDIA_URL }}{{ teacher.image }}"/>
</dt>
</a>
<dd>
<a href="{% url 'org:teacher_detail' teacher.id %}">
<h1 title="bobby">{{ teacher.name }}</h1>
</a>
<p>工作年限:<span>{{ teacher.work_years }}年</span></p>
</dd>
</dl>
{% endfor %}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
{% endblock %}
{% block custom_js %}
<script type="text/javascript">
//收藏分享
function add_fav(current_elem, fav_id, fav_type){
$.ajax({
cache: false,
type: "POST",
url:"{% url 'org:add_fav' %}",
data:{'fav_id':fav_id, 'fav_type':fav_type},
async: true,
beforeSend:function(xhr, settings){
xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
},
success: function(data) {
if(data.status == 'fail'){
if(data.msg == '用户未登录'){
window.location.href="login.html";
}else{
alert(data.msg)
}
}else if(data.status == 'success'){
current_elem.text(data.msg)
}
},
});
}
$('#jsLeftBtn').on('click', function(){
add_fav($(this), {{ teacher.id }}, 3);
});
$('#jsRightBtn').on('click', function(){
add_fav($(this), {{ teacher.id }}, 2);
});
</script>
{% endblock %}
class TeacherDetailView(View):
"""
教师详情页面
"""
def get(self, request, teacher_id):
hot_teachers = Teacher.objects.all().order_by('-fav_nums')[:3]
teacher = Teacher.objects.get(id=teacher_id)
teacher.click_nums += 1
teacher.save()
all_courses = teacher.course_set.all()[:3]
has_teacher_fav = False
has_org_fav = False
if UserFavorite.objects.filter(user=request.user, fav_id=teacher.id, fav_type=3):
has_teacher_fav = True
if UserFavorite.objects.filter(user=request.user, fav_id=teacher.org.id, fav_type=2):
has_org_fav = True
return render(request, 'teacher-detail.html', {
'teacher': teacher,
'all_courses': all_courses,
'hot_teachers': hot_teachers,
'has_teacher_fav': has_teacher_fav,
'has_org_fav': has_org_fav
})
- 本篇博客原视频博主[慕课在线教育平台]
- 本篇博客撰写人: XiaoJinZi 转载请注明出处
- 学生能力有限 附上邮箱: 986209501@qq.com 不足以及误处请大佬指责
网友评论