Ejemplo n.º 1
0
def course(request):  # 课程相关
    sessionManager = SessionManager(request)
    if sessionManager.isLogined():  # 如果是登陆状态,那么对应页面就应该显示登出
        status = 'LOGIN'
    else:  # 如果是未登录状态,那么对应页面就应该显示登陆或者注册
        status = 'LOGOUT'
    return render(request, 'course.html', {"status": status})
Ejemplo n.º 2
0
 def test_user_logined_visit(self):
     c = self.client
     sessionManager = SessionManager()
     sessionManager.session = self.client.session
     sessionManager.setLogin("test_admin")
     response = c.get(url_login, follow=True)
     self.assertRedirects(response, url_index)
Ejemplo n.º 3
0
def yoga(request):  # 瑜伽科普
    sessionManager = SessionManager(request)
    if sessionManager.isLogined():  #如果是登陆状态,那么对应页面就应该显示登出
        status = 'LOGIN'
    else:  #如果是未登录状态,那么对应页面就应该显示登陆或者注册
        status = 'LOGOUT'
    return render(request, 'yoga.html', {"status": status})
Ejemplo n.º 4
0
def register(request):  #用户注册
    sessionManager = SessionManager(request)
    if sessionManager.isLogined():
        return HttpResponseRedirect(url_index_logined)
    if request.method == 'POST':
        registerForm = RegisterForm(request.POST)
        if registerForm.is_valid():
            username = registerForm.cleaned_data.get('username')
            password = registerForm.cleaned_data.get('password')
            phoneNumber = registerForm.cleaned_data.get('phoneNumber')
            birthday = registerForm.cleaned_data.get('birthday')
            identity = request.POST.get('identity')

            #Customer.objects.create(username=username, password=password)
            if identity == 'customer':
                Customer.objects.create(username=username,
                                        password=password,
                                        identitySignal=1)
            elif identity == 'trainer':
                Customer.objects.create(username=username,
                                        password=password,
                                        identitySignal=2)

            personalInformation = PersonalInformation.objects.create(
                username=username)
            personalInformation.setIdentity(identity)
            personalInformation.setPhoneNumber(phoneNumber)
            personalInformation.setBirthday(birthday)
            return HttpResponseRedirect(url_login)
    else:
        registerForm = RegisterForm()
    return render(request, "RegisterUI.html", {'registerForm': registerForm})
Ejemplo n.º 5
0
def index(request):  # 首页页面
    sessionManager = SessionManager(request)
    if sessionManager.isLogined():  #如果是登陆状态,那么对应页面就应该显示登出
        status = 'LOGIN'
    else:  #如果是未登录状态,那么对应页面就应该显示登陆或者注册
        status = 'LOGOUT'
    return render(request, 'Index.html', {"status": status})  # 渲染页面
Ejemplo n.º 6
0
def reAddCourse(request, coursename):  # 执行重新上架操作
    sessionManager = SessionManager(request)
    if not sessionManager.isAdministrator():
        return HttpResponseRedirect(url_index)
    P = Course.objects.get(coursename=coursename)  # 先获取当前课程信息
    P.setCourseFlag(True)  # 重新上架课程
    return render(request, 'successfulUI.html', locals())
Ejemplo n.º 7
0
def viewCourseDetails(request, coursename):  # 显示课程的详细信息
    sessionManager = SessionManager(request)
    if sessionManager.isAdministrator():  #如果是管理员登陆
        courses = Course.objects.get(
            coursename=coursename)  # 查询当前课程信息,为了后面显示详细信息
        detailcourse = BuyRecord.objects.filter(
            coursename=coursename)  # 查询这个课程的所有订单(包括付钱和没付钱的)
        Authority = 'Admin'

    else:  #如果是客户或教练登录
        username = sessionManager.getUsername()  # 获取当前登录的用户名字
        courses = Course.objects.get(
            coursename=coursename)  # 查询当前课程信息,为了后面显示详细信息
        if sessionManager.isTrainer():  #如果是教练
            Authority = 'Trainer'

        else:
            Authority = 'Customer'
        detailcourse = BuyRecord.objects.filter(username=username,
                                                coursename=coursename)
    # 查询这个用户关于这门课的订单状态(付钱和没付钱的)
    return render(request, 'detailmessageUI.html', {
        'Authority': Authority,
        'courses': courses,
        'order1': detailcourse
    })
Ejemplo n.º 8
0
def teacherteam(request):  # 师资团队页面
    sessionManager = SessionManager(request)
    if sessionManager.isLogined():  #如果是登陆状态,那么对应页面就应该显示登出
        status = 'LOGIN'
    else:  #如果是未登录状态,那么对应页面就应该显示登陆或者注册
        status = 'LOGOUT'
    return render(request, 'teacherteam.html', {"status": status})
