Note that there are some explanatory texts on larger screens.

plurals
  1. POError: list indices must be integers, not str
    primarykey
    data
    text
    <p>I have a form which gets pre-populated by an Object. Framework: Pyramid, IDE: PyCharm</p> <p>On the page I have extra fields for users to add additional phone numbers and emails. For example individual phone objects {tag:work, value:555} would get pushed into the phones[] array inside of the person object. Then I need to send that new info back to the server.</p> <p>jQuery</p> <pre><code>// Person var person = { username : profileData.username, firstName : "", lastName : "", phones : [], emails : [], organization : "", title : "" } // Original Profile person.firstName = $('#profile-firstname').val(); person.lastName = $('#profile-lastname').val(); person.organization = $('#profile-company').val(); person.title = $('#profile-title').val(); // Added Profile var phoneObjs = {}; var emailObjs = {}; var extraPhones = []; var extraEmails = []; var addedPhones = $('.added_phone'); var addedEmails = $('.added_email'); addedPhones.each( function(i) { //console.log(i); var tag = $(this).children("label").text(); var value = $(this).children("input").val(); phoneObjs = $(this).map(function(i,el) { var $el = $(el); return { tag: tag, value:value }; }).get(); person.phones.push(phoneObjs); console.log(phoneObjs); }); </code></pre> <p>Python</p> <pre><code>def save_profile(self): success_msgs = ['Saved! Worry not, nothing sent to the NSA... as far as we know', "Profile Saved, doesn't it feel great to be updated?"] error_msgs = ['Internets are clogged up, our monkeys are checking it out', 'Hmm, everything look correct below?', "A BUG! Probably in our code, we're checking it out"] try: json = self.request.json_body first_name = str(json['firstName']) last_name = str(json['lastName']) organization = str(json['organization']) title = str(json['title']) phones = (json['phones']) emails = (json['emails']) self.profiles.update(firstName=first_name, lastName=last_name, organization=organization, title=title, emails=emails, phones=phones) #print phones value = {'result': 'success', 'message': random.choice(success_msgs)} except Exception, err: print err value = {'result': 'error', 'message': random.choice(error_msgs)} #returns a json response return self.respond(value) </code></pre> <p>profile.update</p> <pre><code>if tools.not_blank(phones): lst = phones cnt = len(lst) current = profile.phones for x in xrange(cnt): o = lst[x] #key = o.get("key", o.get("guid", None)) lbl = o["label"] tag = o.get("tag", None) c = [c for c in current if c.label == lbl] c = c[0] if len(c) &gt; 0 else None if c: m, k = self.codex.decode_composite(c.id) if tools.not_blank(tag): tag = tag.lower().title() if c.tag != tag: c.tag = tag self.get_query("UPDATE member_phone SET Type = @tag WHERE ID = @id;", {"tag": tag, "id": k}).update() else: #create a new email address for this member self.members.register_phone_number(member=member, telephone=lbl, tag=tag) if tools.is_blank(remove): return profile </code></pre> <p><br/> <strong>The IDE will throw the "list indices must be integers, not str" error here</strong></p> <p>Any thoughts? Not sure what is wrong here.</p> <pre><code>self.profiles.update(firstName=first_name, lastName=last_name, organization=organization, title=title, emails=emails, phones=phones) </code></pre> <p><br/></p> <p>The form with added fields creates the correct object here</p> <p><img src="https://i.stack.imgur.com/Sfo6S.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/GSMxM.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload