Beispiel #1
0
def import_from_stream(source,list):
    tmp_file = settings.MEDIA_ROOT + '/csv.csv'
    default_storage.save(tmp_file ,source)
    try:
        file=open(tmp_file,'rb') 
        testReader=csv.reader(file,delimiter=';',quotechar='"')
        inserted = 0
        for row in testReader:
            if len(row) < 2:
                continue
            email = row[0].strip() 
            if not email_is_valid(email):
                continue
            created = False
            try:
                contact = Contact.objects.get(email=email)
                created = True
            except:
                contact = Contact() 
            contact.email = email
            contact.first_name = row[1].decode('ISO-8859-1')
            contact.last_name = row[2].decode('ISO-8859-1')    
            contact.save()    
            if  list:
                list.subscribers.add(contact)               
            inserted += int(created)   
        return inserted
    finally:
        file.close()
        os.remove(tmp_file)
 def handle_noargs(self, **options):
     for c in User.objects.all():
         try: 
             contact = Contact.objects.get(email=c.email)
         except:        
             contact = Contact()
             contact.email= c.email
             contact.first_name = c.first_name
             contact.last_name = c.last_name
         contact.content_object = c
         contact.save()    
Beispiel #3
0
def vcard_contact_import(vcard,list):      
    if not email_is_valid(vcard.email.value):
        return 0    
    created = False
    try:
        contact = Contact.objects.get(email=vcard.email.value)
        created = True
    except:
        contact = Contact()
    contact.email = vcard.email.value 
    contact.first_name = vcard.n.value.given    
    contact.last_name = vcard.n.value.family             
    contact.save()
    
    if list:
        list.subscribers.add(contact)         
    return int(created)