def save(self):
        """
        Save the order, create or update the contact information
        (if available) and return the saved order instance
        """
        order = super(BaseCheckoutForm, self).save(commit=False)
        contact = self.shop.contact_from_user(self.request.user)

        if contact:
            order.user = contact.user
        elif self.request.user.is_authenticated():
            order.user = self.request.user

        if (self.cleaned_data.get('create_account') and not contact) or (
                not contact and self.request.user.is_authenticated()):
            password = None
            email = self.cleaned_data.get('email')

            if not self.request.user.is_authenticated():
                password = User.objects.make_random_password()
                params = {'email': email, 'password': password}
                if getattr(User, 'USERNAME_FIELD', 'username') == 'username':
                    params['username'] = email[:30]  # FIXME
                user = User.objects.create_user(**params)
                user = auth.authenticate(username=email, password=password)
                auth.login(self.request, user)
            else:
                user = self.request.user

            contact = self.shop.contact_model(user=user)
            order.user = user

            signals.contact_created.send(
                sender=self.shop,
                user=user,
                contact=contact,
                password=password,
                request=self.request)

        order.save()

        if contact:
            contact.update_from_order(order, request=self.request)
            contact.save()

        return order
dataset/ETHPy150Open matthiask/plata/plata/shop/forms.py/BaseCheckoutForm.save/original