示例#1
0
def person(request, person_key):
    contact_store = request.user_api.contact_store
    try:
        contact = contact_store.get_contact_by_key(person_key)
    except ContactError:
        raise Http404
    groups = contact_store.list_groups()
    if request.method == 'POST':
        if '_delete' in request.POST:
            contact.delete()
            messages.info(request, 'Contact deleted')
            return redirect(reverse('contacts:people'))
        else:
            form = ContactForm(request.POST, groups=groups)
            if form.is_valid():
                for k, v in form.cleaned_data.items():
                    if k == 'groups':
                        contact.groups.clear()
                        for group in v:
                            contact.add_to_group(group)
                        continue
                    setattr(contact, k, v)
                contact.save()
                messages.add_message(request, messages.INFO, 'Profile Updated')
                return redirect(
                    reverse('contacts:person',
                            kwargs={'person_key': contact.key}))
            else:
                messages.error(request, 'Please correct the problem below.')
    else:
        form = ContactForm(groups=groups,
                           initial={
                               'name': contact.name,
                               'surname': contact.surname,
                               'email_address': contact.email_address,
                               'msisdn': contact.msisdn,
                               'twitter_handle': contact.twitter_handle,
                               'facebook_id': contact.facebook_id,
                               'bbm_pin': contact.bbm_pin,
                               'gtalk_id': contact.gtalk_id,
                               'mxit_id': contact.mxit_id,
                               'wechat_id': contact.wechat_id,
                               'dob': contact.dob,
                               'groups': contact.groups.keys(),
                           })

    if contact_store.contact_has_opted_out(contact):
        messages.error(request, 'This contact has opted out.')

    return render(
        request, 'contacts/contact_detail.html', {
            'contact': contact,
            'contact_extra_items': contact.extra.items(),
            'form': form,
        })
示例#2
0
文件: views.py 项目: TouK/vumi-go
def person(request, person_key):
    contact_store = request.user_api.contact_store
    try:
        contact = contact_store.get_contact_by_key(person_key)
    except ContactError:
        raise Http404
    groups = contact_store.list_groups()
    if request.method == 'POST':
        if '_delete' in request.POST:
            contact.delete()
            messages.info(request, 'Contact deleted')
            return redirect(reverse('contacts:people'))
        else:
            form = ContactForm(request.POST, groups=groups)
            if form.is_valid():
                for k, v in form.cleaned_data.items():
                    if k == 'groups':
                        contact.groups.clear()
                        for group in v:
                            contact.add_to_group(group)
                        continue
                    setattr(contact, k, v)
                contact.save()
                messages.add_message(request, messages.INFO, 'Profile Updated')
                return redirect(reverse('contacts:person', kwargs={
                    'person_key': contact.key}))
            else:
                messages.error(request, 'Please correct the problem below.')
    else:
        form = ContactForm(groups=groups, initial={
            'name': contact.name,
            'surname': contact.surname,
            'email_address': contact.email_address,
            'msisdn': contact.msisdn,
            'twitter_handle': contact.twitter_handle,
            'facebook_id': contact.facebook_id,
            'bbm_pin': contact.bbm_pin,
            'gtalk_id': contact.gtalk_id,
            'mxit_id': contact.mxit_id,
            'wechat_id': contact.wechat_id,
            'dob': contact.dob,
            'groups': contact.groups.keys(),
        })

    if contact_store.contact_has_opted_out(contact):
        messages.error(request, 'This contact has opted out.')

    return render(request, 'contacts/contact_detail.html', {
        'contact': contact,
        'contact_extra_items': contact.extra.items(),
        'form': form,
    })
示例#3
0
def new_person(request):
    contact_store = request.user_api.contact_store
    groups = contact_store.list_groups()
    if request.POST:
        form = ContactForm(request.POST, groups=groups)
        if form.is_valid():
            contact = contact_store.new_contact(**form.cleaned_data)
            messages.add_message(request, messages.INFO, 'Contact created')
            return redirect(
                reverse('contacts:person', kwargs={'person_key': contact.key}))
        else:
            messages.add_message(request, messages.ERROR,
                                 'Please correct the problem below.')
    else:
        form = ContactForm(groups=groups)
    return render(request, 'contacts/contact_detail.html', {
        'form': form,
    })
示例#4
0
文件: views.py 项目: TouK/vumi-go
def new_person(request):
    contact_store = request.user_api.contact_store
    groups = contact_store.list_groups()
    if request.POST:
        form = ContactForm(request.POST, groups=groups)
        if form.is_valid():
            contact = contact_store.new_contact(**form.cleaned_data)
            messages.add_message(request, messages.INFO, 'Contact created')
            return redirect(reverse('contacts:person', kwargs={
                'person_key': contact.key}))
        else:
            messages.add_message(
                request, messages.ERROR,
                'Please correct the problem below.')
    else:
        form = ContactForm(groups=groups)
    return render(request, 'contacts/contact_detail.html', {
        'form': form,
    })