def backgroundProcess(self,wxParent):
	'''wxParent is the object instance for the wxPython Frame instance for the app that runs this process or a suitable replacement thereof'''
	try:
	    wxParent.number = 100 # signal the elapsed read-out to begin working...
	    wxParent.count = 1 # signal the elapsed read-out to begin working...
	    wxParent.append_to_message_Q('Init SalesForce Interface.')
	    from vyperlogix.sf.sf import SalesForceQuery
	    sfQuery = SalesForceQuery(self.__login_dialog__.sf_login_model)
	    from vyperlogix.sf.assets import SalesForceAssets
	    wxParent.append_to_message_Q('Issue SOQL for List of Assets.')
	    assets = SalesForceAssets(sfQuery)
	    cassets = assets.getCurrentAssets()
	    cassets = cassets if not _utils.isBeingDebugged else cassets[0:10]
	    wxParent.number = len(cassets)
	    wxParent.count = 0
	    for rec in cassets:
		try:
		    aId = rec['AccountId']
		    wxParent.append_to_message_Q('Fetching Contact for AccountId of "%s".' % (aId))
		    contacts = assets.getAccountContacts(aId)
		    wxParent.append_to_message_Q('\tHas %d Contact%s.' % (len(contacts),'(s)' if (len(contacts) > 1) else ''))
		    wxParent.acceptContacts(rec,contacts)
		except Exception as details:
		    _details = _utils.formattedException(details=details)
		    print >>sys.stdout, _details
		    print >>sys.stderr, _details
		    break
		finally:
		    self.count += 1
	    pass
	except Exception as details:
	    _details = _utils.formattedException(details=details)
	    print >>sys.stdout, _details
	    print >>sys.stderr, _details
    def _getCompetitorsList(self):
        self.last_error = ''
        try:
            from vyperlogix.sf.sf import SalesForceQuery
            sfQuery = SalesForceQuery(self.sf_login_model)
            from vyperlogix.sf.magma.competitors import SalesForceMagmaCompetitors
            competitors = SalesForceMagmaCompetitors(sfQuery)
            c_list = competitors.getCompetitorsList()

            data = []  # tuple(['One']),tuple(['Two']),tuple(['Three'])
            if (c_list is not None):
                for item in c_list:
                    data.append(tuple([str(item['Company_Name__c']).lower()]))
        except Exception as details:
            self.last_error = _utils.formattedException(details=details)
        return data
    def _doUploadToSalesForce(self):
	from vyperlogix.sf.sf import SalesForceQuery
	sfQuery = SalesForceQuery(self.__login_dialog__.sf_login_model)
	from vyperlogix.sf.magma.customers import SalesForceCustomers
	customers = SalesForceCustomers(sfQuery)
	timestamp = sfQuery.sfdc.getServerTimestamp()
	s_timestamp = str(timestamp)
	schemas = []
	for item in self.deduped_Contacts:
	    contact_id = item['Id']
	    for asset_id in item['Asset_Ids'].split(','):
		schemas.append(customers.new_schema(asset_id,contact_id,s_timestamp))
	customers.createBatch(schemas)
	if (customers.save_result_isValid):
	    self.appendText('%s :: Sucessfully saved the batch of objects to SalesForce.' % (ObjectTypeName.objectSignature(self)))
	else:
	    print >>sys.stderr, '%s :: Un-Sucessfully saved the batch of objects to SalesForce.' % (ObjectTypeName.objectSignature(self))
	pass
 def __call__(self, *args, **kwargs):
     super(SalesForceAlchemy, self).__call__(*args, **kwargs)
     n = self.n.pop()
     a = list(args)
     a.append(kwargs)
     if (n == 'endPoint'):
         self.__endPoint__ = a
     elif (n == 'login'):
         self.__tokenize_password__()
         self.__sfLoginModel__ = SalesForceLoginModel(
             username=self.__username__, password=self.__password__)
         if (isinstance(self.__endPoint__, list)):
             self.__sfLoginModel__.api_version = self.__api_version__
             self.__endPoint__ = self.__endPoint__[0] if (
                 len(self.__endPoint__) > 0) else 'www.salesforce.com'
         if (self.__endPoint__.find('://') == -1):
             self.__endPoint__ = self.__sfLoginModel__.get_endpoint(
                 end_point=self.__endPoint__)
         self.__sfLoginModel__.perform_login(end_point=self.__endPoint__)
         if (self.isLoggedIn):
             for t in self.__sfLoginModel__.sfdc.describe_global_response[
                     'types']:
                 self.__types__[t] = t
             self.__sfQuery__ = SalesForceQuery(self.__sfLoginModel__)
     elif (n == 'username'):
         self.__username__ = a[0] if (len(a) > 0) else ''
     elif (n == 'password'):
         self.__password__ = a[0] if (len(a) > 0) else ''
     elif (n == 'token'):
         self.__token__ = a[0] if (len(a) > 0) else ''
     elif (n == 'fields'):
         self.__fieldsStack__.append(a)
     elif (n == 'filter'):
         self.__filterStack__.append(a)
     elif (n == 'order_by'):
         self.__orderByStack__.append(a)
     elif (n == 'all') or (n == 'count'):
         try:
             object_name = self.__objectStack__.pop()
         except IndexError:
             raise SalesForceObjectException(
                 "Required Object Name was not present.  Object Name must appear like this (sf.case.fields('*').filter(Id='value-of-Id').order_by('Name').all()) with each Object Name being present in the target SalesForce Org."
             )
         self.object_name = object_name
         fields = []
         names = self.description.fieldnames
         try:
             while (len(self.__fieldsStack__) > 0):
                 field = self.__fieldsStack__.pop()[0]
                 if (field == '*'):
                     fields = names
                     break
                 elif (field in names):
                     fields.append(field)
                 else:
                     raise SalesForceFieldException(
                         'Field with name of "%s" is not present in the SalesForce object named "%s".'
                         % (field, self.object_name))
         except Exception, _details:
             info_string = _utils.formattedException(details=_details)
             raise SalesForceParmException(
                 'Cannot process the field specifications for object named "%s".\n%s'
                 % (self.object_name, info_string))
         self.namesCanonicalized(fields)
         soql, soql_count = self.__make_soql__()
         results_count = self.sf_query(soql_count)
         if (n == 'count'):
             if (kwargs.has_key('debug')) and (kwargs['debug']):
                 return soql, soql_count, results_count[0]
             else:
                 return results_count[0]
         else:
             if (int(results_count[0]['size'][0]) > 1):
                 pass
             elif (kwargs.has_key('debug')) and (kwargs['debug']):
                 return soql, soql_count, results_count[0]
             else:
                 return self.sf_query(soql)