Ejemplo n.º 9
0
def DelCourse(request, coursename):  # 执行下架操作
    sessionManager = SessionManager(request)
    if not sessionManager.isAdministrator():
        return HttpResponseRedirect(url_index)
    P = Course.objects.get(coursename=coursename)  # 先获取当前课程信息
    P.setCourseFlag(False)  # 下架课程
    Authority = 'Admin'
    return render(request, 'successfulUI.html', locals())
Ejemplo n.º 10
0
 def test_admin_visit_index(self):
     c = self.client
     sessionManager = SessionManager()
     sessionManager.session = c.session
     sessionManager.setLogin('test_admin')
     response = c.get(url_index_admin)
     self.assertEqual(response.status_code, 200)
     self.assertTemplateUsed(response, 'AdminIndex.html')
Ejemplo n.º 11
0
 def test_customer_logout(self):
     c = self.client
     sessionManager = SessionManager()
     sessionManager.session = self.client.session
     sessionManager.setLogin('test_customer')
     response = c.get(url_logout, follow=True)
     self.assertRedirects(response, url_index)
     session = self.client.session
     self.assertEqual('Offline', session.get("LoginStatus"))
Ejemplo n.º 12
0
def customercourse(request):  # 向页面输出当前用户已支付的订单信息
    sessionManager = SessionManager(request)
    username = sessionManager.getUsername()  # 获取当前登录的用户名字
    user = BuyRecord.objects.filter(username=username,
                                    pay_flag=True,
                                    valid=True)  # 获取当前用户已经支付的课程信息
    Authority = 'Customer'
    return render(request, 'customercourseUI.html', {
        'order': user,
        'Authority': Authority
    })  # 渲染页面 按照课程名排序
Ejemplo n.º 13
0
def loginedIndex(request):  # 客户登陆过后显示的首界面
    sessionManager = SessionManager(request)
    if sessionManager.isLogouted():
        return HttpResponseRedirect(url_index)
    if sessionManager.isAdministrator():
        Authority = 'Admin'
        return render(request, 'AdminIndex.html',
                      {"Authority": Authority})  # 渲染页面,传递参数
    else:
        Authority = 'Customer'
        return render(request, 'CustomerIndex.html',
                      {"Authority": Authority})  # 渲染页面,传递参数
Ejemplo n.º 14
0
def purchaseCourse(request):
    sessionManager = SessionManager(request)
    if sessionManager.isLogouted():
        return HttpResponseRedirect(url_login)
    if sessionManager.isAdministrator():
        return HttpResponseRedirect(url_login)
    Authority = 'Customer'
    course_list = Course.objects.filter(course_flag=True)
    return render(request, 'purchaseCourse.html', {
        "Authority": Authority,
        'course_list': course_list
    })
Ejemplo n.º 15
0
def buycourse(request):
    sessionManager = SessionManager(request)
    if sessionManager.isLogouted():
        return HttpResponseRedirect(url_login)
    if not sessionManager.isAdministrator():
        return HttpResponseRedirect(url_index)
    temp = CourseForm()
    Authority = 'Admin'
    return render(request, 'buycourserightnow.html', {
        "Authority": Authority,
        'temp': temp
    })
Ejemplo n.º 16
0
def viewDetails(request, username):
    sessionManager = SessionManager(request)
    if sessionManager.isAdministrator():  # 如果是管理员登陆
        Authority = 'Admin'
    else:  # 如果是客户登陆
        Authority = 'Customer'
    if sessionManager.isLogouted():
        return HttpResponseRedirect(url_login)
    if not sessionManager.isAdministrator():
        return HttpResponseRedirect(url_index)
    userList = PersonalInformation.objects.filter(username=username)
    detailflag = 'true'
    return render(request, 'personalinformation.html', {"user_list": userList,'Authority': Authority, 'detailflag': detailflag})
Ejemplo n.º 17
0
def viewCourse(request):  # 查看课程信息
    sessionManager = SessionManager(request)
    if sessionManager.isAdministrator():  #如果是管理员登陆
        courses = Course.objects.all()  # 查询全部课程信息
        Authority = 'Admin'

    else:  #如果是客户登陆
        courses = Course.objects.filter(course_flag=True)  # 查询在使用的课程信息
        Authority = 'Customer'

    return render(request, 'coursemessageUI.html', {
        'order': courses,
        'Authority': Authority
    })
