├── CQNU-TED ├── apps │ ├── utils │ │ ├── __init__.py │ │ ├── mixin_utils.py │ │ └── email_send.py │ ├── users │ │ ├── __init__.py │ │ ├── tests.py │ │ ├── apps.py │ │ ├── adminx.py │ │ ├── forms.py │ │ ├── urls.py │ │ └── models.py │ ├── course │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── tests.py │ │ ├── apps.py │ │ ├── urls.py │ │ ├── adminx.py │ │ ├── models.py │ │ └── views.py │ ├── operation │ │ ├── __init__.py │ │ ├── tests.py │ │ ├── admin.py │ │ ├── views.py │ │ ├── apps.py │ │ ├── adminx.py │ │ └── models.py │ ├── __init__.py │ └── organization │ │ ├── __init__.py │ │ ├── tests.py │ │ ├── apps.py │ │ ├── forms.py │ │ ├── adminx.py │ │ ├── urls.py │ │ ├── models.py │ │ └── views.py ├── 如果遇到year的时候需要进行删除操作.txt ├── 在局域网发布.txt ├── online_studying │ ├── __init__.py │ ├── wsgi.py │ ├── urls.py │ └── settings.py ├── templates │ ├── send_success.html │ ├── active_fail.html │ ├── 404.html │ ├── org-detail-desc.html │ ├── 500.html │ ├── org-detail-teachers.html │ ├── org-detail-course.html │ ├── usercenter-mycourse.html │ ├── password_reset.html │ ├── usercenter-fav-course.html │ ├── usercenter-message.html │ ├── usercenter-fav-teacher.html │ ├── org-detail-homepage.html │ ├── usercenter-fav-org.html │ ├── usercenter-info.html │ ├── login.html │ ├── teachers-list.html │ ├── course-list.html │ ├── forgetpwd.html │ ├── index.html │ ├── course-detail.html │ ├── base.html │ ├── teacher-detail.html │ ├── course-video.html │ ├── course-play.html │ ├── register.html │ ├── org_base.html │ ├── org-list.html │ └── course-comment.html ├── 迁移数据库.txt └── manage.py ├── pic ├── gkk.png ├── index.png ├── kcxx.png ├── logo.png ├── 上传文件.png ├── 后台管理.png ├── 情感分析图.png ├── 技术架构.png ├── 教师后台.png ├── 数据库表格.png ├── 视频上传.png └── xuebaye.png ├── README.md └── .gitignore /CQNU-TED/apps/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | -------------------------------------------------------------------------------- /CQNU-TED/如果遇到year的时候需要进行删除操作.txt: -------------------------------------------------------------------------------- 1 | 删除之前的makemigrations和migrate -------------------------------------------------------------------------------- /pic/gkk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarryChang/CQNU-TED/HEAD/pic/gkk.png -------------------------------------------------------------------------------- /CQNU-TED/apps/users/__init__.py: -------------------------------------------------------------------------------- 1 | default_app_config = 'apps.users.apps.UsersConfig' -------------------------------------------------------------------------------- /pic/index.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarryChang/CQNU-TED/HEAD/pic/index.png -------------------------------------------------------------------------------- /pic/kcxx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarryChang/CQNU-TED/HEAD/pic/kcxx.png -------------------------------------------------------------------------------- /pic/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarryChang/CQNU-TED/HEAD/pic/logo.png -------------------------------------------------------------------------------- /pic/上传文件.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarryChang/CQNU-TED/HEAD/pic/上传文件.png -------------------------------------------------------------------------------- /pic/后台管理.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarryChang/CQNU-TED/HEAD/pic/后台管理.png -------------------------------------------------------------------------------- /pic/情感分析图.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarryChang/CQNU-TED/HEAD/pic/情感分析图.png -------------------------------------------------------------------------------- /pic/技术架构.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarryChang/CQNU-TED/HEAD/pic/技术架构.png -------------------------------------------------------------------------------- /pic/教师后台.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarryChang/CQNU-TED/HEAD/pic/教师后台.png -------------------------------------------------------------------------------- /pic/数据库表格.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarryChang/CQNU-TED/HEAD/pic/数据库表格.png -------------------------------------------------------------------------------- /pic/视频上传.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarryChang/CQNU-TED/HEAD/pic/视频上传.png -------------------------------------------------------------------------------- /CQNU-TED/apps/course/__init__.py: -------------------------------------------------------------------------------- 1 | default_app_config = 'apps.course.apps.CourseConfig' -------------------------------------------------------------------------------- /CQNU-TED/在局域网发布.txt: -------------------------------------------------------------------------------- 1 | 使用runserver 192.168.191.1:8000命令 2 | runserver后面为本地ipconfig后的ip地址 -------------------------------------------------------------------------------- /pic/xuebaye.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CarryChang/CQNU-TED/HEAD/pic/xuebaye.png -------------------------------------------------------------------------------- /CQNU-TED/apps/operation/__init__.py: -------------------------------------------------------------------------------- 1 | default_app_config = 'apps.operation.apps.OperationConfig' -------------------------------------------------------------------------------- /CQNU-TED/apps/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import pymysql 3 | pymysql.install_as_MySQLdb() -------------------------------------------------------------------------------- /CQNU-TED/apps/organization/__init__.py: -------------------------------------------------------------------------------- 1 | default_app_config = 'apps.organization.apps.OrganizationConfig' -------------------------------------------------------------------------------- /CQNU-TED/apps/users/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /CQNU-TED/apps/course/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /CQNU-TED/apps/course/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /CQNU-TED/apps/operation/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /CQNU-TED/apps/operation/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /CQNU-TED/apps/operation/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /CQNU-TED/apps/organization/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /CQNU-TED/online_studying/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import pymysql 3 | pymysql.install_as_MySQLdb() -------------------------------------------------------------------------------- /CQNU-TED/apps/course/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | class CourseConfig(AppConfig): 3 | name = 'apps.course' 4 | verbose_name = '课程管理' 5 | -------------------------------------------------------------------------------- /CQNU-TED/apps/users/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class UsersConfig(AppConfig): 5 | name = 'apps.users' 6 | verbose_name = '用户信息' 7 | -------------------------------------------------------------------------------- /CQNU-TED/apps/operation/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class OperationConfig(AppConfig): 5 | name = 'apps.operation' 6 | verbose_name = '用户操作' 7 | -------------------------------------------------------------------------------- /CQNU-TED/apps/organization/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class OrganizationConfig(AppConfig): 5 | name = 'apps.organization' 6 | verbose_name = '学院和教师管理' 7 | -------------------------------------------------------------------------------- /CQNU-TED/templates/send_success.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | title 6 | 7 | 8 |

邮件已发送, 请注意查收

