def from_request(self, request, create=False):
        """Get the contact from the session, else look up using the logged-in
        user. Create an unsaved new contact if `create` is true.

        Returns:
        - Contact object or None
        """

        contact = None
        if request.user.is_authenticated():
            try:
                contact = Contact.objects.get(user=request.user.id)
                request.session[CUSTOMER_ID] = contact.id
            except Contact.DoesNotExist:
                pass
        else:
            # Don't create a Contact if the user isn't authenticated.
            create = False
            
        if request.session.get(CUSTOMER_ID):
            try:
                contactBySession = Contact.objects.get(id=request.session[CUSTOMER_ID])
                if contact is None:
                    contact = contactBySession
                elif contact != contactBySession:
                    # For some reason the authenticated id and the session customer ID don't match.
                    # Let's bias the authenticated ID and kill this customer ID:
                    log.debug("CURIOUS: The user authenticated as %r (contact id:%r) and a session as %r (contact id:%r)" %
                               (contact.user.get_full_name(), contact.id, Contact.objects.get(id=request.session[CUSTOMER_ID]).full_name, request.session[CUSTOMER_ID]))
                    log.debug("Deleting the session contact.")
                    del request.session[CUSTOMER_ID]
            except Contact.DoesNotExist:
                log.debug("This user has a session stored customer id (%r) which doesn't exist anymore. Removing it from the session." % request.session[CUSTOMER_ID])
                del request.session[CUSTOMER_ID]

        if contact is None:
            if create:
                contact = Contact(user=request.user)

            else:
                raise Contact.DoesNotExist()

        return contact
dataset/ETHPy150Open dokterbob/satchmo/satchmo/apps/satchmo_store/contact/models.py/ContactManager.from_request/original