Ejemplo n.º 18
0
def UserCourseUsed(request):
    sessionManager = SessionManager(request)
    username = sessionManager.getUsername()
    if request.method == 'POST':
        coursename = request.POST.get('coursename')
        if coursename == 'all':
            user_list = CourseUsedRecord.objects.filter(username=username)
            used_times = 0
        else:
            user_list = CourseUsedRecord.objects.filter(username=username,
                                                        coursename=coursename)
            used_times = CourseUsedRecord.objects.filter(
                username=username, coursename=coursename).count()
    return render(request, 'UserCourseUsedRecord.html', locals())
Ejemplo n.º 19
0
def viewMemeberList(request):
    sessionManager = SessionManager(request)
    if sessionManager.isAdministrator():  # 如果是管理员登陆
        Authority = 'Admin'
    else:  # 如果是客户登陆
        Authority = 'Customer'
    if sessionManager.isLogouted():
        return HttpResponseRedirect(url_login)
    if not sessionManager.isAdministrator():
        return HttpResponseRedirect(url_index)
    userList = PersonalInformation.objects.all()
    detailflag = 'false'
    return render(request, 'personalinformation.html', {'user_list': userList, 'Authority': Authority,
                                                        'detailflag': detailflag })
Ejemplo n.º 20
0
def vipDetails(request, username):
    sessionManager = SessionManager(request)
    if sessionManager.isAdministrator():  # 如果是管理员登陆
        Authority = 'Admin'
    elif sessionManager.isTrainer():
        Authority = 'Trainer'
    else:  # 如果是客户登陆
        Authority = 'Customer'
    userList = PersonalInformation.objects.filter(username=username)
    detailflag = 'true'
    return render(request, 'vipInformations.html', {
        "user_list": userList,
        'Authority': Authority,
        'detailflag': detailflag
    })
Ejemplo n.º 21
0
def vipInformation(request):
    sessionManager = SessionManager(request)
    if sessionManager.isAdministrator():  # 如果是管理员登录
        Authority = 'Admin'
    else:
        if sessionManager.isTrainer():  #教练登录
            Authority = 'Trainer'
        else:  # 如果是客户登录
            Authority = 'Customer'
    userList = PersonalInformation.objects.all()
    detailflag = 'false'
    return render(request, 'vipInformations.html', {
        'user_list': userList,
        'Authority': Authority,
        'detailflag': detailflag
    })  # 渲染页面
Ejemplo n.º 22
0
def login(request):
    sessionManager = SessionManager(request)
    if request.method == 'POST':
        loginForm = LoginForm(request.POST)
        if loginForm.is_valid():
            username = loginForm.cleaned_data.get('username')
            password = loginForm.cleaned_data.get('password')
            user = Customer.objects.get(username=username)
            sessionManager.setLogin(username)
            return HttpResponseRedirect(url_index_logined)
    else:
        if sessionManager.isLogined():
            return HttpResponseRedirect(url_index)
        else:
            loginForm = LoginForm()
    return render(request, 'loginUI.html', {'loginForm': loginForm})
Ejemplo n.º 23
0
def detailrecord(request, recordid):
    sessionManager = SessionManager(request)
    if sessionManager.isLogouted():
        return HttpResponseRedirect(url_login)
    if not sessionManager.isAdministrator():
        return HttpResponseRedirect(url_index)
    Authority = 'Admin'
    localflag = 'False'
    iterable = 'False'
    record_list = BuyRecord.objects.get(number=recordid)
    return render(
        request, 'showrecord.html', {
            "Authority": Authority,
            'item': record_list,
            "localflag": localflag,
            'iterable': iterable
        })
Ejemplo n.º 24
0
def showtherecord(request):
    sessionManager = SessionManager(request)
    if sessionManager.isLogouted():
        return HttpResponseRedirect(url_login)
    if not sessionManager.isAdministrator():
        return HttpResponseRedirect(url_index)
    Authority = 'Admin'  #表示是管理员身份
    localflag = 'True'  #表示是否在主订单节面,作用实现html文件的复用,下同
    iterable = 'True'  #record_list是否可以迭代
    record_list = BuyRecord.objects.filter(valid=True)
    return render(
        request, 'showrecord.html', {
            "Authority": Authority,
            'record_list': record_list,
            'localflag': localflag,
            'iterable': iterable
        })
Ejemplo n.º 25
0
def makerecord(request, cord):
    sessionManager = SessionManager(request)
    if sessionManager.isLogouted():
        return HttpResponseRedirect(url_login)
    if not sessionManager.isAdministrator():
        return HttpResponseRedirect(url_index)
    item = BuyRecord.objects.get(number=cord)
    item.setPayFlag(True)
    Authority = 'Admin'
    localflag = 'False'
    iterable = 'False'
    return render(
        request, 'showrecord.html', {
            "Authority": Authority,
            'item': item,
            'localflag': localflag,
            'iterable': iterable
        })
