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)
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')
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')
def post(self, request, *args, **kwargs): user_info_form = UserInfoForm(request.POST, instance=request.user) if user_info_form.is_valid(): address = user_info_form.cleaned_data['address'] if not Web3.isChecksumAddress(address): return JsonResponse({"status": 'fail', "msg": "地址格式不对!"}) user_info_form.save() return JsonResponse({ "status": "success", }) else: return JsonResponse(user_info_form.errors)
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() message = UserMessage() message.user = request.user message.messgae = "用户信息修改成功!" message.has_read = False message.save() return JsonResponse({ "status": "success", }) else: return JsonResponse(user_info_form.errors)
def Profile(request,username): if request.method == 'GET': config = ConfigPlatform.objects.get(id=1) type_events = TypeEventModel.objects.all() if (request.user == User.objects.filter(username=username).first()): username = username else: username = request.user.username user = User.objects.filter(username=username).first() eventslist = EventModel.objects.filter(user=user) userinfo = UserInfoModel.objects.filter(user=user).first() if (UserInfoModel.objects.filter(user=user).exists()): form = UserInfoForm(instance=userinfo) else: form = UserInfoForm() events = [] for event in eventslist: image = ImagesEvent.objects.filter(event=event).first() ticket = TicketModel.objects.filter(event=event).order_by('price').first() events.append({ 'event':event, 'image':image, 'ticket' : ticket, }) group_sheller = [] shellers = ShellerModel.objects.filter(user=request.user) for sheller in shellers: group = ShellersGroupModel.objects.get(id=sheller.group.id) group_sheller.append({ 'group' : group, 'sheller' : sheller, }) users = User.objects.all() methods = PaymentMethod.objects.all() context = { 'user':user, 'data_events':events, 'userinfo':userinfo, 'form':form, 'config':config, 'type_events':type_events, 'group_sheller':group_sheller, 'users' : users, 'methods' : methods, } return render(request,'user/profile_home.html',context) elif request.method == 'POST': userinfo = UserInfoModel.objects.filter(user__username=username).first() if(UserInfoModel.objects.filter(user__username=username).exists()): form = UserInfoForm(request.POST, instance=userinfo) if form.is_valid(): userinfo2 = form.save(commit=False) userinfo2.user = User.objects.filter(username=username).first() form.save() else: form = UserInfoForm(request.POST,request.FILES) if form.is_valid(): userinfo = form.save(commit=False) userinfo.user = User.objects.filter(username=username).first() form.save() return redirect('profile:home',username)