예제 #1
0
 def post(self, request):
     userinfo_form = UserInfoForm(request.POST, instance=request.user)
     if userinfo_form.is_valid():
         userinfo_form.save()
         return JsonResponse({"status": 'success'})
     else:
         return JsonResponse(userinfo_form.errors)
예제 #2
0
 def post(self, request):
     user_form = UserInfoForm(request.POST, instance=request.user)
     if user_form.is_valid():
         user_form.save()
         return HttpResponseRedirect(reverse("i:info"))
     else:
         return render(request, 'user_info/my_info.html', locals())
예제 #3
0
 def post(self, request):
     user_info_form = UserInfoForm(request.POST, instance=request.user)
     if user_info_form.is_valid():
         user_info_form.save()
         return HttpResponse('{"status":"success"}', content_type='application/json')
     else:
         return HttpResponse(json.dumps(user_info_form.errors), content_type='application/json')
예제 #4
0
 def post(self, request, *args, **kwargs):
     user_info_form = UserInfoForm(request.POST, instance=request.user)
     if user_info_form.is_valid():
         user_info_form.save()
         return JsonResponse({"status": "success"})
     else:
         return JsonResponse(user_info_form.errors)
예제 #5
0
    def post(self, request):
        user_form = UserInfoForm(request.POST, instance=request.user)
        if user_form.is_valid():
            user_form.save()
            suc_dict = {'status': "success", "msg": u"邮箱修改成功"}
            return HttpResponse(json.dumps(suc_dict), content_type="application/json")

        else:
            return HttpResponse(json.dumps(user_form.errors), content_type="application/json")
예제 #6
0
 def post(self, request):
     user_info_form = UserInfoForm(request.POST, instance=request.user)
     res = dict()
     if user_info_form.is_valid():
         user_info_form.save()
         res['status'] = 'success'
     else:
         res = user_info_form.errors
     return HttpResponse(json.dumps(res), content_type='application/json')
예제 #7
0
 def post(request):
     user_info_form = UserInfoForm(request.POST, instance=request.user)
     if user_info_form.is_valid():
         user_info_form.save()
         return HttpResponse("{'status': 'success'}",
                             content_type="application/json")
     else:
         return HttpResponse(json.dumps(user_info_form.errors),
                             content_type="application/json")
예제 #8
0
 def post(self, request):
     data = request.POST
     user_form = UserInfoForm(data, instance=request.user)
     res = user_form.is_valid()
     if res:
         request.user.save()
         return redirect('users/info/')
     return render(request, 'usercenter-info.html', {'MEDIA_URL': settings.MEDIA_URL,
                                                     'status': '修改失败'})
예제 #9
0
파일: views.py 프로젝트: Kylin92/OnlineEdu
 def post(self, request):
     # 不像用户咨询是一个新的。需要指明instance。不然无法修改,而是新增用户
     user_info_form = UserInfoForm(request.POST, instance=request.user)
     if user_info_form.is_valid():
         user_info_form.save()
         return HttpResponse('{"status":"success"}',
                             content_type='application/json')
     else:
         # 通过json的dumps方法把字典转换为json字符串
         return HttpResponse(json.dumps(user_info_form.errors),
                             content_type='application/json')
예제 #10
0
파일: views.py 프로젝트: stabone/papillon
def user_edit(request):

    if request.method == 'GET':
        return redirect(reverse_lazy('user_profile'))

    if request.method == 'POST':
        print(request.POST)
        user = get_object_or_404(CustomUser, id=request.user.id)
        user_form = UserInfoForm(request.POST, instance=user)

        user_form.save()

        return redirect(reverse_lazy('user_profile'))
예제 #11
0
 def get(self, request):
     fav_tag = 'UserInfo'
     userInfo_form = UserInfoForm()
     return render(request, 'usercenter-info.html', {
         'userInfo_form': userInfo_form,
         'fav_tag': fav_tag
     })
