Пример #1
0
def create_contact_from_values(owner=None, type=None, **values):
    created = False
    email = values.get('email')
    if not email:
        return None, False
    try:
        contact = Contact.objects.get(owner=owner, email=email)
    except Contact.DoesNotExist:
        created = True
        contact = Contact(owner=owner, **values)
        try:
            contact.user = User.objects.get(email__iexact=email) 
        except User.DoesNotExist:
            pass
        if type:
            contact.type = type 
        contact.save()
    return contact, created