Ejemplo n.º 26
0
def addCourse(request):  # 管理员增加课程信息
    sessionManager = SessionManager(request)
    if not sessionManager.isAdministrator():
        return HttpResponseRedirect(url_index)
    if request.method == 'POST':
        addcourseForm = AddCourseForm(request.POST)
        if addcourseForm.is_valid():
            coursename = addcourseForm.cleaned_data.get('coursename')
            courseintroduction = addcourseForm.cleaned_data.get(
                'courseintroduction')
            courseprice = addcourseForm.cleaned_data.get('courseprice')
            course = Course()
            course.create(coursename, courseintroduction, courseprice)
            return HttpResponseRedirect(url_course_view_course)
    else:
        addcourseForm = AddCourseForm()
        Authority = 'Admin'
        return render(request, 'addcourseUI.html', locals())
Ejemplo n.º 27
0
def ModCourse(request, coursename):  # 修改课程信息界面
    sessionManager = SessionManager(request)
    if not sessionManager.isAdministrator():
        return HttpResponseRedirect(url_index)
    if request.method == 'POST':  # 如果请求为表单提交
        modcourseForm = ModCourseForm(request.POST)  # 获取表单内容
        if modcourseForm.is_valid():  # 解析表单
            courseintroduction = modcourseForm.cleaned_data[
                'courseintroduction']
            courseprice = modcourseForm.cleaned_data['courseprice']
            R = Course.objects.get(coursename=coursename)  # 查询当前修改信息的课程对象
            R.setCourseIntroduction(courseintroduction)
            R.setCoursePrice(courseprice)
            return HttpResponseRedirect(
                url_course_view_course)  # 写成功之后,跳转到查看课程
    else:
        r = Course.objects.get(coursename=coursename)  # 查询当前课程的信息
        modcourseForm = ModCourseForm(instance=r)  # 创建表单
        return render(request, 'modcourseUI.html', locals())
Ejemplo n.º 28
0
 def test_ChangePassword_successChange(self):
     c = self.client
     sessionManager = SessionManager()
     sessionManager.session = self.client.session
     sessionManager.setLogin('test_customer')
     response = c.post(url_change_password, {
         'oldPassword': '******',
         'newPassword': '******',
         'confirmPassword': "******"
     },
                       follow=True)
     self.assertRedirects(response, url_login)
     response = c.post('/login/', {
         'username': '******',
         'password': '******'
     },
                       follow=True)
     self.assertRedirects(response, url_index_customer)
     session = self.client.session
     self.assertEqual("test_customer", session.get("Username"))
     self.assertEqual("Online", session.get("LoginStatus"))
Ejemplo n.º 29
0
 def test_ForgetPassword_success(self):
     c = self.client
     sessionManager = SessionManager()
     sessionManager.session = self.client.session
     response = c.post(url_forget_password_login,
                       {'username': '******'})
     self.assertRedirects(response, url_forget_password)
     response = c.post(url_forget_password, {
         'newPassword': '******',
         'confirmPassword': '******'
     },
                       follow=True)
     self.assertRedirects(response, url_login)
     response = c.post(url_login, {
         'username': '******',
         'password': '******'
     },
                       follow=True)
     self.assertRedirects(response, url_index_customer)
     session = self.client.session
     self.assertEqual("test_customer", session.get("Username"))
     self.assertEqual("Online", session.get("LoginStatus"))
Ejemplo n.º 30
0
def purchase(request):
    sessionManager = SessionManager(request)
    if sessionManager.isLogouted():
        return HttpResponseRedirect(url_login)
    if sessionManager.isAdministrator():
        return HttpResponseRedirect(url_index)
    if request.method == 'POST':
        username_now = sessionManager.getUsername()
        course = request.POST.get('course_name', '')
        amounttemp = request.POST.get('quantity', '')
        if course and amounttemp:
            course_temp = Course.objects.get(coursename=course)
            idtemp = BuyRecord.objects.order_by('-number')
            numbertemp = idtemp[0].getNumber() + 1
            temp = int(amounttemp)
            p = BuyRecord()
            p.number = numbertemp
            p.username = username_now
            p.price = temp * course_temp.getCoursePrice()
            p.coursename = course_temp.getCourseName()
            p.amount = temp
            p.setPayFlag(False)
            return HttpResponse("添加成功")
    return HttpResponse("添加失败")