Exemplo n.º 1
0
    def post(self, request):
        user_ask_form = UserAskForm(request.POST)

        if user_ask_form.is_valid():
            name = user_ask_form.cleaned_data.get('name')
            mobile = user_ask_form.cleaned_data.get('mobile')
            course_name = user_ask_form.cleaned_data['course_name']
            user_ask = UserAsk.objects.filter(name=name,
                                              mobile=mobile,
                                              course=course_name)

            if user_ask:
                msg = {}
                msg['error'] = '对不起,你已经提交过相同的问题'
                return HttpResponse(json.dumps({
                    'status': 'fail',
                    'msg': msg
                }),
                                    content_type='application/json')

            user_ask = UserAsk(name=name,
                               mobile=mobile,
                               course=course_name,
                               add_time=datetime.now())
            user_ask.save()
            return HttpResponse(json.dumps({'status': 'success'}),
                                content_type='application/json')

        else:
            msg = user_ask_form.errors
            return HttpResponse(json.dumps({
                'status': 'fail',
                'msg': msg
            }),
                                content_type='application/json')
Exemplo n.º 2
0
 def post(self, request):
     userask_form = UserAskForm(request.POST)
     if userask_form.is_valid():
         user_ask = userask_form.save(commit=True)
         #   return HttpResponse("{'status':'scucess'}", content_type='application/json')
         return JsonResponse({'status': 'success'})
     else:
         return JsonResponse({'status': 'fail', 'msg': userask_form.errors})
Exemplo n.º 3
0
 def post(self, request):
     userask_form = UserAskForm(request.POST)
     if userask_form.is_valid():
         user_ask = userask_form.save(commit=True)
         ret = {'status':'success'}
     else:
         ret = {'status':'fail', 'msg':'添加出错'}
     return HttpResponse(json.dumps(ret))
Exemplo n.º 4
0
 def post(self, request):
     user_ask_form = UserAskForm(request.POST)
     if user_ask_form.is_valid():
         user_ask = user_ask_form.save(commit=True)
         return HttpResponse('{"status":"success"}',
                             content_type='application/json')
     else:
         return HttpResponse('{"status":"fail","msg":"添加出错"',
                             content_type='application/json')
Exemplo n.º 5
0
 def post(self, request):
     userask_form = UserAskForm(request.POST)
     if userask_form.is_valid():
         userask_form.save(commit=True)
         return HttpResponse(
             json.loads('{"status": "success", "message": "sucess"}'))
     else:
         return HttpResponse(
             json.loads('{"status": "fail", "message": "error"}'))
Exemplo n.º 6
0
 def post(self, request):
     useraskform = UserAskForm(request.POST)
     if useraskform.is_valid():
         # 验证合法
         # 默认是commit=true
         user_ask = useraskform.save(commit=True)
         return JsonResponse({'status': 'success'})
     else:
         msg = useraskform.errors
         return JsonResponse({'status': 'fail', 'msg': str(useraskform.errors)})
Exemplo n.º 7
0
 def post(self, request):
     userask_form = UserAskForm(request.POST)
     if userask_form.is_valid():
         user_ask = userask_form.save(commit=True)
         return HttpResponse('{"status": "success"}',
                             content_type='application/json')
     else:
         return HttpResponse("{'status': 'fail', 'msg':{0}}".format(
             userask_form.errors),
                             content_type='json')
Exemplo n.º 8
0
 def post(request):
     userask_form = UserAskForm(request.POST)
     if userask_form.is_valid():
         user_ask = userask_form.save(commit=True)
         response = {'status': 'success'}
         return HttpResponse(json.dumps(response),
                             content_type='application/json')
     else:
         response = {'status': 'fail', 'msg': '添加出错'}
         return HttpResponse(json.dumps(response),
                             content_type='application/json')
Exemplo n.º 9
0
 def post(self, request):
     useraskForm = UserAskForm(request.POST)
     if useraskForm.is_valid():
         userask = useraskForm.save(commit=True)
         # return HttpResponse('我喜欢季慧新')
         # return HttpResponse("{'msg':'我喜欢季慧新'}", content_type='application/json')
         resp = {'status': 'success', 'detail123': '我喜欢季慧新'}
         return HttpResponse(json.dumps(resp),
                             content_type="application/json")
     else:
         # return HttpResponse("{'status':'fail' , 'msg':'111'}",content_type='application/json')
         resp = {'status': 'fail', 'msg': '我喜欢季慧新'}
         return HttpResponse(json.dumps(resp),
                             content_type="application/json")
Exemplo n.º 10
0
    def get(self, request):
        ua = UserAskForm()
        all_cities = CityDict.objects.all()
        all_orgs = CourseOrg.objects.all()
        hot_orgs = all_orgs.order_by("-click_nums")[:3]

        search_keywords = request.GET.get('keywords', '')
        city_id = request.GET.get('city', '')
        category = request.GET.get('ct', "")
        sort = request.GET.get('sort', '')

        if search_keywords:
            all_orgs = all_orgs.filter(
                Q(name__icontains=search_keywords)
                | Q(address__icontains=search_keywords)
                | Q(desc__icontains=search_keywords)).distinct()
        if city_id:
            all_orgs = all_orgs.filter(city_id=city_id)
        if category:
            all_orgs = all_orgs.filter(category=category)

        org_nums = all_orgs.count()
        if sort:
            if sort == 'students':
                all_orgs = all_orgs.order_by('-students')
            elif sort == 'courses':
                all_orgs = all_orgs.order_by('-course_nums')
        try:
            page = request.GET.get('page', 1)
        except PageNotAnInteger:
            page = 1

        page_content = Paginator(all_orgs, per_page=4)
        orgs_list = page_content.page(number=page)

        context = {
            'orgs_list': orgs_list,
            'all_cities': all_cities,
            'org_nums': org_nums,
            'city': city_id,
            'ct': category,
            'hot_orgs': hot_orgs,
            'sorted': sort,
            'ua_form': ua,
            'cur_page': 'org_list',
        }

        return render(request,
                      context=context,
                      template_name=self.template_name)