I pass a list into a message using the django message framework. When it is rendered in the template, I try to access the list using {{ item.0 }} for example, but nothing is coming through. If I just use {{ item }}, I can see my list.
In short, I suspect the list isn't actually a list, it is a string that looks like a list (such as "['field1','field2']").
I arrive at this conclusion because if I try to access any list item > 0, the template renders empty, which implies there is no list item beyond position 0, which is consistent with the fact that item is a string.
Messages are populated in the View as:
for item in errorRecords:
messages.add_message(request, messages.WARNING, item)
Here, item is a list (e.g. ['field1','field2','field3']....)
Attempting to access the message list in the template:
{{ message.0 }}
works for position 0, but not for position 1 (renders blank). When access position 0, the entire list contents is shown . i.e. renders as:
['field1','field2','field3']
I want to be able to access each list's elements, so that I can populate a table with each field.
Related
I added a sublist field on a transaction. For instance a Sales Order. When you add the field via user event script, it positions the field at the end of the sublist. Is there a way to position the field? This can't be accomplished in the UI as the field is added via script. It's a select type field, so I am trying to modify the list values with client script and can only do that if the field is created in my user even script. My code works perfectly fine, it's just the field is at the end of the sublist line(far right and have to scroll). I am using SuiteScript 1.0 but am open to using 2.0 if I need to.
This is for suitescript 2.0
This has sort of turned into two questions so I will give an answer for one and then the solution, for clarity. The short answer is you cannot move a sublist field when created in a user event (however there is a solution to that.)
you can add a sublist field by getting the sublist and using the sublist.addField method.
function beforeLoad(context){
var form = context.form;
var sublist = form.getSublist({
id : 'item'
});
sublist.addField({
id: 'fieldid you want to use for script reference ect.',
type: serverWidget.FieldType.CHECKBOX, //any supported TYPE
label: 'Label users will see in sublist'
});
}
If done this way, there will be a new column on the end of the items sublist that cannot be moved.
To be able to move the location of the column do the following.
Navigate to
Customization
Lists, Records, & Fields
Transaction Line Fields
add a new field and apply to the sublist you want it used on.
you can assign and id which will be prefixed with custcol so start your id with an _ and give it a name.
Once this is complete you can access the field by id and change the value in your user event script before load
function beforeLoad(context){
var form = context.form;
var sublist = form.getSublist({
id : 'item'
});
sublist.setSublistValue({
id: 'customcol_id_created_in_ui',
line: 1, //line you want to access if needing to set all you will have to loop through and set each one.
value: "your value"
});
}
If you go to the API reference and look at the ui/serverWidget module and navigate to sublist you can find all of the methods and options for manipulating sublist there.
In SuiteScript 2.x you would use the N/ui/serverWidget module, create the field and then use the Form.insertField(options) method, passing in the field you created as options.field and the existing field which you want to insert your field before as options.nextfield. Note that Form refers to the form object passed to the user event script in the scriptContext.
i don't believe there is a SS1.0 equivalent.
I am using bs4 for web scraping. This is the html code that I am scraping.
items is a list of these multiple div tags i.e <div class="list_item odd" itemscope=""...>
from which the tag that I really want from each in items element is:
<p class="cert-runtime-genre">
<img title="R" alt="Certificate R" class="absmiddle certimage" src="https://m...>
<time datetime="PT119M">119 min</time>
-
<span>Drama</span>
<span class="ghost">|</span>
<span>War</span>
</p>
The main class of this list is saved in items. From that I want to scrape the img tag and then access the title attribute so that I can save all the certifications of the movies in a database i.e R or PG etc. But when I apply loop to the items it gives an error that the items is not subscriptable. I tried list comprehensions, simple for loop, called items elements through a predefined integer array nothing works and still gives the same error. (items is not Null and is subscriptable i.e. is a list). But when I call it with a direct integers it works fine i.e items[0] or items[1] etc, and gives the correct result for each corresponding element in the items list. The error line is below:
cert = [item.find(class_ = "absmiddle certimage")["title"] for item in items] or
cert = [item.find("img",{"class": "absmiddle certimage"})["title"] for item in items]
and this is what works fine: cert = items[0].find(class_ = "absmiddle certimage")["title"]
Any suggestion will be appreciated.
I need to display only one document from my CouchDB, but if I don't create for-each loop, I can't define variable employer
.row
.col-xs-12.col-sm-8
.row.list-group
each employer in the employers
.col-xs-12.list-group-item
h4
p #{employer.value.name}, #{employer.value.location} #{employer.value.type}, #{employeer.value.position}
small
.col-xs-12.col-sm-4
p.lead= sidebar
When I try to display only one document without the loop, I am receiving an error: Cannot read property 'value' of undefined
If employeers is an array, you should be able to do something like:
employeers[0].value.name
If you want to keep using "employer" you can also replace your each loop with:
- var employer = employeers[0];
i have a script that works with internet explorder (ie) and i need to loop the select fields, that it zelf is no ploblem bu the 4 elements got the same ID (on the same page).
How do i let it loop through the 4 fields?
Can i make them more spesified?
the code i use is the following:
ie.document.getElementByID("DownloadImage").Click
The ie code is the following:
field 1
<a id="DownloadButton" href="javascript:__doPostBack('ctl00$ctl00$MainContent$MainContent$ctl00$declaratiebestandView$RetourInformatieGrid$ctl03$DownloadButton','')">CZ_Specificatie_150005697.pdf</a>
field 2
<a id="DownloadButton" href="javascript:__doPostBack('ctl00$ctl00$MainContent$MainContent$ctl00$declaratiebestandView$RetourInformatieGrid$ctl03$DownloadButton','')">CZ_Specificatie_150005697.pdf</a><input name="ctl00$ctl00$MainContent$MainContent$ctl00$declaratiebestandView$RetourInformatieGrid$ctl03$DownloadImage" class="inlineButton" id="DownloadImage" type="image" src="../images/download.png" text="CZ_Specificatie_150005697.pdf">
then it opens the download screen, and then my code continue's (and works :) )
You can loop them by using querySelectorAll to gather all the elements with an id attribute whose values match what you are after. You can distinguish between them by index. This method will allow you to gather them even though the ids are repeating. However, the HTML you have shared downloads the same document so a loop doesn't seem necessary.
Dim nodeList As Object, i As Long
Set nodeList = ie.document.querySelectorAll("[id=DownloadButton]")
For i = 0 to nodeList.Length-1
nodeList.item(i).Click
Next
That loops all of the matching elements and clicks
By index will be specific but if you familiarize yourself with CSS selectors there are a vast number of possibilities for specifying an element.
The id in HTLM must be unique. If it is not unique it is no valid HTML and should be fixed.
HTML4:
http://www.w3.org/TR/html4/struct/global.html
Section 7.5.2:
id = name [CS]
This attribute assigns a name to an element. This name must be unique in a document.
HTML5:
http://www.w3.org/TR/html5/dom.html#the-id-attribute
The id attribute specifies its element's unique identifier (ID). The
value must be unique amongst all the IDs in the element's home subtree
and must contain at least one character. The value must not contain
any space characters.
I'm using Watir-5.0.0, selenium-webdriver-2.40 and testing on IE-8. When I execute the following code:
puts "#browser.tables.length=#{#browser.tables.length}"
#browser.tables.each { |t| puts t.to_s }
t=#browser.table(:class => "jrPage")
puts "jrPage=#{t}"
t.rows.each do |row|
# do something
end
I get the following results:
#browser.tables.length=5
#<Watir::Table:0x3921cc0>
#<Watir::Table:0x3921c48>
#<Watir::Table:0x3921c00>
#<Watir::Table:0x3921bd0>
#<Watir::Table:0x3921b88>
jrPage=#<Watir::Table:0x39219d8>
Selenium::WebDriver::Error::StaleElementReferenceError: Element is no longer valid
Any thoughts on why is table I explicitly locate, Watir::Table:0x39219d8, is not in the #browser.tables.each collection?
I can understand why I get the StaleElementReferenceError (table not found) but not why the table I explicit locate isn't in the tables list.
I can find this table in the HTML.
The code is calling to_s for the table object. Watir-webdriver does not specifically define this method for elements. Therefore, it calls Ruby's default Object#to_s method:
Returns a string representing obj. The default to_s prints the
object’s class and an encoding of the object id. As a special case,
the top-level object that is the initial execution context of Ruby
programs returns “main.”
As you can see, this is what Watir is doing - Watir::Table is the object's class and 0x39219d8 is an encoding of the object id.
When iterating through the tables or getting a table, you are retrieving the table from scratch. In other words, a new table object is created for each of these commands. Even if you run the collection again, you will see that you get 4 different table object ids each time.
Note that while the table objects you are seeing are unique, the jsPage is referring to one of the elements in the collection. You can use the == method to check if two objects are referencing the same html element.
For example, you can see this with:
# Get the specific jrPage
jrPage = browser.table(:class => "jrPage")
# Check which element in the collection is the jrPage
browser.tables.each { |t| puts t == jrPage }
#=> false
#=> false
#=> true
#=> false
#=> false
The above tells you that the jrPage is the 3rd table on the page.