Esempio n. 1
0
def teacher_score(request):
    context = {}
    userid = auth.get_userid(request)
    context['username'] = Teacher.get_by_id(userid).name
    keyword = request.GET.get('keyword', '').strip()
    if request.method == 'POST':
        action = request.POST.get('action')
        if action == 'edit':
            course_id = request.POST.get('courseId')
            student_id = request.POST.get('studentId')
            score = request.POST.get('courseScore')
            item = Selection.objects.get(
                course_id=course_id,
                student_id=student_id,
            )
            item.score = score
            item.save()
            context['message'] = '修改成功!'
    course_list = Selection.objects.filter(
        course_id__in=Course.objects.filter(teacher_id=userid),
    )
    if len(keyword) != 0:
        course_list = course_list.filter(
            Q(course__id__contains=keyword) | Q(course__name__contains=keyword) | Q(student__id__contains=keyword) | Q(
                student__name__contains=keyword)
        )
    context['course_list'] = course_list
    return render(request, 'teacher/score.html', context)
Esempio n. 2
0
def select(request):
    userid = auth.get_userid(request)
    username = Student.get_by_id(userid).name
    context = {
        'username': username,
    }
    if request.method == 'POST':
        action = request.POST.get('action')
        if action == 'select':
            course_id = request.POST.get('courseId')
            try:
                Selection.objects.create(
                    course_id=course_id,
                    student_id=userid,
                )
            except Exception as e:
                context['message'] = '选课失败!' + e.__str__()
            else:
                context['message'] = '选课成功!' + Course.get_by_id(course_id).name
    keyword = request.GET.get('keyword', '').strip()
    course_list = Course.objects.exclude(id__in=Selection.objects.filter(
        student_id=userid).values('course_id'), )
    if len(keyword) > 0:
        course_list = course_list.filter(
            Q(id__contains=keyword) | Q(name__contains=keyword)
            | Q(teacher__name__contains=keyword))
    context['course_list'] = course_list
    return render(request, 'student/select.html', context)
Esempio n. 3
0
def teacher_course(request):
    context = {}
    userid = auth.get_userid(request)
    context['username'] = Teacher.get_by_id(userid).name
    keyword = request.GET.get('keyword', '').strip()
    if request.method == 'POST':
        action = request.POST.get('action')
        if action == 'edit':
            course_id = request.POST.get('courseId')
            description = request.POST.get('courseDescription')
            course = Course.get_by_id(course_id)
            course.description = description
            course.save()
            context['message'] = '修改成功!'
    course_list = Course.objects.filter(
        teacher_id=userid,
    )
    if len(keyword) != 0:
        course_list = course_list.filter(
            Q(id__contains=keyword) | Q(name__contains=keyword)
        )
    for item in course_list:
        count = Selection.objects.filter(
            course_id=item.id,
        ).count()
        item.student_count = count
    context['course_list'] = course_list
    return render(request, 'teacher/course.html', context)
Esempio n. 4
0
def index(request):
    userid = auth.get_userid(request)
    username = Admin.get_by_id(userid).name
    context = {
        'teacher_count': Teacher.objects.count(),
        'course_count': Course.objects.count(),
        'student_count': Student.objects.count(),
        'username': username,
    }
    return render(request, 'admin/index.html', context)
Esempio n. 5
0
def index(request):
    userid = auth.get_userid(request)
    username = Student.get_by_id(userid).name
    context = {
        'username': username,
    }
    list_count = Selection.objects.filter(student_id=userid, ).count()
    course_count = Course.objects.exclude(
        selection__student__id=userid, ).count()
    context['list_count'] = list_count
    context['course_count'] = course_count
    return render(request, 'student/index.html', context)
Esempio n. 6
0
def settings(request):
    userid = auth.get_userid(request)
    username = Admin.get_by_id(userid).name
    context = {
        'username': username,
    }
    if request.method == 'POST':
        # POST data
        password = request.POST.get('password')
        new_password1 = request.POST.get('newPassword1')
        new_password2 = request.POST.get('newPassword2')
        userid = auth.get_userid(request)
        if new_password1 != new_password2:
            context['message'] = "两次密码不一致!"
        else:
            user = Admin.get_by_id(userid)
            if user is None or auth.make_token(password) != user.token:
                context['message'] = "当前密码错误!"
            else:
                user.token = auth.make_token(new_password1)
                user.save()
                context['message'] = "修改成功!"
    return render(request, 'admin/settings.html', context)