9 | 10 | 11 | -------------------------------------------------------------------------------- /CQNU-TED/templates/active_fail.html: -------------------------------------------------------------------------------- 1 | {#templates/active_fail.html#} 2 | 3 | 4 | 5 | 6 | title 7 | 8 | 9 |

链接失效

10 | 11 | -------------------------------------------------------------------------------- /CQNU-TED/迁移数据库.txt: -------------------------------------------------------------------------------- 1 | 2 | 首先: 3 | python3 manage.py migrate 4 | 将该改动作用到数据库文件,比如产生table之类 5 | 然后: 6 | python3 manage.py makemigrations 7 | 当makemigrations之后产生了0001_initial.py 文件,你可以查看下该migrations会对应于什么样子的SQL命令 8 | python manger.py sqlmigrate theapp 0001 9 | 10 | 创建超级用户 11 | createsuperuser 12 | 13 | 修改admin密码:createsuperuser 14 | admin123 -------------------------------------------------------------------------------- /CQNU-TED/apps/utils/mixin_utils.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from django.contrib.auth.decorators import login_required 4 | from django.utils.decorators import method_decorator 5 | class LoginRequiredMixin(object): 6 | @method_decorator(login_required(login_url='/login/')) 7 | def dispatch(self, request, *args, **kwargs): 8 | return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs) -------------------------------------------------------------------------------- /CQNU-TED/online_studying/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for online_studying project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "online_studying.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /CQNU-TED/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "online_studying.settings") 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /CQNU-TED/apps/organization/forms.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | __author__ = 'bobby' 3 | __date__ = '2018/3/18 15:03' 4 | 5 | import re 6 | from django import forms 7 | 8 | from apps.operation.models import UserAsk 9 | 10 | 11 | # 用ModelForm来实现,提交我要学习咨询 12 | class UserAskForm(forms.ModelForm): 13 | 14 | class Meta: 15 | model = UserAsk 16 | fields = ['name', 'mobile', 'course_name'] 17 | 18 | # 手机号验证的正则表达式验证 19 | def clean_mobile(self): 20 | """ 21 | 验证手机号码是否合法 22 | """ 23 | mobile = self.cleaned_data['mobile'] 24 | REGEX_MOBILE = "^1[358]\d{9}$|^147\d{8}$|^176\d{8}$" 25 | p = re.compile(REGEX_MOBILE) 26 | if p.match(mobile): 27 | return mobile 28 | else: 29 | raise forms.ValidationError(u"手机号码非法", code="mobile_invalid") 30 | -------------------------------------------------------------------------------- /CQNU-TED/templates/404.html: -------------------------------------------------------------------------------- 1 | {#templates/404.html#} 2 | 3 | 4 | {% load staticfiles %} 5 | 6 | 7 | 404 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 |
17 | 18 |



19 |

wow~这个页面被外星人抢走了~

20 |
21 | Wow~ this page was the alien took ~ 22 |
23 |
24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /CQNU-TED/templates/org-detail-desc.html: -------------------------------------------------------------------------------- 1 | {#tempaltes/org-detail-desc.html#} 2 | {% extends 'org_base.html' %} 3 | {% load staticfiles %} 4 | 5 | {% block title %}学院描述页{% endblock %} 6 | {% block page_path %}学院描述{% endblock %} 7 | 8 | {% block right_form %} 9 |
10 |
11 |

学院介绍

12 | 查看更多 > 13 |
14 |
   

{{ course_org.desc }}

15 |
18 |
19 |
20 | 21 | {% endblock %} 22 | 23 | -------------------------------------------------------------------------------- /CQNU-TED/templates/500.html: -------------------------------------------------------------------------------- 1 | {#templates/500.html#} 2 | 3 | 4 | {% load staticfiles %} 5 | 6 | 7 | 500 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 |
17 |
18 |
19 | 20 |





21 |

服务器错误,请稍后重新刷新。

22 |
23 |
24 |
25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![996.icu](https://img.shields.io/badge/link-996.icu-red.svg)](https://996.icu) 2 | ###
CQNU-TED
3 | ### 4 | ##
5 | ### 6 | #### 开发意义 7 | >#### 1. 基于在线个性化学习的需求。慕课网因为种类繁杂,学生并不能根据专业知识需要找到自己的课程学习,并且每所高校教师基本都具有自己的一套学习体系,课堂结束后需要能够上传资料供学生学习的平台(逐步替代QQ群),并能够实时视频播放。 8 | ![logo](https://github.com/CarryChang/CQNU-TED/blob/master/pic/index.png) 9 | >#### 2. 推进校园教学智慧化进程。通过对课程数字化,结合先进的深度学习技术提高学习效率,通过机器推荐和完成课前线上学习任务,给老师减少教学负担,提高老师教学的效率。 10 | ![logo](https://github.com/CarryChang/CQNU-TED/blob/master/pic/gkk.png) 11 | >#### 3. 使用Xadmin进行快速搭建,用户权限定义,课程设置,轮播图,以及具有视频等各类文件共享的功能 12 | ![logo](https://github.com/CarryChang/CQNU-TED/blob/master/pic/视频上传.png) 13 | >#### 4. 平台的架构如下所示,可以在线直接观看此在线学习平台的具体信息,详情点击 https://carrychang.github.io/CQNU-TED/ 14 |
15 | -------------------------------------------------------------------------------- /CQNU-TED/apps/course/urls.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from django.conf.urls import url, include 3 | from django.urls import path,re_path 4 | from .views import CourseListView, CourseDetailView, CourseInfoView, CommentsView, AddCommentsView, VideoPlayView 5 | app_name = 'course' 6 | urlpatterns = [ 7 | # 课程列表页 8 | path('list/', CourseListView.as_view(), name="course_list"), 9 | # 课程详情页 10 | re_path('detail/(?P\d+)/$', CourseDetailView.as_view(), name="course_detail"), 11 | # 课程章节信息页 12 | re_path('info/(?P\d+)/', CourseInfoView.as_view(), name="course_info"), 13 | # 课程评论 14 | re_path('comments/(?P\d+)/', CommentsView.as_view(), name="course_comments"), 15 | # 添加课程评论,已经把参数放到post当中了 16 | path('add_comment/', AddCommentsView.as_view(), name="add_comment"), 17 | # 课程视频播放页 18 | re_path('video/(?P\d+)/', VideoPlayView.as_view(), name="video_play"), 19 | 20 | ] 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /CQNU-TED/apps/organization/adminx.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | __author__ = 'bobby' 3 | __date__ = '2018/3/16 20:56' 4 | 5 | 6 | import xadmin 7 | from .models import CityDict, CourseOrg, Teacher 8 | 9 | class CityDictAdmin: 10 | list_display = ['name', 'desc', 'add_time'] 11 | search_fields = ['name', 'desc'] 12 | list_filter = ['name', 'desc', 'add_time'] 13 | 14 | 15 | class CourseOrgAdmin: 16 | list_display = ['name', 'desc', 'click_nums', 'fav_nums', 'image', 'address', 'city', 'add_time'] 17 | search_fields = ['name', 'desc', 'click_nums', 'fav_nums', 'address', 'city'] 18 | list_filter = ['name', 'desc', 'click_nums', 'fav_nums', 'address', 'city__name', 'add_time'] 19 | 20 | 21 | class TeacherAdmin: 22 | list_display = ['org', 'name', 'work_years', 'work_company', 'work_position', 'points', 'click_nums', 'fav_nums', 'add_time'] 23 | search_fields = ['org', 'name', 'work_years', 'work_company', 'work_position', 'points', 'click_nums', 'fav_nums'] 24 | list_filter = ['org__name', 'name', 'work_years', 'work_company', 'work_position', 'points', 'click_nums', 'fav_nums', 'add_time'] 25 | 26 | 27 | xadmin.site.register(CityDict, CityDictAdmin) 28 | xadmin.site.register(CourseOrg, CourseOrgAdmin) 29 | xadmin.site.register(Teacher, TeacherAdmin) -------------------------------------------------------------------------------- /CQNU-TED/apps/organization/urls.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | __author__ = 'bobby' 3 | __date__ = '2018/3/18 15:40' 4 | from django.urls import re_path, path 5 | 6 | from .views import OrgView, AddUserAskView, OrgHomeView, OrgCourseView, OrgDescView, OrgTeacherView, AddFavView 7 | from .views import TeacherListView, TeacherDetailView 8 | 9 | 10 | app_name = "organization" 11 | 12 | urlpatterns = [ 13 | 14 | # 课程机构列表url 15 | path('list/', OrgView.as_view(), name="org_list"), 16 | 17 | # 添加我要学习 18 | path('add_ask/', AddUserAskView.as_view(), name="add_ask"), 19 | 20 | # home页面,取纯数字 21 | re_path('home/(?P\d+)/', OrgHomeView.as_view(), name="org_home"), 22 | 23 | # 访问课程 24 | re_path('course/(?P\d+)/', OrgCourseView.as_view(), name="org_course"), 25 | 26 | # 访问机构描述 27 | re_path('desc/(?P\d+)/', OrgDescView.as_view(), name="org_desc"), 28 | 29 | # 访问机构讲师 30 | re_path('org_teacher/(?P\d+)/', OrgTeacherView.as_view(), name="org_teacher"), 31 | 32 | # 机构收藏 33 | path('add_fav/', AddFavView.as_view(), name="add_fav"), 34 | 35 | # 讲师列表 36 | re_path('teacher/list/', TeacherListView.as_view(), name="teacher_list"), 37 | 38 | # 教师详情 39 | re_path('teacher/detail/(?P\d+)/', TeacherDetailView.as_view(), name="teacher_detail"), 40 | 41 | 42 | ] 43 | -------------------------------------------------------------------------------- /CQNU-TED/apps/users/adminx.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import xadmin 4 | from .models import UserProfile, EmailVerifyRecord, Banner 5 | from xadmin import views 6 | 7 | class UserProfileAdmin: 8 | pass 9 | 10 | 11 | # 邮箱验证码中增加列表项 ,创建管理类,继承object 12 | class EmailVerifyRecordAdmin(object): 13 | list_display = ['code', 'email', 'send_type', 'send_time'] 14 | search_fields = ['code', 'email', 'send_type'] 15 | list_filter = ['code', 'email', 'send_type', 'send_time'] 16 | 17 | 18 | class BannerAdmin(object): 19 | list_display = ['title', 'image', 'url', 'index', 'add_time'] 20 | search_fields = ['title', 'image', 'url', 'index'] 21 | list_filter = ['title', 'image', 'url', 'index', 'add_time'] 22 | 23 | 24 | # 基本的修改 25 | class BaseSetting(object): 26 | enable_themes = True # 打开主题功能 27 | use_bootswatch = True # 设置后才有很多主题可用 28 | 29 | # 针对全局的 头和页脚 30 | class GlobalSettings(object): 31 | site_title = "在线学习后台管理系统" # 系统名称 32 | site_footer = "CQNU-TED" # 底部版权栏 33 | menu_style = "accordion" # 将菜单栏收起来 34 | 35 | # 将model与admin管理器进行关联注册 36 | xadmin.site.register(EmailVerifyRecord, EmailVerifyRecordAdmin) 37 | xadmin.site.register(Banner, BannerAdmin) 38 | # 注册,注意一个是BaseAdminView,一个是CommAdminView 39 | xadmin.site.register(views.BaseAdminView, BaseSetting) 40 | xadmin.site.register(views.CommAdminView, GlobalSettings) 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /CQNU-TED/apps/users/forms.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | __author__ = 'bobby' 3 | __date__ = '2018/3/17 17:11' 4 | from django import forms 5 | from captcha.fields import CaptchaField 6 | 7 | from .models import UserProfile 8 | 9 | 10 | # 检验从前台传来的表单是否合法,并提醒用户正确输入 11 | class LoginForm(forms.Form): 12 | username = forms.CharField(required=True) # 将username设为必填字段 13 | password = forms.CharField(required=True, min_length=5) # 将password设置为必填字段,且最短长度是5 14 | 15 | 16 | # 注册验证表单 17 | class RegisterForm(forms.Form): 18 | email = forms.EmailField(required=True) 19 | password = forms.CharField(required=True, min_length=5) 20 | captcha = CaptchaField(error_messages={"invalid": u"验证码错误"}) # 增加error_message中的invalid的中文写法 21 | 22 | 23 | # 忘记密码 24 | class ForgetPwdForm(forms.Form): 25 | # 此处Email与前端name需保持一致 26 | email = forms.EmailField(required=True) 27 | # 应用验证码 自定义错误输出key必须与异常一样 28 | captcha = CaptchaField(error_messages={"invalid": u"验证码错误"}) 29 | 30 | 31 | # 修改密码的form表单 32 | class ModifyPwdForm(forms.Form): 33 | """重置密码""" 34 | password1 = forms.CharField(required=True, min_length=5) 35 | password2 = forms.CharField(required=True, min_length=5) 36 | 37 | 38 | class UploadImageForm(forms.ModelForm): 39 | class Meta: 40 | model = UserProfile 41 | fields = ['image'] 42 | 43 | 44 | class UserInfoForm(forms.ModelForm): 45 | class Meta: 46 | model = UserProfile 47 | fields = ['nick_name', 'gender', 'birthday', 'address', 'mobile'] 48 | 49 | -------------------------------------------------------------------------------- /CQNU-TED/templates/org-detail-teachers.html: -------------------------------------------------------------------------------- 1 | {#tempaltes/org-detail-teacher.html#} 2 | {% extends 'org_base.html' %} 3 | {% load staticfiles %} 4 | {% block page_path %}学院教师{% endblock %} 5 | {% block right_form %} 6 |
7 |
8 |

学院教师

9 |
10 |
11 |
12 | {% for teacher in all_teachers %} 13 |
14 |
15 | 16 | 17 | 18 |
19 |
20 |

21 | 22 | {{ teacher.name }}已认证 23 | 24 |

25 |
    26 |
  • 工作年限:{{ teacher.work_years }}年
  • 27 |
  • 课程数:{{ teacher.get_course_nums }}
  • 28 |
29 |
30 |
31 | {% endfor %} 32 | 33 |
34 |
35 |
36 | {% endblock %} 37 | 38 | 39 | -------------------------------------------------------------------------------- /CQNU-TED/apps/users/urls.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | __author__ = 'bobby' 3 | __date__ = '2018/3/18 15:40' 4 | from django.conf.urls import url, include 5 | from django.urls import re_path,path 6 | from .views import UserinfoView, UploadImageView, UpdatePwdView, SendEmailCodeView, ResetView 7 | from .views import UpdateEmailView, MyCourseView, MyFavOrgView, MyFavTeacherView, MyFavCourseView, MymessageView,ActiveUserView 8 | 9 | 10 | app_name = 'users' 11 | urlpatterns = [ 12 | 13 | # 激活用户url 14 | re_path('active/(?P.*)/', ActiveUserView.as_view(), name= "user_active"), 15 | 16 | # 重置密码urlc :用来接收来自邮箱的重置链接 17 | re_path('reset/(?P.*)/', ResetView.as_view(), name="reset_pwd"), 18 | 19 | # 用户信息 20 | path('info/', UserinfoView.as_view(), name="user_info"), 21 | 22 | # 用户头像上传 23 | path('image/upload/', UploadImageView.as_view(), name="image_upload"), 24 | 25 | # 用户个人中心修改密码 26 | path('update/pwd/', UpdatePwdView.as_view(), name="update_pwd"), 27 | 28 | # 发送邮箱验证码 29 | path('sendemail_code/', SendEmailCodeView.as_view(), name="sendemail_code"), 30 | 31 | # 修改邮箱 32 | path('update_email/', UpdateEmailView.as_view(), name="update_email"), 33 | 34 | # 用户中心我的课程 35 | path('mycourse/', MyCourseView.as_view(), name="mycourse"), 36 | 37 | # 我收藏的课程机构 38 | path('myfav/org/', MyFavOrgView.as_view(), name="myfav_org"), 39 | 40 | # 我收藏的授课讲师 41 | path('myfav/teacher/', MyFavTeacherView.as_view(), name="myfav_teacher"), 42 | 43 | # 我收藏的课程 44 | path('myfav/course/', MyFavCourseView.as_view(), name="myfav_course"), 45 | 46 | # 我的消息 47 | path('my_message/', MymessageView.as_view(), name="my_message"), 48 | ] 49 | 50 | 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /CQNU-TED/templates/org-detail-course.html: -------------------------------------------------------------------------------- 1 | {#tempaltes/org-detail-course.html#} 2 | 3 | {% extends 'org_base.html' %} 4 | {% load staticfiles %} 5 | 6 | {% block title %}学院课程列表页{% endblock %} 7 | {% block page_path %}学院课程{% endblock %} 8 | 9 | {% block right_form %} 10 |
11 |
12 |

学院课程

13 |
14 |
15 | {% for course in all_courses %} 16 |
17 | 18 | 19 | 20 | 21 |
22 |

{{ course.name }}

23 | 课时:{{ course.learn_times }} 24 | 学习人数{{ course.students }} 25 |
26 |
27 | {{ course.course_org.name }} 28 | 30 | {{ course.fav_nums }} 31 | 32 |
33 |
34 | {% endfor %} 35 | 36 | 37 |
38 |
39 |
    40 |
  • 1
  • 41 |
42 |
43 |
44 | {% endblock %} -------------------------------------------------------------------------------- /CQNU-TED/apps/operation/adminx.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | __author__ = 'bobby' 3 | __date__ = '2018/3/16 20:58' 4 | import xadmin 5 | from .models import UserAsk, UserCourse, UserMessage, CourseComments, UserFavorite 6 | 7 | 8 | class UserAskAdmin(object): 9 | '''用户表单我要学习''' 10 | 11 | list_display = ['name', 'mobile', 'course_name', 'add_time'] 12 | search_fields = ['name', 'mobile', 'course_name'] 13 | list_filter = ['name', 'mobile', 'course_name', 'add_time'] 14 | 15 | 16 | # 17 | class UserCourseAdmin(object): 18 | '''用户课程学习''' 19 | 20 | list_display = ['user', 'course', 'add_time'] 21 | search_fields = ['user', 'course'] 22 | list_filter = ['user', 'course', 'add_time'] 23 | 24 | 25 | 26 | class UserMessageAdmin(object): 27 | '''用户消息后台''' 28 | 29 | list_display = ['user', 'message', 'has_read', 'add_time'] 30 | search_fields = ['user', 'message', 'has_read'] 31 | list_filter = ['user', 'message', 'has_read', 'add_time'] 32 | 33 | 34 | 35 | class CourseCommentsAdmin(object): 36 | '''用户评论后台''' 37 | 38 | list_display = ['user', 'course', 'comments', 'add_time'] 39 | search_fields = ['user', 'course', 'comments'] 40 | list_filter = ['user', 'course', 'comments', 'add_time'] 41 | 42 | 43 | 44 | class UserFavoriteAdmin(object): 45 | '''用户收藏后台''' 46 | 47 | list_display = ['user', 'fav_id', 'fav_type', 'add_time'] 48 | search_fields = ['user', 'fav_id', 'fav_type'] 49 | list_filter = ['user', 'fav_id', 'fav_type', 'add_time'] 50 | 51 | 52 | # 将后台管理器与models进行关联注册。 53 | xadmin.site.register(UserAsk, UserAskAdmin) 54 | xadmin.site.register(UserCourse, UserCourseAdmin) 55 | xadmin.site.register(UserMessage, UserMessageAdmin) 56 | xadmin.site.register(CourseComments, CourseCommentsAdmin) 57 | xadmin.site.register(UserFavorite, UserFavoriteAdmin) -------------------------------------------------------------------------------- /CQNU-TED/templates/usercenter-mycourse.html: -------------------------------------------------------------------------------- 1 | {% extends 'usercenter-base.html' %} 2 | {% block title %} 3 | 我的课程 4 | {% endblock %} 5 | {% block custom_bread %} 6 |
7 |
8 | 13 |
14 |
15 | {% endblock %} 16 | 17 | {% block custom_right_content %} 18 |
19 |
20 |
21 |

我的课程

22 |
23 |
24 |
25 |
26 |
27 | {% for user_course in user_courses %} 28 |
29 | 30 | 31 | 32 |
33 |

{{ user_course.course.name }}

34 | 课时:{{ user_course.course.learn_times }} 35 | 学习人数:{{ user_course.course.students }} 36 |
37 |
38 | {{ user_course.course.course_org.name }} 39 | {{ user_course.course.fav_nums }} 40 |
41 |
42 | {% endfor %} 43 |
44 |
45 |
46 |
47 | {% endblock %} 48 | 49 | -------------------------------------------------------------------------------- /CQNU-TED/apps/utils/email_send.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from random import Random 3 | from django.core.mail import send_mail 4 | 5 | from apps.users.models import EmailVerifyRecord 6 | from online_studying.settings import EMAIL_FROM 7 | 8 | # 生产随机字符串 9 | def random_str(random_length=8): 10 | str = '' 11 | # 生成字符串的可选字符串 12 | chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789' 13 | length = len(chars) - 1 14 | random = Random() 15 | for i in range(random_length): 16 | str += chars[random.randint(0, length)] 17 | return str 18 | 19 | # 发送注册邮件 20 | def send_register_email(email, send_type="register"): 21 | # 发送之前先保存到数据库,到时候查询链接是否存在 22 | # 实例化一个EmailVerifyRecord对象 23 | email_record = EmailVerifyRecord() 24 | if send_type == "update_email": 25 | code = random_str(4) 26 | else: 27 | code = random_str(16) 28 | email_record.code = code 29 | email_record.email = email 30 | email_record.send_type = send_type 31 | 32 | email_record.save() 33 | # 定义邮件的内容 34 | email_title = "" 35 | email_body = "" 36 | if send_type == "register": 37 | email_title = "重师在线学习平台注册激活链接" 38 | email_body = "请点击下面的链接激活你的账号: http://127.0.0.1:8000/active/{0}".format(code) 39 | 40 | # 使用Django内置函数完成邮件发送。四个参数:主题,邮件内容,从哪里发,接受者list 41 | send_status = send_mail(email_title, email_body, EMAIL_FROM, [email]) 42 | if send_status: 43 | pass 44 | elif send_type == "forget": 45 | email_title = "重师网络教学平台注册密码重置链接" 46 | email_body = "请点击下面的链接重置密码: http://127.0.0.1:8000/reset/{0}".format(code) 47 | 48 | # 使用Django内置函数完成邮件发送。 49 | # 四个参数:主题,邮件内容,发件人邮箱地址,收件人(是一个字符串列表) 50 | send_status = send_mail(email_title, email_body, EMAIL_FROM, [email]) 51 | # 如果发送成功 52 | if send_status: 53 | pass 54 | elif send_type == "update_email": 55 | email_title = "重师在线平台邮箱修改验证码" 56 | email_body = "你的邮箱验证码为: {0}".format(code) 57 | 58 | send_status = send_mail(email_title, email_body, EMAIL_FROM, [email]) 59 | if send_status: 60 | pass 61 | -------------------------------------------------------------------------------- /CQNU-TED/templates/password_reset.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 密码修改 8 | 9 | 10 | 11 | 21 | 22 | 23 |
24 |
25 |

修改密码

26 |

已经通过验证,请设置新密码

27 |
28 |
    29 |
  • 30 | 新 密 码 : 31 | 32 | 33 |
  • 34 | 35 |
  • 36 | 确定密码: 37 | 38 | 39 |
  • 40 |
    41 | {% for key,error in modify_form.errors.items %}{{ key }}:{{ error }}{% endfor %}{{ msg }} 42 |
    43 |
  • 44 | 45 |
  • 46 |
47 | {% csrf_token %} 48 |
49 |
50 | 55 |
56 | 57 | -------------------------------------------------------------------------------- /CQNU-TED/apps/users/models.py: -------------------------------------------------------------------------------- 1 | # _*_ encoding:utf-8 _*_ 2 | # 第一个区域,放python自带的包 3 | from __future__ import unicode_literals 4 | from datetime import datetime 5 | 6 | from django.db import models 7 | from django.contrib.auth.models import AbstractUser 8 | # Create your models here. 9 | from django.db import models 10 | # from django.contrib.auth.models import AbstractUser 11 | 12 | # 继承Django自身的AbstractUser,沿用默认字段 13 | class UserProfile(AbstractUser): 14 | nick_name = models.CharField(max_length=50, verbose_name=u"昵称", default="") 15 | birthday = models.DateField(verbose_name=u"生日", null=True, blank=True) 16 | gender = models.CharField(max_length=6, choices=(("male",u"男"),("female","女")), default="female") 17 | address = models.CharField(max_length=100, default=u"") 18 | mobile = models.CharField(max_length=11, null=True, blank=True,verbose_name='手机号') 19 | # 增加用户头像字段,img/%Y/%m代表上传时按年月文件夹进行,default设置的是默认头像路径 20 | image = models.ImageField(upload_to="image/%Y/%m",default=u"image/default.png", max_length=100, verbose_name='头像') 21 | class Meta: 22 | verbose_name = "用户信息" # 设置UserProfile这个类的别名 23 | verbose_name_plural = verbose_name 24 | def __str__(self): 25 | return self.username # 当使用print打印时,把继承的username字段打印出来 26 | 27 | # 邮箱验证码 28 | class EmailVerifyRecord(models.Model): 29 | code = models.CharField(max_length=20, verbose_name=u"验证码") 30 | email = models.EmailField(max_length=50, verbose_name=u"邮箱") 31 | send_type = models.CharField(verbose_name=u"验证码类型", choices=(("register", u"注册"), ("forget", u"找回密码"), ("update_email",u"修改邮箱")), max_length=30) 32 | send_time = models.DateTimeField(verbose_name=u"发送时间", default=datetime.now) 33 | class Meta: 34 | verbose_name = u"邮箱验证码" 35 | verbose_name_plural = verbose_name 36 | def __str__(self): 37 | return '{0}({1})'.format(self.code, self.email) 38 | 39 | 40 | class Banner(models.Model): 41 | title = models.CharField(max_length=100, verbose_name=u"标题") 42 | image = models.ImageField(upload_to="banner/%Y/%m", verbose_name=u"轮播图", max_length=100) 43 | url = models.URLField(max_length=200, verbose_name=u"访问地址") 44 | # 默认index很大靠后。想要靠前修改index值 45 | index = models.IntegerField(default=100, verbose_name=u"顺序") 46 | add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间") 47 | class Meta: 48 | verbose_name = u"轮播图" 49 | verbose_name_plural = verbose_name 50 | 51 | -------------------------------------------------------------------------------- /CQNU-TED/templates/usercenter-fav-course.html: -------------------------------------------------------------------------------- 1 | {% extends 'usercenter-base.html' %} 2 | {% load staticfiles %} 3 | {% block title %} 4 | 我的收藏 5 | {% endblock %} 6 | {% block custom_bread %} 7 |
8 |
9 | 14 |
15 |
16 | {% endblock %} 17 | 18 | {% block custom_right_content %} 19 |
20 |
21 |
22 |

我的收藏

23 |
24 |
25 |
26 |
27 | 32 | 33 |
34 |
35 |
36 | {% for fav_course in course_list %} 37 |
38 | 39 | 40 | 41 |
42 |

{{ fav_course.name }}

43 | 时长:{{ fav_course.learn_times }} 44 | 学习人数:{{ fav_course.students }} 45 |
46 |
47 | {{ fav_course.course_org.name }} 48 | 49 |
50 |
51 | {% endfor %} 52 |
53 |
54 |
55 |
56 | {% endblock %} 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /CQNU-TED/apps/operation/models.py: -------------------------------------------------------------------------------- 1 | # _*_ encoding:utf-8 _*_ 2 | from __future__ import unicode_literals 3 | from datetime import datetime 4 | from django.db import models 5 | from apps.course.models import Course 6 | from apps.users.models import UserProfile 7 | 8 | # Create your models here. 9 | # 用户咨询 10 | class UserAsk(models.Model): 11 | name = models.CharField(max_length=20, verbose_name=u"姓名") 12 | mobile = models.CharField(max_length=11, verbose_name=u"手机") 13 | course_name = models.CharField(max_length=50, verbose_name=u"课程名") 14 | add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间") 15 | 16 | class Meta: 17 | verbose_name = u"用户咨询" 18 | verbose_name_plural = verbose_name 19 | 20 | def __str__(self): 21 | return self.name 22 | 23 | 24 | class CourseComments(models.Model): 25 | # 课程评论 设计两个外键:1.用户 2.课程 26 | user = models.ForeignKey(UserProfile, verbose_name=u"用户",on_delete=models.CASCADE) 27 | course = models.ForeignKey(Course, verbose_name=u"课程",on_delete=models.CASCADE) 28 | comments = models.CharField(max_length=200, verbose_name=u"评论") 29 | add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间") 30 | 31 | class Meta: 32 | verbose_name = u"课程评论" 33 | verbose_name_plural = verbose_name 34 | 35 | 36 | # 用户对于课程,学院,讲师的收藏 37 | class UserFavorite(models.Model): 38 | # 涉及四个外键。用户,课程,学院,讲师 39 | user = models.ForeignKey(UserProfile, verbose_name=u"用户",on_delete=models.CASCADE) 40 | fav_id = models.IntegerField(default=0, verbose_name=u"数据id") # 直接保存用户id 41 | fav_type = models.IntegerField(choices=((1,"课程"), (2,"课程学院"),(3,"讲师")), default=1, verbose_name=u"收藏类型") 42 | add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间") 43 | 44 | class Meta: 45 | verbose_name = u"用户收藏" 46 | verbose_name_plural = verbose_name 47 | 48 | 49 | class UserMessage(models.Model): 50 | # 因为我们的消息有两种:发给全员和发给某一个用户。 51 | # 所以如果使用外键,每个消息会对应要有用户。很难实现全员消息。 52 | 53 | # 机智版 为0发给所有用户,不为0就是发给用户的id 54 | user = models.IntegerField(default=0, verbose_name=u"接收用户") 55 | message = models.CharField(max_length=500, verbose_name=u"消息内容") 56 | has_read = models.BooleanField(default=False, verbose_name=u"是否已读") 57 | add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间") 58 | 59 | class Meta: 60 | verbose_name = u"用户消息" 61 | verbose_name_plural = verbose_name 62 | 63 | 64 | class UserCourse(models.Model): 65 | # 两个外键:1.用户,2.课程. 66 | user = models.ForeignKey(UserProfile, verbose_name=u"用户",on_delete=models.CASCADE) 67 | course = models.ForeignKey(Course, verbose_name=u"课程",on_delete=models.CASCADE) 68 | add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间") 69 | 70 | class Meta: 71 | verbose_name = u"用户课程" 72 | verbose_name_plural = verbose_name -------------------------------------------------------------------------------- /CQNU-TED/templates/usercenter-message.html: -------------------------------------------------------------------------------- 1 | {% extends 'usercenter-base.html' %} 2 | {% load staticfiles %} 3 | {% block title %} 4 | 我的消息 5 | {% endblock %} 6 | {% block custom_bread %} 7 |
8 |
9 | 14 |
15 |
16 | {% endblock %} 17 | 18 | {% block custom_right_content %} 19 |
20 |
21 |
22 |

我的消息

23 |
24 | 25 |
26 |
27 |
28 | 31 |
32 |
33 | {% for message in messages.object_list %} 34 |
35 |
36 |
{{ message.add_time }}
37 |

38 | {{ message.message }} 39 |

40 |
41 |
42 | {% endfor %} 43 |
44 | 45 |
46 |
    47 | {% if messages.has_previous %} 48 |
  • 上一页
  • 49 | {% endif %} 50 | 51 | {% for page in messages.pages %} 52 | {% if page %} 53 | {% ifequal page messages.number %} 54 |
  • {{ page }}
  • 55 | {% else %} 56 |
  • {{ page }}
  • 57 | {% endifequal %} 58 | {% else %} 59 |
  • ...
  • 60 | {% endif %} 61 | {% endfor %} 62 | {% if messages.has_next %} 63 |
  • 下一页
  • 64 | {% endif %} 65 |
66 |
67 |
68 | 69 |
70 | {% endblock %} 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /CQNU-TED/templates/usercenter-fav-teacher.html: -------------------------------------------------------------------------------- 1 | {% extends 'usercenter-base.html' %} 2 | {% load staticfiles %} 3 | {% block title %} 4 | 我的收藏 5 | {% endblock %} 6 | {% block custom_bread %} 7 |
8 |
9 | 14 |
15 |
16 | {% endblock %} 17 | 18 | {% block custom_right_content %} 19 |
20 |
21 |
22 |

我的收藏

23 |
24 |
25 |
26 |
27 | 32 |
33 |
34 | {% for teacher in teacher_list %} 35 |
36 |
37 |
38 | 39 | 40 | 41 |
42 |
43 |

44 | 45 | {{ teacher.name }}认证教师 46 | 47 |

48 |
    49 |
  • 工作年限:{{ teacher.work_years }}年
  • 50 |
  • 课程数:{{ teacher.get_course_nums }}
  • 51 |
52 |
    53 |
  • 工作公司:{{ teacher.work_company }}
  • 54 |
  • 公司职位:{{ teacher.work_position }}
  • 55 |
56 |
57 |
58 |
59 |
60 | {% endfor %} 61 | 62 | 63 | 64 | 65 | 66 |
67 |
68 |
69 | {% endblock %} 70 | 71 | 72 | -------------------------------------------------------------------------------- /CQNU-TED/online_studying/urls.py: -------------------------------------------------------------------------------- 1 | """online_studying path Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/2.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a path to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a path to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a path to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path, re_path 18 | from django.conf.urls import include,url 19 | from django.views.generic import TemplateView #导入view,表示处理的是静态文件 20 | from apps.users.views import LogoutView, LoginView, RegisterView, ActiveUserView, ForgetPwdView, ResetView, ModifyPwdView 21 | from django.views.generic import RedirectView 22 | import xadmin 23 | from apps.users.views import IndexView 24 | from django.views.static import serve 25 | from apps.organization.views import OrgView 26 | from DjangoUeditor import urls as djud_urls 27 | from online_studying.settings import MEDIA_ROOT 28 | from apps.course.views import CourseDetailView 29 | 30 | 31 | urlpatterns = [ 32 | path('xadmin/', xadmin.site.urls), 33 | # path('', TemplateView.as_view(template_name='index.html'), name='index'), 34 | path('login/', LoginView.as_view(), name='login'), 35 | # 注册url 36 | path("register/", RegisterView.as_view(), name="register"), # 通过类的as_view方法,调用这个view类 37 | path('', IndexView.as_view(), name="index"), 38 | # 退出功能url 39 | path('logout/', LogoutView.as_view(), name="logout"), 40 | # 验证码url 41 | path('captcha/', include('captcha.urls')), 42 | # 激活用户url 43 | re_path('active/(?P.*)/', ActiveUserView.as_view(), name="user_active"), 44 | # 忘记密码 45 | path('forget/', ForgetPwdView.as_view(), name="forget_pwd"), 46 | # 重置密码url :用来接收来自邮箱的重置链接 47 | re_path('reset/(?P.*)/', ResetView.as_view(), name="reset_pwd"), 48 | # 修改密码url; post提交的地方与get方式url中的地址不一样 49 | path('modify_pwd/', ModifyPwdView.as_view(), name="modify_pwd"), 50 | # 课程机构app的url配置,讲师的也在里面 51 | path("org/", include('apps.organization.urls', namespace='org')), 52 | # 课程机构首页url 53 | # path('org_list/', OrgView.as_view(), name='org_list'), 54 | 55 | # 课程app的url配置 56 | path("course/", include('apps.course.urls', namespace="course")), 57 | # re_path('course/(?P\d+)/', CourseDetailView.as_view(), name="course_detail"), 58 | # 处理图片显示的url,使用Django自带serve,传入参数告诉它去哪个路径找,我们有配置好的路径MEDIAROOT 59 | re_path('media/(?P.*)', serve, {"document_root": MEDIA_ROOT}), 60 | # url(r'^static/(?P.*)$', serve, {"document_root":STATIC_ROOT}), 61 | # user app的url配置 62 | path("users/", include('apps.users.urls', namespace="users")), 63 | # 富文本相关url 64 | path('ueditor/', include('DjangoUeditor.urls')), 65 | ] 66 | # 全局404页面配置 67 | handler404 = 'users.views.page_not_found' 68 | handler500 = 'users.views.page_error' 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /CQNU-TED/templates/org-detail-homepage.html: -------------------------------------------------------------------------------- 1 | {#templates/org-detail-homepage.html#} 2 | 3 | {% extends 'org_base.html' %} 4 | 5 | {% block title %}学院首页{% endblock %} 6 | {% block page_path %}学院首页{% endblock %} 7 | 8 | {% block right_form %} 9 |
10 |
11 |

