def import_chats(self): for c in self.data['chats']: print '>> Chat(%s)' % str(c) new_chat = Chat(created_at=c['started_at'], subject=c['subject']) new_chat.save() self.chat_ids[c['id']] = new_chat.id if not c['staff_name'] is None: try: staff_user = User.objects.filter(username__exact=c['staff_name'])[0] except: print "Couldnt find associated User with username: %s" % c['staff_name'] staff_user = None staff = Participant(conversation=new_chat, name=c['staff_name'], user=staff_user, role=Participant.ROLE_STAFF, ip_hash=c['staff_ip']) staff.save() if not c['client_name'] is None: client = Participant(conversation=new_chat, name=c['client_name'], user=None, role=Participant.ROLE_CLIENT, ip_hash=c['client_ip'], blocked=c['client_blocked'], blocked_at=c['client_blocked_at']) client.save(keep_blocked_at=True) for msg in c['messages']: self.print_indent('>> Message(%s)' % str(msg)) if msg['who'] == 'CLIENT': sender = client else: sender = staff new_chat.create_message(sender=sender, sender_name=sender.name, created_at=msg['created_at'], body=msg['body'], event=msg['event'])