예제 #12
0
파일: views.py 프로젝트: zh0zh/boxuegu
    def post(self, request):
        # 1、获取前端传递的表单数据
        data = request.POST
        user = request.user
        # 2、验证表单数据
        userinfo_form = UserInfoForm(data)
        res = userinfo_form.is_valid()  # 验证成功返回True,验证失败返回False

        if res:
            # 验证成功,则执行相应业务逻辑操作,这里就直接返回验证成功后的字段数据
            userinfo_data = userinfo_form.cleaned_data
            try:
                UserProfile.objects.filter(pk=user.id).update(**userinfo_data)
            except Exception as e:
                return http.JsonResponse({"status": "error"})
            else:
                return http.JsonResponse({"status": "success"})
예제 #13
0
 def post(self, request):
     # 需要知名instance,不然不知道给谁修改
     user_info_from = UserInfoForm(request.POST, instance=request.user)
     if user_info_from.is_valid():
         user_info_from.save()
예제 #14
0
파일: views.py 프로젝트: aryapriyamsn/beta
def subscription(request):
    #import ipdb; ipdb.set_trace()
    user = request.user
    bill = 0
    userr = User.objects.get(username=user)
    userr = Users.objects.get(u_name=userr)
    today = datetime.date.today()
    form_editsubscription = SubscriptionForm(request.POST or None)
    queryset = Subscription.objects.all()
    if queryset.filter(sub_user=userr).exists():
        user = Subscription.objects.get(sub_user=userr)
        form_editsubscription = SubscriptionForm(request.POST or None,
                                                 instance=user)
        user_instance = UserInfo.objects.get(user_link=userr)
        form_editinfo = UserInfoForm(request.POST or None,
                                     instance=user_instance)
        papers = user.sub_paper.all()
        start = user.start_date
        if datetime.datetime.now().time().hour > 8:
            days = (today - start).days
        else:
            days = (today - start).days - 1

        if (len(user.sub_paper.all()) >= 1):
            for item in papers:
                paper = str(item)
                paper = Newspapers.objects.get(title=paper)
                amount = paper.price
                bill += days * amount

        if UserInfo.objects.filter(user_link=userr).exists():
            userinfo = UserInfo.objects.get(user_link=userr)
            context = {
                'pic': userinfo.profile_pic,
                "name": userinfo.full_name,
                "papers": papers,
                "user": user,
                'days': days,
                'bill': bill,
                'form': form_editsubscription,
                'form_editinfo': form_editinfo,
                "start_date": user.start_date,
                "message": "You have subscribed for",
                "address": user.address,
                'nbar': 'account',
                'abar': 'subscription',
            }
        else:
            context = {
                "papers": papers,
                "user": user,
                "days": days,
                'bill': bill,
                'form': form_editsubscription,
                "start_date": user.start_date,
                "message": "You have subscribed for",
                "address": user.address,
                'nbar': 'account',
                'abar': 'subscription',
            }
    else:
        if queryset.filter(sub_user=userr).exists():
            instance = Subscription.objects.get(sub_user=user)
        else:
            instance = None
        if UserInfo.objects.filter(user_link=userr).exists():
            userinfo = UserInfo.objects.get(user_link=userr)
            form_editinfo = UserInfoForm(request.POST or None,
                                         instance=userinfo)
            context = {
                'pic': userinfo.profile_pic,
                "name": userinfo.full_name,
                'user': instance,
                'message':
                "You have not subscribed for any newspaper till now. start your subscription today!!",
                'nbar': 'account',
                'abar': 'subscription',
                'form': form_editsubscription,
            }
        else:
            context = {
                'user': instance,
                'message':
                "You have not subscribed for any newspaper till now. start your subscription today!!",
                'nbar': 'account',
                'abar': 'subscription',
                'form': form_editsubscription,
            }
    context.update(csrf(request))
    return render(request, "subscription.html", context)
