def edit(request): user = request.user contact = Contact.objects.by_user(user) if not contact: messages.error(request, u'请先上传个人页面') return HttpResponseRedirect(reverse('contacts_upload')) if request.method == 'GET': if request.session.get('contact_info'): contact_info = request.session.pop('contact_info') contact.fullname = contact_info.get('fullname') contact.email = contact_info.get('email') contact.phone = contact_info.get('phone') contact.qq = contact_info.get('qq') form = ContactEditForm(instance=contact) elif request.method == 'POST': form = ContactEditForm(request.POST, instance=contact) if form.is_valid(): form.save() messages.success(request, u'个人资料已更新') return HttpResponseRedirect(reverse('root')) return {'form': form}
def edit(request): user = request.user contact = Contact.objects.by_user(user) or Contact(user=user) ''' if not contact: messages.error(request, u'请先上传个人页面') return HttpResponseRedirect(reverse('contacts_upload')) ''' if request.method == 'GET': if request.session.get('contact_info'): contact_info = request.session.pop('contact_info') contact.fullname = contact_info.get('fullname') contact.email = contact_info.get('email') contact.phone = contact_info.get('phone') contact.qq = contact_info.get('qq') contact.douban_id = contact_info.get('douban_id') form = ContactEditForm(instance=contact) elif request.method == 'POST': form = ContactEditForm(request.POST, instance=contact) if form.is_valid(): form.save() messages.success(request, u'个人资料已更新') return HttpResponseRedirect(reverse('root')) return { 'form': form}
def contact_edit(request): """ Ajax post to edit contact info. """ result = {} content_type = "application/json; charset=utf-8" form = ContactEditForm(request.POST) if form.is_valid(): user_email = form.cleaned_data["user_email"] contact_email = form.cleaned_data["contact_email"] contact_name = form.cleaned_data["contact_name"] note = form.cleaned_data["note"] contact = Contact.objects.get(user_email=user_email, contact_email=contact_email) contact.contact_name = contact_name contact.note = note contact.save() result["success"] = True messages.success(request, _(u"Successfully edited %s.") % contact_email) return HttpResponse(json.dumps(result), content_type=content_type) else: return HttpResponseBadRequest(json.dumps(form.errors), content_type=content_type)
def contact_edit(request): """ Ajax post to edit contact info. """ result = {} content_type = 'application/json; charset=utf-8' form = ContactEditForm(request.POST) if form.is_valid(): user_email = form.cleaned_data['user_email'] contact_email = form.cleaned_data['contact_email'] contact_name = form.cleaned_data['contact_name'] note = form.cleaned_data['note'] contact = Contact.objects.get(user_email=user_email, contact_email=contact_email) contact.contact_name = contact_name contact.note = note contact.save() result['success'] = True messages.success(request, _(u'Editting Successfully')) return HttpResponse(json.dumps(result), content_type=content_type) else: return HttpResponseBadRequest(json.dumps(form.errors), content_type=content_type)
def contact_edit(request): """ Ajax post to edit contact info. """ result = {} content_type = 'application/json; charset=utf-8' form = ContactEditForm(request.POST) if form.is_valid(): user_email = form.cleaned_data['user_email'] contact_email = form.cleaned_data['contact_email'] contact_name = form.cleaned_data['contact_name'] note = form.cleaned_data['note'] contact = Contact.objects.get(user_email=user_email, contact_email=contact_email) contact.contact_name = contact_name contact.note = note contact.save() result['success'] = True messages.success(request, _(u'Successfully edited %s.') % contact_email) return HttpResponse(json.dumps(result), content_type=content_type) else: return HttpResponseBadRequest(json.dumps(form.errors), content_type=content_type)