simple salesforce update on custom field - python

Is it possible to update an account on salesforce using an external custom field?
I've tried sf.Account.Update("Custom_Field__c:{}.format(field), data) and I cannot seem to get it to work.

I know this is really late, but in case somebody else stumbles on this:
The answer is yes, however your code is formatted incorrectly.
The update method that you're asking about is actually lower-case, it typically takes two arguments to evaluate correctly, a valid SF Id as a string, and the data you want to update with as a dictionary. So to fix what's going on in your question it would look like:
sf.Account.update("15characterIdoftheAccount", {"Custom_Field__c:{}.format(thevalueyouwanttoshowupinSF)})

Related

Python, Returning object class names by a function

I'm new to Python and this is my first question here. Hope any of you guys will be able to help me out.
I'm trying to call values inside an object from an external program. The object that I'm trying to access is given in a class (as i uderstand it), and the name of the class may change according to X, see below:
External programs object and class information
I want to be able to call information from Phase_6 in this case, however it could be Phase_12 in another case. I was considering making a function where i could have the _'Number' as an input. But I can't seem to find any information of how to do such.
I was thinking of something like using +str(X), as I do when plotting. But as it is probably not a string, it doesn't work out.
My proposed code
Ive read that bpy in Blender may be able to replace the name of the class that i want to return, however I'm not sure if it'll work, and I dont want to switch editor :)
Hope you guys can help me out,
Joachim
Found the answer, one could use getattr.
x = 6
result = getattr(g_o, 'phase_'+str(x)).Info.SumMsf.value
Thanks anyway - And I'll work on the pictures
Joachim

Omniture - python: keyError with authentication

I have been trying to use the omniture module to retrieve data from omniture but I am stuck at the very first step.
I followed the instructions on the readme but when I try to authenticate I receive the following traceback:
enter image description here
any little help will be much appreciated !
Thanks a lot,
Bastien
There's no report_suites key in the dictionary. Don't know what are you trying to find, but the best for you would be either print whole dictionary, or more efficient - print only keys and choose the one you want.
If you don't know what key do you want, printing the whole dictionary may be more useful as the values alone would be useless for you without a way to access them.
Also I think you didn't pass enough arguments to the function, because it seems that the function is missing something, therefore can't return what you need.

Python Eve: Add custom route, changing an object manually

I just started using Eve and it's really great for quickly getting a full REST API to run. However, I'm not entirely convinced that REST is perfect in all cases, e.g. I'd like to have a simple upvote route where I can increase the counter of an object. If I manually retrieve the object, increase the counter, and update it, I can easily run into problems with getting out-of-sync. So I'd like to add a simple extra-route, e.g. /resource/upvote that increases the upvote count by one and returns the object.
I don't know how "hacky" this is, so if it's over-the-top please tell me. I don't see a problem with having custom routes for some important tasks that would be too much work to do in a RESTful way. I know I could treat upvotes as its own resource, but hey I thought we're doing MongoDB, so let's not be overly relational.
So here is as far as I got:
#app.route('/api/upvote/<type>/<id>')
def upvote(type, id):
obj = app.data.find_one_raw(type, id)
obj['score'] += 1
Problem #1 find_one_raw returns None all the time. I guess I have to convert the id parameter? (I'm using the native MongoDB ObjectId)
Problem #2 How to save the object? I don't see a handy easy-to-use method like save_raw
Problem #3 Can we wrap the whole thing in a transaction or similar to make sure it's thread-safe? (I'm also new to MongoDB as you can tell).
1:
type happens to be python keyword. Do you mean to say something like resource_type ?
2: There is app.data.insert (to create new) or app.data.update (to update existing one)
3: Apparently there are no transactions in mongodb as apparent from this thread (As you can tell, I am new to mongodb myself)

Django using LIKE in an inappropriate way?

I'm trying to do the following
from core.models import *
q1 = MessageRecipient.objects.filter(message__subject__icontains="Enfim")
Producing the following WHERE clause:
WHERE `message`.`subject` LIKE %Enfim%
Look at the like statement.
Django is not using quote.
Am I missing something here? I bet I am. Cause this is a common used feature. Somebody would realize if it was a bug.
What's happening?
If you look at the __str__() method of the Query object at https://github.com/django/django/blob/master/django/db/models/sql/query.py, you'll see the following warning in the docstring:
Parameter values won't necessarily be quoted correctly, since that is
done by the database interface at execution time.
Don't worry about it, it's not important, seems to be the message! This is not a bug, as such, you just need to think about what you're using .query for. It's fine for a spot of debugging, or to pickle, if you want to recreate a query set with up to date results at a later date. It's not something you can pass directly to your database.

Is there a good language/syntax for field validation we can re-use?

I'm working on a web app (using Python & Bottle) and building a decorator for validating HTTP parameters sent in GET or POST. The early version takes callables, so this:
#params(user_id=int, user_name=unicode)
... ensures that user_id is an int, user_name is a string, and both fields exist.
But that's not enough. I want to be able to specify that user_name is optional, or that it must be non-empty and within 40 characters. Implementing that is easy enough, but I'm struggling with what syntax would be most elegant. It seems like that might be a problem someone's solved before, but I'm not finding an answer. Specifically I'm wondering if there's an elegant way to take parseable strings that provide the syntax. Something like:
#params(user_id='int:min1', user_name='unicode:required:max40')
I just don't want to invent a syntax if there's a good one floating around somewhere.
Anyone seen something like this? In any language..but I'm specifically valuing terseness and readability.
You could use lists.
#validate(user_id=[int, min(1)], user_name=[unicode,required,max(40)])
And each item could be a function (or class/object) that gets executed with the corresponding field as an argument. If it raises an error, it fails validation.

Categories