コード例 #1
0
ファイル: views.py プロジェクト: Goldcap/ember_utils
def contact_row(row, type, member, colheaders):
    
    contact = Contact()
    contact_fields = []
    
    x=0
    d=[]
    dosave = False
    format = stringMatch();
    
    for col in colheaders:
        #dzink means we commit the column into the artifact object
        dzink = False
        if (col[0][:8] == "<sysval:"):
            matches = re.match( '<sysval:(.+)>', col[0])
            if matches:
                val = matches.group(1)
            else:
                val = None
            x -= 1
        elif type == 'csv':
            # a tuple of cells, e.g. (cell, cell, cell)
            #logger.log("COLUMNS: %s",[len(row)],"info")
            val = row[x]
        elif type == 'excel':
            # a tuple of cells, e.g. (cell, cell, cell)
            val = row[x].value
        
        #Format some input vals using string parsing
        if col[1] == "state":
            val = format.formatState(val)
        
        if col[1] == "zip_code":
            val = format.formatZip(val)
            
        #logger.log("COL: %s",[col[1]],"info")
        #logger.log("VALUE: %s",[val],"info")
        #if (not dzink) and (str(val).rstrip() != ""):
        if (not dzink) and (val != ""):
            #try:
            if (col[1] in ROOT_KEYS):
                setattr(contact,col[1],val)
                dosave = True
            
        x += 1
        
    contact.parent_member = member
    if dosave:
        #try:
        contact.save()
     
    #logger.log("GROUPING IS: %s",[artifact.grouping],"info")
    
    if (contact):
        status = "success"
    else:
        status = "failed"
     
    return [ status ]     
コード例 #2
0
ファイル: views.py プロジェクト: Goldcap/ember_utils
def add(request):
    meta = {'type': request.method}
    requestor = request.user.profile
    result = 'success'
    title = 'Your Contact Was Added'
    message = ''
    objects = []
    
    if request.method == 'POST':
    
        contact_id = 0
        if 'contact_id' in request.POST:
            contact_id =  request.POST["contact_id"]
            
        contact_first_name = ''
        if 'contact_first_name' in request.POST:
            contact_first_name =  request.POST["contact_first_name"]
            
        contact_last_name = ''
        if 'contact_last_name' in request.POST:
            contact_last_name =  request.POST["contact_last_name"]
        
        contact_email = ''
        if 'contact_email' in request.POST:
            contact_email =  request.POST["contact_email"]
        
        contact_organization_name = ''
        if 'contact_organization_name' in request.POST:
            contact_organization_name =  request.POST["contact_organization_name"]
        
        contact_address1 = ''
        if 'contact_address1' in request.POST:
            contact_address1 =  request.POST["contact_address1"]
        
        contact_address2 = ''
        if 'contact_address2' in request.POST:
            contact_address2 =  request.POST["contact_address2"]
        
        contact_phone = ''
        if 'contact_phone' in request.POST:
            contact_phone =  request.POST["contact_phone"]
        
        contact_city = ''
        if 'contact_city' in request.POST:
            contact_city =  request.POST["contact_city"]
        
        contact_state = ''
        if 'contact_state' in request.POST:
            contact_state =  request.POST["contact_state"]
        
        contact_zip = ''
        if 'contact_zip' in request.POST:
            contact_zip =  request.POST["contact_zip"]
        
        contact_country = ''
        if 'contact_country' in request.POST:
            contact_country =  request.POST["contact_country"]
        
        contact = None
        if contact_email != '':
            try:
                contact = Contact.objects.get(email=contact_email,parent_member=request.user.profile)
            except ObjectDoesNotExist:
                pass
        
        format = stringMatch();        
        if not contact:
            contact = Contact(
                parent_member = request.user.profile,
                first_name = contact_first_name,
                last_name = contact_last_name,
                email = contact_email,
                organization_name = contact_organization_name,
                address1 = contact_address1,
                address2 = contact_address2,
                phone = contact_phone,
                city = contact_city,
                us_state = format.formatState(contact_state),
                zip_code = format.formatZip(contact_zip),
                country_code = contact_country,
                contact_type_id = 1
                )
            contact.save()
        else:
            result = 'error'
            title = 'A contact for this user already exists.'
            message = 'The email address "' + contact_email +'" is already in your contacts.'
    
        response = {'result': result, 'title': title, 'message': message}
        return utils.jsonHttpOutput(meta, response, objects)
        #return utils.textHttpOutput(result)
    else:
        return utils.textHttpOutput("add")