Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: c8d18d9fcc
Fetching contributors…

Cannot retrieve contributors at this time

43 lines (32 sloc) 1.152 kb
from contacts_import.models import TransientContact
class BasePersistance(object):
def persist(self, contact, status, credentials):
if status is None:
status = self.default_status()
return self.persist_contact(contact, status, credentials)
def default_status(self):
return None
def persist_contact(self, contact, status, credentials):
return None
class ModelPersistance(BasePersistance):
def default_status(self):
return {
"imported": 0,
"total": 0,
}
def persist_contact(self, contact, status, credentials):
obj, created = TransientContact.objects.get_or_create(
user = credentials["user"],
email = contact["email"],
defaults = {"name": contact["name"]}
)
status["total"] += 1
if created:
status["imported"] += 1
return status
class InMemoryPersistance(BasePersistance):
def default_status(self):
return []
def persist_contact(self, contact, status, credentials):
status.append(contact)
return status
Jump to Line
Something went wrong with that request. Please try again.