全部课程

12 | 查看更多 > 13 |
14 |
15 | {% for course in all_courses %} 16 |
17 | 18 |
19 |

{{ course.name }}

20 | 课时:{{ course.learn_times }} 21 | 参加人数:{{ course.students }} 22 |
23 |
24 | {{ course.course_org.name }} 25 | 27 | {{ course.fav_nums }} 28 | 29 |
30 |
31 | {% endfor %} 32 |
33 |
34 |
35 |
36 |

学院教师

37 | 查看更多 > 38 |
39 | {% for teacher in all_teacher %} 40 |
41 | 56 |
57 | {% endfor %} 58 |
59 | 60 | 61 |
62 |
63 |

学院介绍

64 | 查看更多 > 65 |
66 |
   

{{ course_org.desc }}

67 |

68 |

69 | 70 |

71 | [查看更多]
72 |
73 | {% endblock %} -------------------------------------------------------------------------------- /CQNU-TED/apps/organization/models.py: -------------------------------------------------------------------------------- 1 | # _*_ encoding:utf-8 _*_ 2 | from __future__ import unicode_literals 3 | from datetime import datetime 4 | 5 | from django.db import models 6 | from DjangoUeditor.models import UEditorField 7 | # Create your models here. 8 | 9 | # 城市信息和课程结构信息 10 | class CityDict(models.Model): 11 | name = models.CharField(max_length=20, verbose_name=u"城市") 12 | desc = models.CharField(max_length=200, verbose_name=u"描述") 13 | add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间") 14 | 15 | class Meta: 16 | verbose_name = u"城市" 17 | verbose_name_plural = verbose_name 18 | 19 | def __str__(self): 20 | return self.name 21 | 22 | 23 | class CourseOrg(models.Model): 24 | name = models.CharField(max_length=50, verbose_name=u"学院名称") 25 | desc = UEditorField(verbose_name=u"学院描述",width=900, height=300, imagePath="org/ueditor/", 26 | filePath="org/ueditor/", default='') 27 | tag = models.CharField(default="全国知名", max_length=10, verbose_name=u"学院标签") 28 | category = models.CharField(default="pxjg", verbose_name=u"学院类别", max_length=20, choices=(("pxjg","大学"),("gr","个人"),("gx","研究生"))) 29 | click_nums = models.IntegerField(default=0, verbose_name=u"点击数") 30 | fav_nums = models.IntegerField(default=0, verbose_name=u"收藏数") 31 | # /media/org/2018/月份/图片名字 32 | image = models.ImageField(upload_to="org/%Y/%m", verbose_name=u"logo", max_length=100) 33 | address = models.CharField(max_length=150, verbose_name=u"学院地址") 34 | city = models.ForeignKey(CityDict, verbose_name=u"所在城市",on_delete=models.CASCADE) 35 | students = models.IntegerField(default=0, verbose_name=u"学习人数") 36 | course_nums = models.IntegerField(default=0, verbose_name=u"课程数") 37 | add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间") 38 | 39 | class Meta: 40 | verbose_name = u"课程学院" 41 | verbose_name_plural = verbose_name 42 | 43 | def get_teacher_nums(self): 44 | # 获取学院的教师数 45 | return self.teacher_set.all().count() 46 | 47 | def __str__(self): 48 | return self.name 49 | 50 | 51 | # 讲师 52 | class Teacher(models.Model): 53 | # 一个学院会有很多老师,所以我们在讲师表添加外键并把课程学院名称保存下来 54 | # 可以使我们通过讲师找到对应的学院 55 | org = models.ForeignKey(CourseOrg, verbose_name=u"所属学院",on_delete=models.CASCADE, null=True, blank=True) 56 | name = models.CharField(max_length=50, verbose_name=u"教师名") 57 | work_years = models.IntegerField(default=0, verbose_name=u"工作年限") 58 | work_company = models.CharField(max_length=50, verbose_name=u"就职学校") 59 | work_position = models.CharField(max_length=50, verbose_name=u"教师级别") 60 | points = models.CharField(max_length=50, verbose_name=u"教学特点") 61 | click_nums = models.IntegerField(default=0, verbose_name=u"点击数") 62 | fav_nums = models.IntegerField(default=0, verbose_name=u"收藏数") 63 | age = models.IntegerField(default=25, verbose_name=u"年龄") 64 | image = models.ImageField(default='', upload_to="teacher/%Y/%m", verbose_name=u"头像", max_length=100) 65 | add_time = models.DateTimeField(default=datetime.now,verbose_name=u"添加时间") 66 | 67 | class Meta: 68 | verbose_name = u"教师" 69 | verbose_name_plural = verbose_name 70 | 71 | def __str__(self): 72 | return "[{0}]的教师: {1}".format(self.org, self.name) 73 | 74 | def get_course_nums(self): 75 | return self.course_set.all().count() 76 | 77 | 78 | -------------------------------------------------------------------------------- /CQNU-TED/templates/usercenter-fav-org.html: -------------------------------------------------------------------------------- 1 | {% extends 'usercenter-base.html' %} 2 | {% load staticfiles %} 3 | {% block title %} 4 | 我的收藏 5 | {% endblock %} 6 | {% block custom_bread %} 7 |
8 |
9 | 14 |
15 |
16 | {% endblock %} 17 | 18 | {% block custom_right_content %} 19 |
20 |
21 |
22 |