Esempio n. 7
0
def admin_teacher(request):
    if not auth.is_admin(request):
        return redirect('auth_index')
    userid = auth.get_userid(request)
    username = Admin.get_by_id(userid).name
    context = {
        'username': username,
    }
    keyword = request.GET.get('keyword', '').strip()
    order_by = request.GET.get('orderBy', '').strip()
    if request.method == 'POST':
        action = request.POST.get('action')
        if action == 'add':
            _id = request.POST.get('teacherId')
            _name = request.POST.get('teacherName')
            try:
                Teacher.objects.create(
                    id=_id,
                    name=_name,
                    token=auth.make_token(_id),
                )
                context['message'] = '添加成功!'
            except Exception as e:
                context['message'] = '添加失败!' + e.__str__()
        elif action == 'delete':
            _id = request.POST.get('teacherId')
            if _id:
                teacher = Teacher.get_by_id(_id)
                if teacher:
                    teacher.delete()
                context['message'] = '已删除!'
        elif action == 'edit':
            _id = request.POST.get('teacherId')
            _name = request.POST.get('teacherName')
            _password = request.POST.get('teacherPassword')
            teacher = Teacher.get_by_id(_id)
            teacher.name = _name
            if _password and len(_password) > 0:
                teacher.token = auth.make_token(_password)
            teacher.save()
            context['message'] = '已修改!'
    if len(keyword) == 0:
        teacher_list = Teacher.objects.all()
    else:
        teacher_list = Teacher.objects.filter(
            Q(id__contains=keyword) | Q(name__contains=keyword))
    if order_by in ('id', 'name'):
        teacher_list = teacher_list.order_by(order_by)
    context['teacher_list'] = teacher_list
    return render(request, 'admin/teacher.html', context)
Esempio n. 8
0
def admin_student(request):
    userid = auth.get_userid(request)
    username = Admin.get_by_id(userid).name
    context = {
        'username': username,
    }
    keyword = request.GET.get('keyword', '').strip()
    order_by = request.GET.get('orderBy', '').strip()
    if request.method == 'POST':
        action = request.POST.get('action')
        if action == 'add':
            _id = request.POST.get('studentId')
            _name = request.POST.get('studentName')
            try:
                Student.objects.create(
                    id=_id,
                    name=_name,
                    token=auth.make_token(_id),
                )
                context['message'] = '添加成功!'
            except Exception as e:
                context['message'] = '添加失败!' + e.__str__()
        elif action == 'delete':
            _id = request.POST.get('studentId')
            if _id:
                student = Student.get_by_id(_id)
                if student:
                    student.delete()
                context['message'] = '已删除!'
        elif action == 'edit':
            _id = request.POST.get('studentId')
            _name = request.POST.get('studentName')
            _password = request.POST.get('studentPassword')
            student = Student.get_by_id(_id)
            student.name = _name
            if _password and len(_password) > 0:
                student.token = auth.make_token(_password)
            student.save()
            context['message'] = '已修改!'
    if len(keyword) == 0:
        student_list = Student.objects.all()
    else:
        student_list = Student.objects.filter(
            Q(id__contains=keyword) | Q(name__contains=keyword))
    if order_by in ('id', 'name'):
        student_list = student_list.order_by(order_by)
    context['student_list'] = student_list
    return render(request, 'admin/student.html', context)
Esempio n. 9
0
def index(request):
    context = {}
    userid = auth.get_userid(request)
    context['username'] = Teacher.get_by_id(userid).name
    course_list = Course.objects.filter(
        teacher_id=userid,
    )
    course_count = course_list.count()
    score_count = 0
    for item in course_list:
        selections = Selection.objects.filter(
            course_id=item.id,
        )
        for s in selections:
            if s.score is None:
                score_count += 1
    context['course_count'] = course_count
    context['score_count'] = score_count
    return render(request, 'teacher/index.html', context)