Esempio n. 5
0
    _use_staging = False

    __sf_account__ = credentials(magma_molten_passphrase,0 if (not _use_staging) else 1)

    from vyperlogix.wx.pyax.SalesForceLoginModel import SalesForceLoginModel
    sf_login_model = SalesForceLoginModel(username=__sf_account__['username'],password=__sf_account__['password'])

    sf_login_model.isStaging = _use_staging
    sf_login_model.perform_login_appropriately()

    if (sf_login_model.isLoggedIn):
        print 'Logged-in Successfully.'

        from vyperlogix.sf.sf import SalesForceQuery
        sfQuery = SalesForceQuery(sf_login_model)

        sf_accounts = SalesForceAccounts(sfQuery)
        accounts = sf_accounts.getAccountsLikeName('Toshiba')
        if (isinstance(accounts,list)):
            for account in accounts:
                tree = sf_accounts._getAccountTree(account)
                print 'BEGIN: (%s) %s (%s)' % (account['Id'],account['Name'],account['ParentId'])
                tree.dump()
                print 'END!'
                print '-'*40
                n = tree.findForwards(Id=account['Id'])
                if (n is not None):
                    n.dump()
                else:
                    print '()'
Esempio n. 6
0
    def __call__(self,*args,**kwargs):
        super(SalesForceAlchemy, self).__call__(*args,**kwargs)
        n = self.n.pop()
        a = list(args)
        a.append(kwargs)
        if (n == 'endPoint'):
            self.__endPoint__ = a
        elif (n == 'login'):
            self.__tokenize_password__()
            self.__sfLoginModel__ = SalesForceLoginModel(username=self.__username__,password=self.__password__)
            if (isinstance(self.__endPoint__,list)):
                self.__sfLoginModel__.api_version = self.__api_version__
                self.__endPoint__ = self.__endPoint__[0] if (len(self.__endPoint__) > 0) else 'www.salesforce.com'
            if (self.__endPoint__.find('://') == -1):
                self.__endPoint__ = self.__sfLoginModel__.get_endpoint(end_point=self.__endPoint__)
            self.__sfLoginModel__.perform_login(end_point=self.__endPoint__)
            if (self.isLoggedIn):
                for t in self.__sfLoginModel__.sfdc.describe_global_response['types']:
                    self.__types__[t] = t
		#self.__sfQuery__ = SalesForceQuery(self.__sfLoginModel__)
		SalesForceAbstract.__init__(self, SalesForceQuery(self.__sfLoginModel__))
        elif (n == 'username'):
            self.__username__ = a[0] if (len(a) > 0) else ''
        elif (n == 'password'):
            self.__password__ = a[0] if (len(a) > 0) else ''
        elif (n == 'token'):
            self.__token__ = a[0] if (len(a) > 0) else ''
        elif (n == 'fields'):
            self.__fieldsStack__.append(a)
        elif (n == 'filter'):
            self.__filterStack__.append(a)
        elif (n == 'order_by'):
            self.__orderByStack__.append(a)
        elif (n == 'all') or (n == 'count'):
            try:
                object_name = self.__objectStack__.pop()
            except IndexError:
                raise SalesForceObjectException("Required Object Name was not present.  Object Name must appear like this (sf.case.fields('*').filter(Id='value-of-Id').order_by('Name').all()) with each Object Name being present in the target SalesForce Org.")
	    fieldsStack_copy = misc.copy(self.__fieldsStack__)
	    filterStack_copy = misc.copy(self.__filterStack__)
	    orderByStack_copy = misc.copy(self.__orderByStack__)
            self.object_name = object_name
	    self.canonicalizeNames(self.__fieldsStack__)
            soql,soql_count = self.__make_soql__()
            results_count = self.sf_query(soql_count)
	    if (n == 'count'):
		if (kwargs.has_key('debug')) and (kwargs['debug']):
		    return soql,soql_count,results_count[0]
		else:
		    return results_count[0]
	    else:
		_callback = None
		if (kwargs.has_key('callback')) and (callable(kwargs['callback'])):
		    _callback = kwargs['callback']
		if (int(results_count[0].size[0]) > 1):
		    f = self.fields_by_(name='idlookup',value='true')
		    if (f is not None):
			l = [_f for _f in f if (_f.has_key('name')) and (_f['name'].find('Id') > -1)]
			if (len(l) == 0):
			    l = random.choice(f)
			l = l[0] if (isinstance(l,list)) and (len(l) > 0) else l
			self.__filterStack__ = filterStack_copy
			self.__orderByStack__ = orderByStack_copy
			self.namesCanonicalized([l['name']])
			soql,soql_count = self.__make_soql__()
			records = self.sf_query(soql)
			for rec in records:
			    self.__fieldsStack__ = fieldsStack_copy
			    self.__filterStack__ = filterStack_copy
			    self.__orderByStack__ = orderByStack_copy
			    self.canonicalizeNames(self.__fieldsStack__)
			    pass
			pass
		    pass
		elif (kwargs.has_key('debug')) and (kwargs['debug']):
		    return soql,soql_count,results_count[0]
		else:
		    records = self.sf_query(soql)
		    if (callable(_callback)):
			for rec in records:
			    _callback(rec)
		    return records
        self.__reset_magic__()
        return self