我的收藏

23 |
24 | 25 |
26 |
27 |
28 | 33 |
34 |
35 | {% for org in org_list %} 36 |
37 |
38 |
39 | 40 | 41 | 42 |
43 |
44 |

{{ org.name }}

45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 |
53 | {{ org.address }} 54 |
55 |
56 |
57 |
58 | {% endfor %} 59 |
60 |
61 |
62 | {% endblock %} 63 | 64 | 65 | {% for user_course in user_courses %} 66 |
67 | 68 | 69 | 70 |
71 |

{{ user_course.course.name }}

72 | 课时:{{ user_course.course.learn_times }} 73 | 学习人数:{{ user_course.course.students }} 74 |
75 |
76 | {{ user_course.course.course_org.name }} 77 | {{ user_course.course.fav_nums }} 78 |
79 |
80 | {% endfor %} 81 | 82 | 83 | -------------------------------------------------------------------------------- /CQNU-TED/apps/course/adminx.py: -------------------------------------------------------------------------------- 1 | # course/adminx.py 2 | 3 | import xadmin 4 | from .models import Course, Lesson, Video, CourseResource, BannerCourse 5 | # 上传视频 6 | from .models import Videoup 7 | class LessonInline(object): 8 | model = Lesson 9 | extra = 0 10 | 11 | class CourseResourceInline(object): 12 | model = CourseResource 13 | extra = 0 14 | 15 | 16 | # Course的admin管理器 17 | class CourseAdmin(object): 18 | '''课程''' 19 | 20 | list_display = [ 'name','desc','detail','degree','learn_times','students','get_zj_nums','go_to'] #显示的字段 21 | search_fields = ['name', 'desc', 'detail', 'degree', 'students'] #搜索 22 | list_filter = [ 'name','desc','detail','degree','learn_times','students'] #过滤 23 | model_icon = 'fa fa-book' #图标 24 | ordering = ['-click_nums'] #排序 25 | readonly_fields = ['click_nums'] #只读字段 26 | exclude = ['fav_nums'] #不显示的字段 27 | # list_editable = ['degree','desc'] 28 | # refresh_times = [3,5] #自动刷新(里面是秒数范围) 29 | inlines = [LessonInline,CourseResourceInline] #增加章节和课程资源 30 | style_fields = {"detail": "ueditor"} 31 | 32 | def queryset(self): 33 | # 重载queryset方法,来过滤出我们想要的数据的 34 | qs = super(CourseAdmin, self).queryset() 35 | # 只显示is_banner=True的课程 36 | qs = qs.filter(is_banner=False) 37 | return qs 38 | 39 | def save_models(self): 40 | # 在保存课程的时候统计课程机构的课程数 41 | # obj实际是一个course对象 42 | obj = self.new_obj 43 | # 如果这里不保存,新增课程,统计的课程数会少一个 44 | obj.save() 45 | # 确定课程的课程机构存在。 46 | if obj.course_org is not None: 47 | #找到添加的课程的课程机构 48 | course_org = obj.course_org 49 | #课程机构的课程数量等于添加课程后的数量 50 | course_org.course_nums = Course.objects.filter(course_org=course_org).count() 51 | course_org.save() 52 | 53 | 54 | class BannerCourseAdmin(object): 55 | '''轮播课程''' 56 | 57 | list_display = [ 'name','desc','detail','degree','learn_times','students'] 58 | search_fields = ['name', 'desc', 'detail', 'degree', 'students'] 59 | list_filter = [ 'name','desc','detail','degree','learn_times','students'] 60 | model_icon = 'fa fa-book' 61 | ordering = ['-click_nums'] 62 | readonly_fields = ['click_nums'] 63 | exclude = ['fav_nums'] 64 | inlines = [LessonInline,CourseResourceInline] 65 | 66 | def queryset(self): 67 | #重载queryset方法,来过滤出我们想要的数据的 68 | qs = super(BannerCourseAdmin, self).queryset() 69 | #只显示is_banner=True的课程 70 | qs = qs.filter(is_banner=True) 71 | return qs 72 | 73 | class LessonAdmin(object): 74 | '''章节''' 75 | 76 | list_display = ['course', 'name', 'add_time'] 77 | search_fields = ['course', 'name'] 78 | #这里course__name是根据课程名称过滤 79 | list_filter = ['course__name', 'name', 'add_time'] 80 | 81 | 82 | class VideoAdmin(object): 83 | '''视频''' 84 | 85 | list_display = ['lesson', 'name', 'add_time'] 86 | search_fields = ['lesson', 'name'] 87 | list_filter = ['lesson', 'name', 'add_time'] 88 | 89 | class CourseResourceAdmin(object): 90 | '''课程资源''' 91 | 92 | list_display = ['course', 'name', 'download', 'add_time'] 93 | search_fields = ['course', 'name', 'download'] 94 | list_filter = ['course__name', 'name', 'download', 'add_time'] 95 | 96 | class Video_upAdmin(object): 97 | '''上传video''' 98 | list_display = ['name', 'upload'] 99 | search_fields = ['name', 'upload'] 100 | list_filter = ['name', 'upload'] 101 | # 将管理器与model进行注册关联 102 | xadmin.site.register(Course, CourseAdmin) 103 | xadmin.site.register(BannerCourse, BannerCourseAdmin) 104 | xadmin.site.register(Lesson, LessonAdmin) 105 | xadmin.site.register(Video, VideoAdmin) 106 | xadmin.site.register(Videoup, Video_upAdmin) 107 | xadmin.site.register(CourseResource, CourseResourceAdmin) -------------------------------------------------------------------------------- /CQNU-TED/templates/usercenter-info.html: -------------------------------------------------------------------------------- 1 | {% extends 'usercenter-base.html' %} 2 | {% block title %} 3 | 个人信息 4 | {% endblock %} 5 | {% block custom_bread %} 6 |
7 |
8 | 13 |
14 |
15 | {% endblock %} 16 | 17 | {% block custom_right_content %} 18 |
19 |
20 |
21 |

个人信息

22 |
23 |
24 |
25 | 26 |
27 | 36 | 37 | {% csrf_token %} 38 |
39 |
40 | 修改密码 41 |
42 |
43 |
44 |
    45 |
  • 昵       称: 46 | 47 | 48 |
  • 49 |
  • 生       日: 50 | 51 | 52 |
  • 53 |
  • 性       别: 54 | 55 | 56 |
  • 57 |
  • 地       址: 58 | 59 | 60 |
  • 61 |
  • 手  机  号: 62 | 63 |
  • 64 |
  • 邮       箱: 65 | 66 | [修改] 67 |
  • 68 |
  • 69 | 70 |
  • 71 |