Esempio n. 10
0
def settings(request):
    userid = auth.get_userid(request)
    user = Student.get_by_id(userid)
    context = {
        'username': user.name,
    }
    if request.method == 'POST':
        password = request.POST.get('password')
        new_password1 = request.POST.get('newPassword1')
        new_password2 = request.POST.get('newPassword2')
        if new_password1 != new_password2:
            context['message'] = "两次密码不一致!"
        else:
            if auth.make_token(password) != user.token:
                context['message'] = "当前密码错误!"
            else:
                user.token = auth.make_token(new_password1)
                user.save()
                context['message'] = "修改成功!"
    return render(request, 'student/settings.html', context)
Esempio n. 11
0
def list_course(request):
    userid = auth.get_userid(request)
    username = Student.get_by_id(userid).name
    context = {
        'username': username,
    }
    keyword = request.GET.get('keyword', '').strip()
    if request.method == 'POST':
        action = request.POST.get('action')
        if action == 'withdraw':
            course_id = request.POST.get('courseId')
            try:
                selection = Selection.objects.get(
                    student_id=userid,
                    course_id=course_id,
                )
            except Selection.DoesNotExist as e:
                context['message'] = '操作失败!' + e.__str__()
            else:
                selection.delete()
                context['message'] = '已退选!' + Course.get_by_id(course_id).name
        elif action == 'comment':
            course_id = request.POST.get('courseId')
            comment = request.POST.get('courseComment')
            selection = Selection.objects.get(
                student_id=userid,
                course_id=course_id,
            )
            selection.comment = comment
            selection.save()
            context['message'] = '评价已更新!'
    course_list = Selection.objects.filter(student_id=userid, )
    if len(keyword) > 0:
        course_list = course_list.filter(
            Q(course__id__contains=keyword) | Q(course__name__contains=keyword)
            | Q(course__teacher__name__contains=keyword))
    context['course_list'] = course_list
    return render(request, 'student/list.html', context)
Esempio n. 12
0
def admin_course(request):
    userid = auth.get_userid(request)
    username = Admin.get_by_id(userid).name
    context = {
        'username': username,
    }
    keyword = request.GET.get('keyword', '').strip()
    order_by = request.GET.get('orderBy', '').strip()
    if request.method == 'POST':
        action = request.POST.get('action')
        if action == 'add':
            course_id = request.POST.get('courseId')
            course_name = request.POST.get('courseName')
            teacher_id = request.POST.get('courseTeacher')
            description = request.POST.get('courseDescription')
            if len(description) == 0:
                description = None
            if len(teacher_id) == 0:
                teacher = None
            else:
                teacher = Teacher.get_by_id(teacher_id)
            try:
                Course.objects.create(
                    id=course_id,
                    name=course_name,
                    teacher=teacher,
                    description=description,
                )
                context['message'] = '添加成功!'
            except Exception as e:
                context['message'] = '添加失败!' + e.__str__()
        elif action == 'delete':
            course_id = request.POST.get('courseId')
            if course_id:
                course = Course.get_by_id(course_id)
                if course:
                    course.delete()
                context['message'] = '已删除!'
        elif action == 'edit':
            course_id = request.POST.get('courseId')
            course_name = request.POST.get('courseName')
            teacher_id = request.POST.get('courseTeacher')
            description = request.POST.get('courseDescription')
            if len(teacher_id) == 0:
                teacher = None
            else:
                teacher = Teacher.get_by_id(teacher_id)
            if len(description) == 0:
                description = None
            course = Course.get_by_id(course_id)
            if course:
                course.name = course_name
                course.teacher = teacher
                course.description = description
                course.save()
            context['message'] = '已修改!'

    if len(keyword) == 0:
        course_list = Course.objects.all()
    else:
        course_list = Course.objects.filter(
            Q(id__contains=keyword) | Q(name__contains=keyword)
            | Q(teacher__name__contains=keyword))
    if order_by in ('id', 'name'):
        course_list = course_list.order_by(order_by)
    context['course_list'] = course_list
    context['teacher_list'] = Teacher.objects.all()
    return render(request, 'admin/course.html', context)