예제 #15
0
파일: views.py 프로젝트: aryapriyamsn/beta
def subscription_details(request):
    #import ipdb; ipdb.set_trace()
    user = request.user
    user_link = Users.objects.get(u_name=user)
    bill = 0
    total = 0
    vendors = []
    today = datetime.date.today()
    edit_form = SubscribeForm(request.POST or None)
    if Unpaid.objects.filter(sub_user=user_link).exists():
        unpaid = Unpaid.objects.filter(sub_user=user_link).all()
    else:
        unpaid = None
    queryset = SubscribePaper.objects.all()
    users_papers = []
    if queryset.filter(sub_user=user_link).exists():
        # user=SubscribePaper.objects.get(sub_user=user_link)
        # edit_form=SubscribeForm(request.POST or None, instance=user)
        if UserInfo.objects.filter(user_link=user_link).exists():
            logged_user = UserInfo.objects.get(user_link=user_link)
            editinfo_form = UserInfoForm(request.POST or None,
                                         instance=logged_user)
        else:
            editinfo_form = UserInfoForm(request.POST or None)

        for item in queryset:
            if item.vendor not in vendors:
                vendors.append(item.vendor)
            if item.sub_user == user_link:
                users_papers.append(item)
                print(item.id)
                start = item.start_date
                if today >= start:
                    if datetime.datetime.now().time().hour > 8:
                        days = (today - start).days
                    else:
                        days = (today - start).days - 1
                    bill = 0
                    paper = str(item.sub_paper)
                    paper = Newspapers.objects.get(title=paper)
                    amount = paper.price
                    bill += days * amount
                    SubscribePaper.objects.filter(sub_paper=paper).update(
                        bill=bill, days=days)
                else:
                    bill = 0
                    days = 0
            total += bill
            bill = 0

        Users.objects.filter(u_name=user).update(total_bill=total)
        if UserInfo.objects.filter(user_link=user_link).exists():
            userinfo = UserInfo.objects.get(user_link=user_link)
            context = {
                'pic': userinfo.profile_pic,
                "name": userinfo.full_name,
                'papers': users_papers,
                'vendors': vendors,
                "user": user_link,
                'days': days,
                'unpaid': unpaid,
                'bill': total,
                'form': edit_form,
                'form_editinfo': editinfo_form,
                "message": "You have subscribed for",
                'nbar': 'account',
                'abar': 'subscription',
            }
        else:

            context = {
                'papers': users_papers,
                "user": user_link,
                "days": days,
                'bill': bill,
                'unpaid': unpaid,
                'vendors': vendors,
                'form': edit_form,
                "message": "You have subscribed for",
                'form_editinfo': editinfo_form,
                'nbar': 'account',
                'abar': 'subscription',
            }
    else:
        users_papers = None
        if UserInfo.objects.filter(user_link=user_link).exists():
            userinfo = UserInfo.objects.get(user_link=user_link)
            form_editinfo = UserInfoForm(request.POST or None,
                                         instance=userinfo)
            context = {
                'pic': userinfo.profile_pic,
                "name": userinfo.full_name,
                'user': user_link,
                'papers': users_papers,
                'unpaid': unpaid,
                'message':
                "You have not subscribed for any newspaper till now. start your subscription today!!",
                'nbar': 'account',
                'abar': 'subscription',
                'vendors': vendors,
                'form': edit_form,
                'form_editinfo': form_editinfo,
            }
        else:
            form_editinfo = UserInfoForm(request.POST or None)

            context = {
                'user': user_link,
                'papers': users_papers,
                'message':
                "You have not subscribed for any newspaper till now. start your subscription today!!",
                'nbar': 'account',
                'abar': 'subscription',
                'vendors': vendors,
                'unpaid': unpaid,
                'form': edit_form,
                'form_editinfo': form_editinfo,
            }
    return render(request, "subscription.html", context)
예제 #16
0
 def post(self, request):
     user_info_form = UserInfoForm(request.POST, instance=request.user)
     if user_info_form.is_valid():
         user_info_form.save()
         pass