72 | {% csrf_token %} 73 |
74 |
75 |
76 |
77 | {% endblock %} 78 | -------------------------------------------------------------------------------- /CQNU-TED/online_studying/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for online_studying project. 3 | 4 | Generated by 'django-admin startproject' using Django 2.0.3. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/2.0/ref/settings/ 11 | """ 12 | 13 | import os 14 | import sys 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | sys.path.insert(0,os.path.join(BASE_DIR, 'apps')) 18 | # Quick-start development settings - unsuitable for production 19 | # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ 20 | 21 | # SECURITY WARNING: keep the secret key used in production secret! 22 | SECRET_KEY = 'n7o)y21z#t7z2ess6z!(6l1out!5fl^*=lneh2y+-slg!i^@u*' 23 | 24 | # SECURITY WARNING: don't run with debug turned on in production! 25 | DEBUG = True 26 | ALLOWED_HOSTS = ['*'] 27 | # Application definition 28 | AUTHENTICATION_BACKENDS = ( 29 | 'apps.users.views.CustomBackend', 30 | ) 31 | # Application definition 32 | INSTALLED_APPS = [ 33 | 'django.contrib.admin', 34 | 'django.contrib.auth', 35 | 'django.contrib.contenttypes', 36 | 'django.contrib.sessions', 37 | 'django.contrib.messages', 38 | 'django.contrib.staticfiles', 39 | 'apps.users', 40 | 'apps.organization', 41 | 'apps.operation', 42 | 'apps.course', 43 | 'xadmin', 44 | 'crispy_forms', 45 | # 验证码 46 | 'captcha', 47 | # 百度富文本插件 48 | 'DjangoUeditor', 49 | # 分页插件 50 | 'pure_pagination', 51 | ] 52 | AUTH_USER_MODEL="users.UserProfile" # 修改默认用户图像 53 | 54 | MIDDLEWARE = [ 55 | 'django.middleware.security.SecurityMiddleware', 56 | 'django.contrib.sessions.middleware.SessionMiddleware', 57 | 'django.middleware.common.CommonMiddleware', 58 | 'django.middleware.csrf.CsrfViewMiddleware', 59 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 60 | 'django.contrib.messages.middleware.MessageMiddleware', 61 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 62 | ] 63 | ROOT_URLCONF = 'online_studying.urls' 64 | TEMPLATES = [ 65 | { 66 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 67 | 'DIRS': [os.path.join(BASE_DIR, 'templates')], 68 | 'APP_DIRS': True, 69 | 'OPTIONS': { 70 | 'context_processors': [ 71 | 'django.template.context_processors.debug', 72 | 'django.template.context_processors.request', 73 | 'django.contrib.auth.context_processors.auth', 74 | 'django.contrib.messages.context_processors.messages', 75 | # 添加图片处理器,为了在课程列表中前面加上MEDIA_URL 76 | 'django.template.context_processors.media', 77 | ], 78 | }, 79 | }, 80 | ] 81 | WSGI_APPLICATION = 'online_studying.wsgi.application' 82 | 83 | 84 | # Database 85 | # https://docs.djangoproject.com/en/2.0/ref/settings/#databases 86 | 87 | DATABASES = { 88 | 'default': { 89 | 'ENGINE': 'django.db.backends.mysql', 90 | 'NAME': 'online', 91 | 'USER': 'root', 92 | 'PASSWORD': '9527', 93 | 'HOST': '127.0.0.1', 94 | 'PORT': '3306', 95 | } 96 | } 97 | # Password validation 98 | # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators 99 | 100 | AUTH_PASSWORD_VALIDATORS = [ 101 | { 102 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 103 | }, 104 | { 105 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 106 | }, 107 | { 108 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 109 | }, 110 | { 111 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 112 | }, 113 | ] 114 | # Internationalization 115 | # https://docs.djangoproject.com/en/2.0/topics/i18n/ 116 | LANGUAGE_CODE = 'zh-hans' 117 | TIME_ZONE = 'Asia/Shanghai' 118 | USE_I18N = True 119 | USE_L10N = True 120 | USE_TZ = False # 使用本地时间,而不是UTC时 121 | # Static files (CSS, JavaScript, Images) 122 | # https://docs.djangoproject.com/en/2.0/howto/static-files/ 123 | STATIC_URL = '/static/' 124 | STATICFILES_DIRS = [ 125 | os.path.join(BASE_DIR, 'static') 126 | ] 127 | 128 | # 使用新浪邮箱 129 | EMAIL_HOST = "smtp.sina.cn" # SMTP服务器主机 130 | EMAIL_PORT = 25 # 端口 131 | EMAIL_HOST_USER = "carrychang@sina.cn" # 邮箱地址 132 | EMAIL_HOST_PASSWORD = "Zhang1017" # 邮箱授权码 133 | EMAIL_USE_TLS = True 134 | EMAIL_FROM = "carrychang@sina.cn" # 与邮箱一致 135 | # 设置文件上传路径 136 | MEDIA_URL = '/media/' 137 | MEDIA_ROOT = os.path.join(BASE_DIR, 'media') # 指定根目录 138 | 139 | 140 | -------------------------------------------------------------------------------- /CQNU-TED/templates/login.html: -------------------------------------------------------------------------------- 1 | {#templates/login.html#} 2 | 3 | 4 | {% load staticfiles %} 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 |

我们已经向您的邮箱12@13.com发送了邮件,
为保证您的账号安全,请及时验证邮箱

30 |

去邮箱验证

31 |

32 | 33 |

没收到,您可以查看您的垃圾邮件和被过滤邮件,
也可以再次发送验证邮件

34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |

重庆师范大学网络学习系统软件,在线学习平台!

42 | 47 |
48 |
49 |
50 |
51 |
52 | 92 |
93 |
94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /CQNU-TED/templates/teachers-list.html: -------------------------------------------------------------------------------- 1 | {#templates/teacher-list.html#} 2 | {% extends 'base.html' %} 3 | {% load staticfiles %} 4 | {% block title %}授课教师{% endblock %} 5 | 6 | {% block custom_bread %} 7 |
8 |
9 |
    10 |
  • 首页>
  • 11 |
  • 课程教师
  • 12 |
13 |
14 |
15 | {% endblock %} 16 | 17 | 18 | {% block content %} 19 |
20 |
21 |
22 |
23 |
24 | 28 |
{{ teacher_nums }}人   
29 |
30 | 31 | {% for teacher in all_teachers.object_list %} 32 |
33 |
34 | 35 |
36 | 37 |
38 |
39 |
40 |
45 | 分享 46 | 47 |
48 |
49 |
50 |
51 | 52 |

{{ teacher.name }}金牌教师

53 |
54 |
    55 |
  • 工作年限:{{ teacher.work_years }}年
  • 56 |
  • 工作职位:{{ teacher.work_position }}
  • 57 |
  • 就职学校:{{ teacher.work_company }} 
  • 58 |
  • 年龄:{{ teacher.age }}岁
  • 59 |
  • 教学特点:{{ teacher.points }}
  • 60 |
61 |
62 |
查看
详情
63 |
64 | {% endfor %} 65 | 66 | 67 | 68 | 69 | 70 |
71 | 72 |
73 |
    74 | {% if all_teachers.has_previous %} 75 |
  • 上一页
  • 76 | {% endif %} 77 | 78 | {% for page in all_teachers.pages %} 79 | {% if page %} 80 | {% ifequal page all_teachers.number %} 81 |
  • {{ page }}
  • 82 | {% else %} 83 |
  • {{ page }}
  • 84 | {% endifequal %} 85 | {% else %} 86 |
  • ...
  • 87 | {% endif %} 88 | {% endfor %} 89 | {% if all_teachers.has_next %} 90 |
  • 下一页
  • 91 | {% endif %} 92 |
93 |
94 |
95 | 96 | 97 |
98 |
教师排行榜
99 | {% for hot_teacher in sorted_teacher %} 100 |
101 | 1 102 | 103 |
104 | 105 |
106 |
107 |
108 | 109 |

{{ hot_teacher.name }}

110 |
111 |

工作年限:{{ hot_teacher.work_years }}年

112 |
113 |
114 | {% endfor %} 115 |
116 |
117 |
118 | {% endblock %} 119 | -------------------------------------------------------------------------------- /CQNU-TED/apps/course/models.py: -------------------------------------------------------------------------------- 1 | # _*_ encoding:utf-8 _*_ 2 | from __future__ import unicode_literals 3 | from datetime import datetime 4 | from django.db import models 5 | from DjangoUeditor.models import UEditorField 6 | from apps.organization.models import CourseOrg, Teacher 7 | 8 | # 课程信息表 9 | class Course(models.Model): 10 | name = models.CharField(max_length=50, verbose_name=u"课程名") 11 | desc = models.CharField(max_length=300, verbose_name=u"课程描述") 12 | detail = UEditorField(verbose_name=u"课程详情",width=600, height=300, imagePath="courses/ueditor/",filePath="courses/ueditor/", default='') 13 | is_banner = models.BooleanField(default=False, verbose_name=u"是否轮播") 14 | degree = models.CharField(verbose_name=u"难度", choices=(("cj","初级"), ("zj","中级"), ("gj","高级")), max_length=2) 15 | learn_times = models.IntegerField(default=0, verbose_name=u"学习时长(分钟数)") 16 | students = models.IntegerField(default=0, verbose_name=u'学习人数') 17 | fav_nums = models.IntegerField(default=0, verbose_name=u'收藏人数') 18 | image = models.ImageField(upload_to="courses/%Y/%m", verbose_name=u"封面图", max_length=100) 19 | click_nums = models.IntegerField(default=0, verbose_name=u"点击数") 20 | add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间") 21 | course_org = models.ForeignKey(CourseOrg, on_delete=models.CASCADE, verbose_name="所属学院", null=True, blank=True) 22 | category = models.CharField('课程类别', max_length=20, default='') 23 | tag = models.CharField('课程标签', default='', max_length=10) 24 | teacher = models.ForeignKey(Teacher, verbose_name='教师', null=True, on_delete=models.CASCADE, blank=True) 25 | youneed_know = models.CharField("上课须知", max_length=300, default='') 26 | teacher_tell = models.CharField('悄悄告诉你', max_length=300, default='') 27 | class Meta: 28 | verbose_name = u"课程" 29 | verbose_name_plural = verbose_name 30 | def get_zj_nums(self): 31 | # 获取课程的章节数 32 | return self.lesson_set.all().count() 33 | get_zj_nums.short_description = '章节数' # 在后台显示的名称 34 | def go_to(self): 35 | from django.utils.safestring import mark_safe 36 | # mark_safe后就不会转义 37 | return mark_safe("跳转") 38 | go_to.short_description = "跳转" 39 | 40 | def get_course_lesson(self): 41 | # 获取课程的章节 42 | return self.lesson_set.all() 43 | def get_learn_users(self): 44 | # 获取这门课程的学习用户 45 | return self.usercourse_set.all()[:5] 46 | 47 | def __str__(self): 48 | return self.name 49 | 50 | 51 | class BannerCourse(Course): 52 | # 显示轮播课程 53 | class Meta: 54 | verbose_name = '轮播课程' 55 | verbose_name_plural = verbose_name 56 | # 这里必须设置proxy=True,这样就不会在生成一张表,而且具有Model的功能 57 | proxy = True 58 | 59 | # lesson章节 60 | class Lesson(models.Model): 61 | # 因为一个课程对应很多章节。所以在章节中将课程设置为外键 62 | # 作为一个字段来让我们可以知道这个章节对应哪个课程 63 | course = models.ForeignKey(Course, verbose_name=u"课程", on_delete=models.CASCADE, null=True, blank=True) 64 | name = models.CharField(max_length=100, verbose_name=u"章节名") 65 | learn_times = models.IntegerField(default=0, verbose_name=u"学习时长(分钟数)") 66 | add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间") 67 | class Meta: 68 | verbose_name = u"章节" 69 | verbose_name_plural = verbose_name 70 | def get_lesson_video(self): 71 | # 获取章节所有视频 72 | return self.video_set.all() 73 | 74 | def __str__(self): 75 | return '《{0}》课程的章节 >> {1}'.format(self.course, self.name) 76 | 77 | 78 | # video 79 | class Video(models.Model): 80 | lesson = models.ForeignKey(Lesson, verbose_name=u"章节", on_delete=models.CASCADE, null=True, blank=True) 81 | name = models.CharField(max_length=100, verbose_name=u"视频名") 82 | learn_times = models.IntegerField(default=0, verbose_name=u"学习时长(分钟数)") 83 | url = models.CharField(max_length=200, default="", verbose_name=u"访问地址") 84 | add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间") 85 | class Meta: 86 | verbose_name = u"视频" 87 | verbose_name_plural = verbose_name 88 | def __str__(self): 89 | return self.name 90 | # CourseResource 课程资源 91 | class CourseResource(models.Model): 92 | course = models.ForeignKey(Course, verbose_name=u"课程", on_delete=models.CASCADE, null=True, blank=True) 93 | name = models.CharField(max_length=100, verbose_name=u"名称") 94 | download = models.FileField(upload_to="course/resource/%Y/%m", verbose_name=u"资源文件", max_length=100) 95 | add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间") 96 | class Meta: 97 | verbose_name = u"课程资源" 98 | verbose_name_plural = verbose_name 99 | def __str__(self): 100 | return self.name 101 | # Videoup 上传视频,写完之后记得对数据库进行更新(先makemigrations,再migrate) 102 | class Videoup(models.Model): 103 | name = models.CharField(max_length=100, verbose_name=u"视频名") 104 | upload = models.FileField(upload_to='video/', verbose_name=u"视频文件", max_length=100) 105 | class Meta: 106 | verbose_name = u"上传视频" 107 | verbose_name_plural = verbose_name 108 | def __str__(self): 109 | return self.name -------------------------------------------------------------------------------- /CQNU-TED/templates/course-list.html: -------------------------------------------------------------------------------- 1 | {#templates/course-list.html#} 2 | 3 | {% extends 'base.html' %} 4 | {% load staticfiles %} 5 | {% block title %}公开课列表{% endblock %} 6 | 7 | {% block custom_bread %} 8 |
9 |
10 |
    11 |
  • 首页>
  • 12 |
  • 公开课
  • 13 |
14 |
15 |
16 | {% endblock %} 17 | 18 | {% block content %} 19 |
20 |
21 |
22 |
23 |
24 | 29 |
30 |
31 |
32 |
33 | {% for course in all_courses.object_list %} 34 |
35 | 36 | 37 | 38 |
39 | 40 |

{{ course.name }}

41 |
42 | 时长:{{ course.learn_times }} 43 | 学习人数:{{ course.students }}   44 |
45 |
46 | 来自{{ course.course_org.name }} 47 | 49 | {{ course.fav_nums }} 50 | 51 |
52 |
53 | {% endfor %} 54 |
55 |
56 |
    57 | {% if all_courses.has_previous %} 58 |
  • 上一页
  • 59 | {% endif %} 60 | 61 | {% for page in all_courses.pages %} 62 | {% if page %} 63 | {% ifequal page all_courses.number %} 64 |
  • {{ page }}
  • 65 | {% else %} 66 |
  • {{ page }}
  • 67 | {% endifequal %} 68 | {% else %} 69 |
  • ...
  • 70 | {% endif %} 71 | {% endfor %} 72 | {% if all_courses.has_next %} 73 |
  • 下一页
  • 74 | {% endif %} 75 |
76 |
77 |
78 |
79 |
80 |
81 |
热门课程推荐
82 |
83 | {% for hot_course in hot_courses %} 84 |
85 |
86 | 87 | 88 | 89 |
90 |
91 |

{{ hot_course.name }}

92 | 难度:{{ hot_course.get_degree_display }} 93 |
94 |
95 | {% endfor %} 96 | 97 | 98 | 99 | 100 | 101 | 102 |
103 |
104 |
105 |
106 |
107 | {% endblock %} 108 | 109 | course-list.html -------------------------------------------------------------------------------- /CQNU-TED/templates/forgetpwd.html: -------------------------------------------------------------------------------- 1 | {#templates/forgetpwd.html#} 2 | 3 | 4 | {% load staticfiles %} 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 |
32 |
33 | 确 认 密 码 34 | 35 |
36 |
37 | 验  证  码 38 | 39 |
40 |
41 |
42 | 43 | 44 |
45 | 46 |
47 |
48 |
49 |
50 |
51 |
52 |

重师网络教学平台,在线学习平台!

53 | 58 |
59 |
60 |
61 |
62 |
63 | 101 |
102 |
103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /CQNU-TED/templates/index.html: -------------------------------------------------------------------------------- 1 | {#templates/index.html#} 2 | {% extends 'base.html' %} 3 | {% block title %}重庆师范大学在线学习系统软件{% endblock %} 4 | {% load staticfiles %} 5 | {% block custom_bread %} 6 | {% endblock %} 7 | 8 | {% block custom_js %} 9 | 10 | {% endblock %} 11 | {% block content %} 12 | 34 | 35 | 36 |
37 |
38 |
    39 |
  • 40 | 41 |

    学分认证

    42 |
  • 43 |
  • 44 | 45 |

    课程丰富

    46 |
  • 47 |
  • 48 | 49 |

    兴趣学习

    50 |
  • 51 |
  • 52 | 53 |

    共同进步

    54 |
  • 55 |
56 |
57 |
58 | 59 | 60 |
61 |
62 |
63 |

公开课

64 |
65 |
66 | 67 |

专业负责

68 | 查看更多课程 > 69 |
70 |
71 |
72 |
73 |
    74 | {% for banner_course in banner_courses %} 75 |
  • 76 | 77 | 78 | 79 |
  • 80 | {% endfor %} 81 |
82 |
83 | 84 | 85 |
86 | {% for course in courses %} 87 |
88 | 89 | 90 | 91 |
92 | 93 |

{{ course.name }}

94 |
95 | 难度:{{ course.get_degree_display }} 96 | 学习人数:{{ course.students }} 97 |
98 |
99 | {{ course.course_org.name }} 100 | {{ course.fav_nums }} 101 |
102 |
103 | {% endfor %} 104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |

课程学院

113 |
114 |
115 | 116 |

权威认证

117 | 查看更多学院 > 118 |
119 |
120 | 137 |
138 |
139 |
140 |
141 |
142 | {% endblock %} 143 | 144 | 145 | -------------------------------------------------------------------------------- /CQNU-TED/templates/course-detail.html: -------------------------------------------------------------------------------- 1 | {#templates/course-detail.html#} 2 | {% extends 'base.html' %} 3 | {% load staticfiles %} 4 | {% block title %}公开课列表{% endblock %} 5 | 6 | {% block custom_bread %} 7 |
8 |
9 |
10 | 15 |
16 |
17 |
18 | {% endblock %} 19 | 20 | {% block content %} 21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | 29 |
30 | 31 |
32 |
33 |

{{ course.name }}

34 | {{ course.desc }} 35 |
36 | 难度:{{ course.get_degree_display }} 37 | 学习人数:{{ course.students }} 38 |
39 |
    40 |
  • 时     长:{{ course.learn_times }}
  • 41 |
  • 章 节 数:{{ course.get_zj_nums }}
  • 42 |
  • 课程类别:{{ course.category }}
  • 43 |
  • 学习用户: 44 | {% for user_course in course.get_learn_users %} 45 | 46 | {% endfor %} 47 |
  • 48 |
49 |
50 |
51 | {% if has_fav_course %}已收藏{% else %}收藏{% endif %} 52 |
53 | 54 |
55 |
56 |
57 |
62 | 分享到: 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 |
72 |
73 |
74 |

授课学院

75 |

世界名校,课程权威

76 |
77 |
78 | 79 | 80 | 81 |
82 | 83 |

{{ course.course_org.name }}

84 |
85 |
87 | {% if has_fav_org %}已收藏{% else %}收藏{% endif %} 88 |
89 |
90 |
    91 |
  • 92 | 课  程  数:      {{ course.course_org.course_nums }} 93 |
  • 94 |
  • 95 | 教  师  数:      {{ course.course_org.get_teacher_nums }} 96 |
  • 97 |
  • 所在地区:  {{ course.course_org.address }}
  • 98 |
  • 认       证 : 99 |    100 | 101 |
  • 102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
    115 |
  • 课程详情
  • 116 |
117 |
118 |
119 | {% autoescape off %} 120 | {{ course.detail }} 121 | {% endautoescape %} 122 |
123 | 124 |
125 |
126 |
127 | 128 |
129 |
130 |
131 |
132 | 133 | 134 |
135 | 136 |
相关课程推荐
137 |
138 | {% for relate_course in relate_courses %} 139 |
140 |
141 | 142 | 143 | 144 |
145 |
146 |

{{ relate_course.name }}

147 | 学习时长:{{ relate_course.learn_times }} 148 |
149 |
150 | {% endfor %} 151 |
152 |
153 |
154 |
155 |
156 | {% endblock %} 157 | 158 | {% block custom_js %} 159 | 196 | 197 | {% endblock %} 198 | -------------------------------------------------------------------------------- /CQNU-TED/apps/course/views.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from django.shortcuts import render 3 | from django.views.generic.base import View 4 | from apps.operation.models import UserFavorite,CourseComments,UserProfile 5 | from pure_pagination import Paginator, EmptyPage, PageNotAnInteger 6 | from django.http import HttpResponse 7 | from django.db.models import Q 8 | from .models import Course,CourseResource,Video 9 | from apps.utils.mixin_utils import LoginRequiredMixin 10 | 11 | from .models import Course, CourseResource 12 | from apps.operation.models import UserFavorite, CourseComments, UserCourse 13 | from apps.utils.mixin_utils import LoginRequiredMixin 14 | from .models import Video 15 | # Create your views here. 16 | # 列表展示相关 17 | class CourseListView(View): 18 | def get(self, request): 19 | all_courses = Course.objects.all().order_by("-add_time") 20 | # 热门课程推荐 21 | hot_courses = Course.objects.all().order_by("-click_nums")[:3] 22 | 23 | # 课程搜索 24 | search_keywords = request.GET.get('keywords', "") 25 | if search_keywords: 26 | all_courses = all_courses.filter(Q(name__icontains=search_keywords)|Q(desc__icontains=search_keywords)|Q(detail__icontains=search_keywords)) 27 | 28 | # 课程排序 29 | sort = request.GET.get('sort', "") 30 | if sort: 31 | if sort == "students": 32 | all_courses = all_courses.order_by("-students") 33 | elif sort == "hot": 34 | all_courses = all_courses.order_by("-click_nums") 35 | 36 | # 对课程进行分页 37 | try: 38 | page = request.GET.get('page', 1) 39 | except PageNotAnInteger: 40 | page = 1 41 | 42 | p = Paginator(all_courses, 2, request=request) 43 | 44 | courses = p.page(page) 45 | 46 | return render(request, 'course-list.html', { 47 | "all_courses": courses, 48 | "sort": sort, 49 | "hot_courses": hot_courses 50 | }) 51 | 52 | 53 | class CourseDetailView(View): 54 | """ 55 | 课程详情页 56 | """ 57 | def get(self, request, course_id): 58 | course = Course.objects.get(id=int(course_id)) 59 | 60 | # 增加课程点击数 61 | course.click_nums += 1 62 | course.save() 63 | 64 | # 是否收藏课程,在数据库中查找 65 | has_fav_course = False 66 | # 是否收藏机构 67 | has_fav_org = False 68 | 69 | # 必须是用户登录我们才能判断 70 | if request.user.is_authenticated: 71 | if UserFavorite.objects.filter(user=request.user, fav_id=course.id, fav_type=1): 72 | has_fav_course = True 73 | 74 | if UserFavorite.objects.filter(user=request.user, fav_id=course.course_org.id, fav_type=2): 75 | has_fav_org = True 76 | # 课程标签 77 | # 通过当前标签,查找数据库中的课程 78 | tag = course.tag 79 | if tag: 80 | # 需要从1开始不然会推荐自己 81 | relate_courses = Course.objects.filter(tag=tag)[:3] 82 | else: 83 | relate_courses = [] 84 | return render(request, "course-detail.html", { 85 | "course": course, 86 | "relate_courses": relate_courses, 87 | "has_fav_course": has_fav_course, 88 | "has_fav_org": has_fav_org, 89 | }) 90 | 91 | 92 | class CourseInfoView(LoginRequiredMixin, View): 93 | """ 94 | 课程章节信息 95 | """ 96 | def get(self, request, course_id): 97 | course = Course.objects.get(id=int(course_id)) 98 | course.students += 1 99 | course.save() 100 | # 查询用户是否已经关联了该课程 101 | user_courses = UserCourse.objects.filter(user=request.user, course=course) 102 | if not user_courses: 103 | # 如果没有学习该门课程就关联起来 104 | user_course = UserCourse(user=request.user, course=course) 105 | user_course.save() 106 | # 相关课程推荐 107 | # 找到学习这门课的所有用户 108 | user_courses = UserCourse.objects.filter(course=course) 109 | user_ids = [user_course.user.id for user_course in user_courses] 110 | # 通过所有用户的id,找到所有用户学习的所有课程 111 | all_user_courses = UserCourse.objects.filter(user_id__in=user_ids) 112 | # 取出所有课程id 113 | course_ids = [all_user_course.course.id for all_user_course in all_user_courses] 114 | # 获取学过该用户学过其他的所有课程 115 | relate_courses = Course.objects.filter(id__in=course_ids).order_by("-click_nums")[:5] 116 | all_resources = CourseResource.objects.filter(course=course) 117 | return render(request, "course-video.html", { 118 | "course": course, 119 | "course_resources": all_resources, 120 | "relate_courses": relate_courses 121 | }) 122 | 123 | 124 | # 课程评论 125 | class CommentsView(LoginRequiredMixin, View): 126 | def get(self, request, course_id): 127 | course = Course.objects.get(id=int(course_id)) 128 | all_resources = CourseResource.objects.filter(course=course) 129 | all_comments = CourseComments.objects.all().order_by("-id") 130 | return render(request, "course-comment.html", { 131 | "course": course, 132 | "course_resources": all_resources, 133 | "all_comments": all_comments 134 | 135 | }) 136 | 137 | 138 | class AddCommentsView(View): 139 | """ 140 | 用户添加课程评论 141 | """ 142 | def post(self, request): 143 | # 使用request.user的形式进行确认登录状态 144 | if not request.user.is_authenticated: 145 | # 判断用户登录状态 146 | # 未登录返回json提示未登录,在Ajax中做登陆跳转 147 | return HttpResponse('{"status":"fail", "msg":"用户未登录"}', content_type='application/json') 148 | course_id = request.POST.get("course_id", 0) 149 | comments = request.POST.get("comments", "") 150 | if int(course_id) > 0 and comments: 151 | # 实例化一个course_comments对象 152 | course_comments = CourseComments() 153 | # 获取评论的是哪门课程 154 | course = Course.objects.get(id=int(course_id)) 155 | # 分别把评论的课程、评论的内容和评论的用户保存到数据库 156 | course_comments.course = course 157 | course_comments.comments = comments 158 | course_comments.user = request.user 159 | course_comments.save() 160 | return HttpResponse('{"status":"success", "msg":"评论成功"}', content_type='application/json') 161 | else: 162 | return HttpResponse('{"status":"fail", "msg":"评论失败"}', content_type='application/json') 163 | # # 参考地址:http://www.cnblogs.com/sellsa/p/8641919.html 164 | 165 | class VideoPlayView(LoginRequiredMixin, View): 166 | # 课程章节视频播放页面 167 | def get(self, request, video_id): 168 | video = Video.objects.get(id=int(video_id)) 169 | # 通过外键找到章节再找到视频对应的课程 170 | course = video.lesson.course 171 | course.students += 1 172 | course.save() 173 | # 查询用户是否已经学习了该课程 174 | user_courses = UserCourse.objects.filter(user=request.user,course=course) 175 | if not user_courses: 176 | # 如果没有学习该门课程就关联起来 177 | user_course = UserCourse(user=request.user,course=course) 178 | user_course.save() 179 | # 相关课程推荐 180 | # 找到学习这门课的所有用户 181 | user_courses = UserCourse.objects.filter(course=course) 182 | # 找到学习这门课的所有用户的id 183 | user_ids = [user_course.user_id for user_course in user_courses] 184 | # 通过所有用户的id,找到所有用户学习过的所有过程 185 | all_user_courses = UserCourse.objects.filter(user_id__in=user_ids) 186 | # 取出所有课程id 187 | course_ids = [all_user_course.course_id for all_user_course in all_user_courses] 188 | # 通过所有课程的id,找到所有的课程,按点击量前五个 189 | relate_courses = Course.objects.filter(id__in=course_ids).order_by("-click_nums")[:5] 190 | # 资源 191 | all_resources = CourseResource.objects.filter(course=course) 192 | return render(request,'course-play.html',{ 193 | 'course': course, 194 | 'all_resources': all_resources, 195 | 'relate_courses': relate_courses, 196 | 'video': video, 197 | }) 198 | -------------------------------------------------------------------------------- /CQNU-TED/templates/base.html: -------------------------------------------------------------------------------- 1 | {#templates/base.html#} 2 | 3 | {% load staticfiles %} 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | {% block title %}课程学院列表首页{% endblock %} 12 | 13 | 14 | 15 | {% block custom_css %} 16 | {% endblock %} 17 | 18 | 19 | 20 | 21 | 22 |
23 |
24 |
25 |
26 |
27 |

28 | 重庆师范大学网络教学平台

29 | 30 | {% if request.user.is_authenticated %} 31 |
32 |
33 |
{{ user.username }}
35 |
36 |
37 |
38 |
39 |
40 |
41 |

{{ request.user.nick_name }}

42 |

{{ request.user.username }}

43 |
44 |
45 |
46 | 进入个人中心 47 | 退出 48 |
49 |
50 |
51 | {% else %} 52 | 注册 53 | 登录 54 | {% endif %} 55 | 56 | 57 |
58 |
59 | 60 |
61 |
62 | 63 | 64 | 78 |
79 |
80 | 81 | 82 | 102 | 103 |
104 |
105 |
106 | 107 | 108 | {#面包屑#} 109 | {% block custom_bread %} 110 | {% endblock %} 111 | 112 | {#正文#} 113 | {% block content %} 114 | {% endblock %} 115 | 116 |
117 | 135 |
136 | 137 |
138 | 141 |
142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 174 | 175 | {% block custom_js %}{% endblock %} 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /CQNU-TED/templates/teacher-detail.html: -------------------------------------------------------------------------------- 1 | {#templates/teacher-detail.html#} 2 | 3 | {% extends 'base.html' %} 4 | {% load staticfiles %} 5 | {% block title %}教师详情{% endblock %} 6 | 7 | {% block custom_bread %} 8 |
9 |
10 | 15 |
16 |
17 | {% endblock %} 18 | 19 | 20 | {% block content %} 21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | 30 |
31 |
32 | 33 | {% if has_teacher_faved %}已收藏{% else %}收藏{% endif %} 34 | 35 | 43 |
44 |
45 |
46 | 47 |

{{ teacher.name }}金牌教师

48 |
49 |
    50 |
  • 工作年限:{{ teacher.work_years }}年
  • 51 |
  • 就职学校:{{ teacher.work_company }}
  • 52 |
  • 工作职位:{{ teacher.work_position }} 
  • 53 |
  • 教学特点:{{ teacher.points }}
  • 54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | 65 |
66 |
67 |
68 | {% for teacher_course in all_course %} 69 |
70 | 71 | 72 | 73 |
74 |

{{ teacher_course.name }}

75 | 时长:{{ teacher_course.learn_times }} 76 | 学习人数:{{ teacher_course.students }} 77 |
78 |
79 | {{ teacher_course.course_org.name }} 80 | {{ teacher_course.fav_nums }} 81 |
82 |
83 | {% endfor %} 84 | 85 | 86 | 87 |
88 |
89 | 90 | 91 | 92 | 93 | 94 |
95 |
96 |
97 | 98 | 99 |
100 |
101 |
102 |
103 |

{{ teacher.org.name }}

104 |

知名高校,权威教学

105 |
106 |
107 | 108 | 109 | 110 |
111 | 112 |

{{ teacher.org.name }}

113 |
114 |

地址:{{ teacher.org.address }}

115 | {% if has_org_faved %}已收藏{% else %}收藏{% endif %} 116 |
117 |
118 | 119 |
120 |
121 |
122 |
教师排行榜
123 | {% for hot_teacher in sorted_teacher %} 124 |
125 | 1 126 | 127 |
128 | 129 |
130 |
131 |
132 | 133 |

{{ hot_teacher.name }}

134 |
135 |

工作年限:{{ hot_teacher.work_years }}年

136 |
137 |
138 | {% endfor %} 139 |
140 |
141 |
142 |
143 |
144 |
145 | {% endblock %} 146 | 147 | 148 | {% block custom_js %} 149 | 184 | {% endblock %} 185 | 186 | 187 | 188 | 189 | -------------------------------------------------------------------------------- /CQNU-TED/templates/course-video.html: -------------------------------------------------------------------------------- 1 | {#templates/course-video.html#} 2 | {% extends 'base.html' %} 3 | {% block title %}公开课视频信息{% endblock %} 4 | {% load staticfiles %} 5 | {% block custom_bread %} 6 |
7 |
8 |
9 | 15 |
16 |
17 |
18 | {% endblock %} 19 | 20 | {% block custom_css %} 21 | 22 | 23 | 24 | 25 | 26 | 27 | {% endblock %} 28 | 29 | {% block content %} 30 |
31 |
32 |
33 |
34 |
35 |
36 |

{{ course.name }}

37 |
38 |
39 |
40 | {{ course.get_degree_display }} 41 | 难度 42 | 43 |
44 |
45 | {{ course.learn_times }}分钟 46 | 时长 47 | 48 |
49 |
50 | {{ course.students }} 51 | 学习人数 52 | 53 |
54 |
55 |
56 |
57 |
58 | 59 |
60 |
61 |
62 |
63 | 67 |
68 | 69 | 72 | 73 |
74 | {% for lesson in course.get_course_lesson %} 75 |
76 |

77 | {{ lesson.name }} 78 |

79 | 88 |
89 | {% endfor %} 90 |
91 | 92 |
93 |
94 |
95 | 96 |
97 |

资料下载

98 |
    99 | {% for course_resource in course_resources %} 100 |
  • 101 |   {{ course_resource.name }} 102 | 下载 103 |
  • 104 | {% endfor %} 105 |
106 |
107 |
108 |

教师提示

109 |
110 | 111 | 112 | 113 | 114 | {{ course.teacher.name }} 115 | 116 | {{ course.teacher.work_position }} 117 |
118 |
119 |
120 |
听课须知
121 |
{{ course.youneed_know }}
122 |
123 |
124 |
偷偷的告诉你
125 |
{{ course.teacher_tell }}
126 |
127 |
128 |
129 | 130 | 131 |
132 |
133 |

该课的同学还学过

134 |
135 |
136 |
137 | 138 | 148 |
149 |
150 | 158 |
159 |
160 |
161 | 162 |
163 |
164 |
165 | 166 |
167 | 168 |
169 |
170 | {% endblock %} 171 | 172 | -------------------------------------------------------------------------------- /CQNU-TED/templates/course-play.html: -------------------------------------------------------------------------------- 1 | {#templates/course-play.html#} 2 | {% extends 'base.html' %} 3 | 4 | {% block titile %} 5 | {{ video.name }} 重师网络教学平台 6 | {% endblock %} 7 | 8 | {% load staticfiles %} 9 | 10 | {% block custom_bread %} 11 |
12 |
13 |
14 | 20 |
21 |
22 |
23 | {% endblock %} 24 | 25 | {% block custom_css %} 26 | 27 | 28 | 29 | 30 | 31 | 32 | 38 | {% endblock %} 39 | 40 | {% block custom_js %} 41 | 42 | {% endblock %} 43 | 44 | {% block content %} 45 |
46 |
47 |
48 | 53 |
54 |
55 |
56 |
57 |
58 | 64 |
65 |
66 | 68 |
69 |
70 | {% for lesson in course.lesson_set.get_queryset %} 71 |
72 |

73 | {{ lesson.name }} 74 |

75 | 88 |
89 | {% endfor %} 90 |
91 | 92 |
93 |
94 |
95 | 96 |
97 |

资料下载

98 |
    99 | {% for course_resource in course.courseresource_set.get_queryset %} 100 |
  • 101 |   {{ course_resource.name }} 103 | 下载 105 |
  • 106 | {% endfor %} 107 |
108 |
109 |
110 |

教师提示

111 |
112 | 113 | 114 | 115 | 116 | {{ course.teacher.name }} 117 | 118 | {{ course.teacher.work_position }} 119 |
120 |
121 |
122 |
课程须知
123 |
{{ course.you_need_know }}
124 |
125 |
126 |
老师告诉你能学到什么?
127 |
{{ course.teacher_tell }}
128 |
129 |
130 |
131 | 132 | 133 |
134 |
135 |

该课的同学还学过

136 |
137 |
138 |
140 | 141 | 155 |
156 |
157 |
    158 | 159 |
160 |
161 |
162 |
163 | 164 |
165 |
166 |
167 |
168 | 169 |
170 | 171 |
172 |
173 | {% endblock %} -------------------------------------------------------------------------------- /CQNU-TED/templates/register.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | {% load staticfiles %} 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 |
32 |
33 | 34 |
35 |
36 | 没有账号?立即注册 37 |
38 |
39 |
40 |
41 |
42 | 43 |
44 |

成功提交

45 |
46 |
47 |

您的需求提交成功!

48 |

49 |
50 |
51 |
52 |

邮件验证提示

53 |
54 |
55 | 56 |

我们已经向您的邮箱12@13.com发送了邮件,
为保证您的账号安全,请及时验证邮箱

57 |

去邮箱验证

58 |

59 | 60 |

没收到,您可以查看您的垃圾邮件和被过滤邮件,
也可以再次发送验证邮件

61 |
62 |
63 |
64 | 65 |
66 |
67 |
68 |
69 |

重师网络教学平台,在线学习平台!

70 | 75 |
76 |
77 |
78 |
79 |
80 | 160 |
161 |
162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /CQNU-TED/templates/org_base.html: -------------------------------------------------------------------------------- 1 | {#templates/org_base.html#} 2 | {% load staticfiles %} 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | {% block title %}学院首页{% endblock %} 11 | 12 | 13 | 14 | 15 | {% block custom_css %}{% endblock %} 16 | 17 | 18 | 19 | 20 | 21 |
22 |
23 |
24 | 25 |
26 |
27 |

服务电话:33333333

28 | 29 | {% if request.user.is_authenticated %} 30 |
31 |
32 |
{{ user.username }}
33 |
34 |
35 |
36 |
37 |
38 |
39 |

{{ request.user.nick_name }}

40 |

{{ request.user.username }}

41 |
42 |
43 |
44 | 进入个人中心 45 | 退出 46 | {% else %} 47 | 注册 48 | 登录 49 | {% endif %} 50 |
51 |
52 |
53 |
54 |
55 | 56 | 57 |
58 |
59 | 60 |
61 |

62 | {{ course_org.name }} 63 | 64 | 65 |

66 |

67 | 推荐指数: 68 | 69 | 5.0 70 |

71 |
72 |
74 | {% if has_fav %}已收藏{% else %}收藏{% endif %} 75 |
76 | 77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
    85 |
  • 首页>
  • 86 |
  • 课程学院>
  • 87 |
  • {% block page_path %}学院首页{% endblock %}
  • 88 |
89 |
90 |
91 | 92 |
93 |
94 |
95 | 105 |
106 | 107 | {% block right_form %} 108 | {% endblock %} 109 | 110 |
111 | 112 |
113 | 119 |
120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 198 | 199 | 200 | 225 | {% block custom_js %}{% endblock %} 226 | 227 | 228 | 229 | 230 | -------------------------------------------------------------------------------- /CQNU-TED/templates/org-list.html: -------------------------------------------------------------------------------- 1 | {#templates/org-list.html#} 2 | {% extends 'base.html' %} 3 | {% load staticfiles %} 4 | {% block title %}课程学院列表{% endblock %} 5 | 6 | {% block custom_bread %} 7 |
8 |
9 |
    10 |
  • 首页>
  • 11 |
  • 课程学院
  • 12 |
13 |
14 |
15 | {% endblock %} 16 | 17 | 18 | {% block content %} 19 |
20 |
21 |
22 |
23 |
    24 |
  • 25 |

    课程来源

    26 |
    27 | 全部 29 | {# 研究生院#} 31 | {#研究生#} 32 | 老师 34 | 35 | 学生 37 |
    38 |
  • 39 |
  • 40 |

    所在地区

    41 |
    更多
    42 |
    43 | 全部 45 | {% for city in all_citys %} 46 | {{ city.name }} 48 | {% endfor %} 49 |
    50 |
  • 51 |
52 |
53 | 54 |
{{ org_nums }}
55 | 56 |
57 |
58 |
59 | 67 |
68 | 69 | {% for course_org in all_orgs.object_list %} 70 |
71 | 72 |
73 | 74 | 75 | 77 | 78 | 79 |
80 |
81 | 93 | {#
    #} 94 | {#
  • 课程数:1

    #} 95 | {#

    学习人数:1000

  • #} 96 | {#
  • 北京市海淀区中关村北大街
  • #} 97 | {#
  • 经典课程:#} 98 | {##} 99 | {# c语言基础入门#} 100 | {##} 101 | {# 数据库基础#} 102 | {##} 103 | {#
  • #} 104 | {#
#} 105 |
106 | {#

联系
服务
#} 107 |
108 | {% endfor %} 109 | 110 | 111 |
112 |
113 |
    114 | {% if all_orgs.has_previous %} 115 |
  • 上一页
  • 116 | {% endif %} 117 | 118 | {% for page in all_orgs.pages %} 119 | {% if page %} 120 | {% ifequal page all_orgs.number %} 121 |
  • {{ page }}
  • 122 | {% else %} 123 |
  • {{ page }}
  • 124 | {% endifequal %} 125 | {% else %} 126 |
  • ...
  • 127 | {% endif %} 128 | {% endfor %} 129 | {% if all_orgs.has_next %} 130 |
  • 下一页
  • 131 | {% endif %} 132 |
133 |
134 | 135 |
136 |
137 | 138 |
139 |
我要学习
140 |
141 |
142 | 143 | 144 |
145 |
146 | 147 | 148 |
149 |
150 | 151 | 152 |
153 |

154 | 155 | {% csrf_token %} 156 |
157 |
158 | 159 | 160 | 161 |
162 |
授课学院排名
163 | {% for curent_org in hot_orgs %} 164 |
165 |
{{ foorloop.counter }}
166 |
167 |

{{ curent_org.name }}

168 |

{{ curent_org.address }}

169 |
170 |
171 | {% endfor %} 172 |
173 |
174 |
175 | {% endblock %} 176 | 177 | 178 | 199 | 200 | 201 | -------------------------------------------------------------------------------- /CQNU-TED/templates/course-comment.html: -------------------------------------------------------------------------------- 1 | {#templates/course-comment.html#} 2 | {% extends 'base.html' %} 3 | {% block title %}公开课评论{% endblock %} 4 | {% load staticfiles %} 5 | {% block custom_bread %} 6 |
7 |
8 |
9 | 15 |
16 |
17 |
18 | {% endblock %} 19 | 20 | {% block custom_css %} 21 | 22 | 23 | 24 | 25 | 26 | 27 | {% endblock %} 28 | 29 | {% block content %} 30 |
31 |
32 |
33 |
34 |
35 |
36 |

{{ course.name }}

37 |
38 |
39 |
40 | {{ course.get_degree_display }} 41 | 难度 42 | 43 |
44 |
45 | {{ course.learn_times }}分钟 46 | 时长 47 | 48 |
49 |
50 | {{ course.students }} 51 | 学习人数 52 | 53 |
54 |
55 |
56 |
57 |
58 | 59 |
60 |
61 |
62 |
63 | 67 |
68 | 69 | 70 |
71 |
72 | 73 |
74 | 75 |

76 |
77 |
78 |
    79 | {% for user_comments in all_comments %} 80 |
  • 81 |
    82 | 83 |
    84 |
    85 |
    86 | {{ user_comments.user.username }} 87 |
    88 |

    {{ user_comments.comments }}

    89 | 92 |
    93 |
  • 94 | {% endfor %} 95 |
96 |
97 | 98 |
99 |
100 |
101 | 102 |
103 |

资料下载

104 |
    105 | {% for course_resource in course_resources %} 106 |
  • 107 |   {{ course_resource.name }} 108 | 下载 109 |
  • 110 | {% endfor %} 111 |
112 |
113 |
114 |

讲师提示

115 |
116 | 117 | 118 | 119 | 120 | {{ course.teacher.name }} 121 | 122 | {{ course.teacher.work_position }} 123 |
124 |
125 |
126 |
课程须知
127 |
{{ course.youneed_know }}
128 |
129 |
130 |
老师告诉你能学到什么?
131 |
{{ course.teacher_tell }}
132 |
133 |
134 |
135 | 136 | 137 |
138 |
139 |

该课的同学还学过

140 |
141 |
142 |
144 | 145 | 159 |
160 |
161 |
    162 | 163 |
164 |
165 |
166 |
167 | 168 |
169 |
170 |
171 |
172 | 173 |
174 | 175 |
176 |
177 | {% endblock %} 178 | {% block custom_js %} 179 | 212 | {% endblock %} 213 | 214 | -------------------------------------------------------------------------------- /CQNU-TED/apps/organization/views.py: -------------------------------------------------------------------------------- 1 | # _*_ encoding:utf-8 _*_ 2 | from django.shortcuts import render 3 | from django.views.generic import View 4 | from pure_pagination import Paginator, EmptyPage, PageNotAnInteger 5 | from django.http import HttpResponse 6 | from django.db.models import Q 7 | 8 | from .models import CourseOrg, CityDict, Teacher 9 | from .forms import UserAskForm 10 | from apps.operation.models import UserFavorite 11 | from apps.course.models import Course 12 | from apps.utils.mixin_utils import LoginRequiredMixin 13 | # Create your views here. 14 | 15 | 16 | # 创建一个课程学院类 17 | class OrgView(View): 18 | """ 19 | 课程学院列表功能 20 | """ 21 | def get(self, request): 22 | # 取出所有课程学院 23 | all_orgs = CourseOrg.objects.all() 24 | # 热门课程学院排名,按点击量排名,取前三 25 | hot_orgs = all_orgs.order_by("-click_nums")[:3] 26 | 27 | # 取出所有城市 28 | all_citys = CityDict.objects.all() 29 | 30 | # 学院搜索 31 | search_keywords = request.GET.get('keywords', "") 32 | if search_keywords: 33 | # 在name字段进行操作,做like语句的操作。i代表不区分大小写 34 | # or操作使用Q 35 | all_orgs = all_orgs.filter(Q(name__icontains=search_keywords) | Q(desc__icontains=search_keywords)) 36 | 37 | # 取出筛选城市 38 | city_id = request.GET.get('city', "") 39 | if city_id: 40 | all_orgs = all_orgs.filter(city_id=int(city_id)) 41 | 42 | # 类别筛选 43 | category = request.GET.get('ct', "") 44 | if category: 45 | all_orgs = all_orgs.filter(category=category) 46 | 47 | # 进行排序 48 | sort = request.GET.get('sort', "") 49 | if sort: 50 | if sort == "students": 51 | all_orgs = all_orgs.order_by("-students") 52 | elif sort == "courses": 53 | all_orgs = all_orgs.order_by("-course_nums") 54 | # 学院数量 55 | org_nums = all_orgs.count() 56 | 57 | # 对课程学院进行分页 58 | # 尝试获取前台get请求传递过来的page参数 59 | # 如果是不合法的配置参数,默认返回第一页 60 | try: 61 | page = request.GET.get('page', 1) 62 | except PageNotAnInteger: 63 | page = 1 64 | # 从all org中取出五个 65 | p = Paginator(all_orgs, 5, request=request) # 每页五个 66 | orgs = p.page(page) 67 | return render(request, "org-list.html", { 68 | "all_orgs": orgs, 69 | "all_citys": all_citys, 70 | "org_nums": org_nums, 71 | "city_id": city_id, 72 | "category": category, 73 | "hot_orgs": hot_orgs, 74 | "sort": sort, 75 | }) 76 | 77 | 78 | # 用户添加我要学习 79 | class AddUserAskView(View): 80 | """ 81 | 用户添加咨询 提交表单,post 82 | """ 83 | def post(self, request): 84 | userask_form = UserAskForm(request.POST) 85 | if userask_form.is_valid(): 86 | user_ask = userask_form.save(commit=True) 87 | # 如果保存成功,返回json字符串,后面content type是告诉浏览器返回的数据类型 88 | return HttpResponse('{"status":"success"}', content_type='application/json') 89 | else: 90 | return HttpResponse('{"status":"fail", "msg":"添加出错"}', content_type='application/json') 91 | 92 | 93 | class OrgHomeView(View): 94 | """ 95 | 学院首页 96 | """ 97 | def get(self, request, org_id): 98 | current_page = "home" 99 | # 根据id找到课程学院 100 | course_org = CourseOrg.objects.get(id=int(org_id)) 101 | # 通过课程学院找到课程。内建的变量,找到指向这个字段的外键引用 102 | course_org.click_nums += 1 103 | course_org.save() 104 | has_fav = False 105 | if request.user.is_authenticated: 106 | if UserFavorite.objects.filter(user=request.user, fav_id=course_org.id, fav_type=2): 107 | has_fav = True 108 | # 反向查询到课程学院的所有课程和老师 109 | all_courses = course_org.course_set.all()[:4] 110 | all_teachers = course_org.teacher_set.all()[:2] 111 | return render(request, 'org-detail-homepage.html', { 112 | 'all_courses': all_courses, 113 | 'all_teachers': all_teachers, 114 | 'course_org': course_org, 115 | 'current_page': current_page, 116 | 'has_fav': has_fav, 117 | }) 118 | 119 | 120 | class OrgCourseView(View): 121 | """ 122 | 学院课程列表页 123 | """ 124 | def get(self, request, org_id): 125 | current_page = "course" 126 | # 根据id找到课程学院 127 | course_org = CourseOrg.objects.get(id=int(org_id)) 128 | has_fav = False 129 | if request.user.is_authenticated: 130 | if UserFavorite.objects.filter(user=request.user, fav_id=course_org.id, fav_type=2): 131 | has_fav = True 132 | all_courses = course_org.course_set.all() 133 | return render(request, 'org-detail-course.html', { 134 | 'all_courses': all_courses, 135 | 'course_org': course_org, 136 | 'current_page': current_page, 137 | 'has_fav': has_fav 138 | }) 139 | 140 | 141 | class OrgDescView(View): 142 | """ 143 | 学院介绍页 144 | """ 145 | def get(self, request, org_id): 146 | # 向前端传值,表明现在在home页 147 | current_page = "desc" 148 | course_org = CourseOrg.objects.get(id=int(org_id)) 149 | has_fav = False 150 | if request.user.is_authenticated: 151 | if UserFavorite.objects.filter(user=request.user, fav_id=course_org.id, fav_type=2): 152 | has_fav = True 153 | return render(request, 'org-detail-desc.html', { 154 | 'course_org': course_org, 155 | 'current_page': current_page, 156 | 'has_fav': has_fav 157 | }) 158 | 159 | 160 | class OrgTeacherView(View): 161 | """ 162 | 学院教师页 163 | """ 164 | def get(self, request, org_id): 165 | current_page = "teacher" 166 | # 根据id取到课程学院 167 | course_org = CourseOrg.objects.get(id=int(org_id)) 168 | # 向前端传值说明用户是否收藏 169 | has_fav = False 170 | # 必须是用户登录我们才能判断 171 | if request.user.is_authenticated: 172 | if UserFavorite.objects.filter(user=request.user, fav_id=course_org.id, fav_type=2): 173 | has_fav = True 174 | # 通过课程学院找到课程。内建的变量,指向这个字段的外键引用 175 | all_teachers = course_org.teacher_set.all() 176 | return render(request, 'org-detail-teachers.html', { 177 | 'all_teachers': all_teachers, 178 | 'course_org': course_org, 179 | 'current_page': current_page, 180 | 'has_fav': has_fav 181 | 182 | }) 183 | 184 | 185 | class AddFavView(View): 186 | """ 187 | 用户收藏,用户取消收藏 188 | """ 189 | def post(self, request): 190 | fav_id = request.POST.get('fav_id', 0) # 防止后边的int(fav_id)时出错 191 | fav_type = request.POST.get('fav_type', 0) # 防止int(fav_id)时出错 192 | 193 | if not request.user.is_authenticated: 194 | # 判断用户登录状态 195 | # 未登录返回json提示,在Ajax中做跳转到登录页面 196 | return HttpResponse('{"status":"fail", "msg":"用户未登录"}', content_type='application/json') 197 | 198 | exist_records = UserFavorite.objects.filter(user=request.user, fav_id=int(fav_id), fav_type=int(fav_type)) 199 | if exist_records: 200 | # 如果记录已经存在, 则表示用户取消收藏 201 | exist_records.delete() 202 | if int(fav_type) == 1: 203 | course = Course.objects.get(id=int(fav_id)) 204 | course.fav_nums -= 1 205 | if course.fav_nums < 0: 206 | course.fav_nums = 0 207 | course.save() 208 | elif int(fav_type) == 2: 209 | course_org = CourseOrg.objects.get(id=int(fav_id)) 210 | course_org.fav_nums -= 1 211 | if course_org.fav_nums < 0: 212 | course_org.fav_nums = 0 213 | course_org.save() 214 | elif int(fav_type) == 3: 215 | teacher = Teacher.objects.get(id=int(fav_id)) 216 | teacher.fav_nums -= 1 217 | if teacher.fav_nums < 0: 218 | teacher.fav_nums = 0 219 | teacher.save() 220 | return HttpResponse('{"status":"success", "msg":"收藏"}', content_type='application/json') 221 | else: 222 | user_fav = UserFavorite() 223 | if int(fav_id) > 0 and int(fav_type) > 0: 224 | user_fav.user = request.user 225 | user_fav.fav_id = int(fav_id) 226 | user_fav.fav_type = int(fav_type) 227 | user_fav.save() 228 | 229 | if int(fav_type) == 1: 230 | course = Course.objects.get(id=int(fav_id)) 231 | course.fav_nums += 1 232 | course.save() 233 | elif int(fav_type) == 2: 234 | course_org = CourseOrg.objects.get(id=int(fav_id)) 235 | course_org.fav_nums += 1 236 | course_org.save() 237 | elif int(fav_type) == 3: 238 | teacher = Teacher.objects.get(id=int(fav_id)) 239 | teacher.fav_nums += 1 240 | teacher.save() 241 | 242 | return HttpResponse('{"status":"success", "msg":"已收藏"}', content_type='application/json') 243 | else: 244 | return HttpResponse('{"status":"fail", "msg":"收藏出错"}', content_type='application/json') 245 | 246 | 247 | class TeacherListView(View): 248 | """ 249 | 课程讲师列表页 250 | """ 251 | def get(self, request): 252 | all_teachers = Teacher.objects.all() 253 | # 总共有多少老师使用count进行统计 254 | teacher_nums = all_teachers.count() 255 | # 课程讲师搜索 256 | search_keywords = request.GET.get('keywords', "") 257 | if search_keywords: 258 | all_teachers = all_teachers.filter(Q(name__icontains=search_keywords)| 259 | Q(work_company__icontains=search_keywords)| 260 | Q(work_position__icontains=search_keywords)) 261 | # 人气排序 262 | sort = request.GET.get('sort', "") 263 | if sort: 264 | if sort == "hot": 265 | all_teachers = all_teachers.order_by("-click_nums") 266 | # 教师排行榜 267 | sorted_teacher = Teacher.objects.all().order_by("-click_nums")[:3] 268 | 269 | # 对讲师进行分页 270 | try: 271 | page = request.GET.get('page', 1) 272 | except PageNotAnInteger: 273 | page = 1 274 | 275 | p = Paginator(all_teachers, 1, request=request) 276 | 277 | teachers = p.page(page) 278 | return render(request, "teachers-list.html", { 279 | "all_teachers": teachers, 280 | "sorted_teacher": sorted_teacher, 281 | "sort": sort, 282 | "teacher_nums": teacher_nums, 283 | }) 284 | 285 | 286 | # 教师详情 287 | class TeacherDetailView(View): 288 | def get(self, request, teacher_id): 289 | teacher = Teacher.objects.get(id=int(teacher_id)) 290 | teacher.click_nums += 1 291 | teacher.save() 292 | all_courses = Course.objects.filter(teacher=teacher) 293 | 294 | has_teacher_faved = False 295 | if request.user.is_authenticated: 296 | if UserFavorite.objects.filter(user=request.user, fav_type=3, fav_id=teacher.id): 297 | has_teacher_faved = True 298 | 299 | has_org_faved = False 300 | if request.user.is_authenticated: 301 | if UserFavorite.objects.filter(user=request.user, fav_type=2, fav_id=teacher.org.id): 302 | has_org_faved = True 303 | 304 | # 教师排行榜 305 | sorted_teacher = Teacher.objects.all().order_by("-click_nums")[:3] 306 | return render(request, "teacher-detail.html", { 307 | "teacher": teacher, 308 | "all_courses": all_courses, 309 | "sorted_teacher": sorted_teacher, 310 | "has_teacher_faved": has_teacher_faved, 311 | "has_org_faved": has_org_faved 312 | }) --------------------------------------------------------------------------------