def import_contacts(self): self.verbose('retrieving contact log from old mysql DB...') self.old_contacts = list(OldContact.objects.all()) self.message('retrieved %d entries from contact log' % len(self.old_contacts)) saved_contacts = [] content_type = ContentType.objects.only('id', 'model').get(app_label='nodes', model='node') for old_contact in self.old_contacts: try: user = User.objects.get(email=old_contact.from_email) except User.DoesNotExist: user = None self.message('Could not find any user with email: %s' % old_contact.from_email) contact = Inward( **{ "id": old_contact.id, "content_type": content_type, "object_id": old_contact.node_id, "status": 1, # sent, "from_name": old_contact.from_name, "from_email": old_contact.from_email, "message": old_contact.message, "ip": old_contact.ip, "user_agent": old_contact.user_agent, "accept_language": old_contact.accept_language, "added": old_contact.date, "updated": old_contact.date, }) if user: contact.user = user # if contact already exists flag it for UPDATE instead of INSERT try: Inward.objects.get(pk=old_contact.id) contact._state.adding = False except Inward.DoesNotExist: pass try: contact.full_clean(exclude=['user']) contact.save(auto_update=False) saved_contacts.append(contact) self.verbose('Saved contact log entry #%s' % contact.id) except Exception: tb = traceback.format_exc() self.message( 'Could not save contact log entry %s, got exception:\n\n%s' % (old_contact.id, tb)) self.message('saved %d entries of contact log into local DB' % len(saved_contacts)) self.saved_contacts = saved_contacts
def import_contacts(self): self.verbose('retrieving contact log from old mysql DB...') self.old_contacts = list(OldContact.objects.all()) self.message('retrieved %d entries from contact log' % len(self.old_contacts)) saved_contacts = [] content_type = ContentType.objects.only('id', 'model').get(app_label='nodes', model='node') for old_contact in self.old_contacts: contact = Inward(**{ "id": old_contact.id, "content_type": content_type, "object_id": old_contact.node_id, "status": 1, # sent "from_name": old_contact.from_name, "from_email": old_contact.from_email, "message": old_contact.message, "ip": old_contact.ip, "user_agent": old_contact.user_agent, "accept_language": old_contact.accept_language, "added": old_contact.date, "updated": old_contact.date, }) # if contact already exists flag it for UPDATE instead of INSERT try: Inward.objects.get(pk=old_contact.id) contact._state.adding = False except Inward.DoesNotExist: pass try: contact.full_clean() contact.save(auto_update=False) saved_contacts.append(contact) self.verbose('Saved contact log entry #%s' % contact.id) except Exception as e: tb = traceback.format_exc() self.message('Could not save contact log entry %s, got exception:\n\n%s' % (old_contact.id, tb)) self.message('saved %d entries of contact log into local DB' % len(saved_contacts)) self.saved_contacts = saved_contacts
def import_contacts(self): self.verbose('retrieving contact log from old mysql DB...') self.old_contacts = list(OldContact.objects.all()) self.message('retrieved %d entries from contact log' % len(self.old_contacts)) saved_contacts = [] content_type = ContentType.objects.only('id', 'model').get(app_label='nodes', model='node') for old_contact in self.old_contacts: contact = Inward(**{ "content_type": content_type, "object_id": old_contact.node_id, "status": 1, # sent "from_name": old_contact.from_name, "from_email": old_contact.from_email, "message": old_contact.message, "ip": old_contact.ip, "user_agent": old_contact.user_agent, "accept_language": old_contact.accept_language, "added": old_contact.date, "updated": old_contact.date, }) try: contact.full_clean() contact.save(auto_update=False) saved_contacts.append(contact) self.verbose('Saved contact log entry #%s' % contact.id) except Exception as e: self.message('Could not save contact log entry %s, got exception: %s' % (old_contact.id, e)) self.message('saved %d entries of contact log into local DB' % len(saved_contacts)) self.saved_contacts = saved_contacts