chameleon can not render deform form - pyramid

I have used deform before with jinja engine but with chameleon i can not render my form
I pass the form to the view to be rendered
#view_config(route_name='home_cms',
renderer='../views/accounts.pt',
request_method='GET',
)
def home(self):
model = Bundle("ModelAccounts", xx.account_id,
xx.name, xx.state, xx.account_type)
cm_filters = xxx(self.request.db)
list_accounts = xxx.search(model=model)
return dict(list_accounts=list_accounts, filter_form=self.form.render())
in the view i add this line
<span tal:content="python:filter_form"></span>
and in the main function I add this line of code
deform.renderer.configure_zpt_renderer()
config.add_static_view('static_deform', 'deform:static')

You don't say specifically what you are getting, but from what I can see I think the issue you are facing is that your HTML form is getting escaped. If this is the case then change your template code in ../views/accounts.pt' to read:
<span tal:content="structure: filter_form"></span>
The "structure" keyword tells Chameleon to not escape the value. See http://chameleon.readthedocs.io/en/latest/reference.html#structure for more details

Related

XPATH Input Tag Query - Katalon Studio

I wanted to read the text of "TestData.txt" from the below HTML Code. There is huge html code in the original page. Sharing the below content for reference. There are few more input tags on the top to the below mentioned HTML code.
Can you please correct the below step definition code ?
Step Definition
TestObject testObj5 = new TestObject().addProperty("xpath", ConditionType.EQUALS, "//input[#value='TestData.txt']??")
inq = WebUI.getText(testObj5)
HTML Code
<input type="file" name="file_attach_text" accept="text/html" value="TestData.txt" onkeypress="if(chkKey(event)){return false;}" id="attach_text" class="button" title="Opens a dialog box to select files">
You can select the element using the xpath with the name attribute and then get the value like this:
TestObject testObj5 = new TestObject().addProperty("xpath", ConditionType.EQUALS, "//input[#name='file_attach_text']")
inq = WebUI.getAttribute(testObj5, "value")

Can I use a Jade if conditional to change a style class value? Using flash variables

Currently I get my message with no problem when the login if it isnt successfull, but I want to display a div if theres any message (for this time just the error message)
This is the code
div(class='formPosSize')
form(action='/auth/login' method='post' autocomplete='off')
fieldset
legend.legend Login
.input
input(name='username', placeholder='Email', required='')
span
i.fa.fa-envelope-o
.input
input(type='password',name='password', placeholder='Password', required='')
span
i.fa.fa-lock
button.submit(type='submit')
i.fa.fa-long-arrow-right
.feedback(class=message!=="undefined" ? "" : "feederror")
if(message)
| #{message}
if theres any message at all, I would like to change the current feedback style variable "display: none and opacity : 0" to "display: block and opacity : 1" a
the feedback class is just a rectangle, I want the message value in there and showing it if it does exist
i tried this too, but it didnt work
if(message)
.feedback(class=feederror)
| #{message}
I have another class called "feederror" that is the same as feedback, but the difference is with opacity and display..
I fixed it at last!
One afternoon lost, but victory!
whenever you get the "message" variable its better to check its lenght rather than check if exist, or is empty, or if true:
this code:
if (message.length > 0)
div.feederror
div #{message}
Generates this if the message variable has anything on it:
<div class="feederror">
<div>Usuario o contraseƱa incorrectas.</div>
</div>
And it does not generate anything if message does not have anything or does not exist.
This helps when you need to show an already designed div with its class (in my code is feederror) containing the message variable from flash.

Correct way to handle pagination with form submission?

I have a form for doing a search on a search page:
<form action="{{ url_for('searchresults') }}" method="get" name="noname" id="theform">
{{ form2.page(id="hiddenpage") }}
... some form inputs
<button id = "mybutton" type = "submit" >Apply</button>
</form>
The form is a SearchForm, where
class SearchForm(Form):
page = HiddenField()
categories = SelectMultipleField(u'Text', validators=[Optional()])
# some other stuff...
The view for searchresults handles the form:
#app.route('/searchresults', methods=['GET'])
def searchresults():
form = SearchForm()
# handle the form and get the search results using pagination
page = int(request.args.getlist('page')[0])
results = models.Product.query....paginate(page, 10, False)
return render_template('searchresults.html', form=form, results=results, curpage=page)
The results in render_template will be the first 10 results of my query. In searchresults.html I display the results, along with a next and previous link for the other results. This page also contains the same search form which I re-instate as per the initial submission. Currently I'm handling the next and previous links using
Next
So the next link re-submits the same initial form, but with the page value increased. I'm not really happy with this approach because when I hover over the next link I don't see the actual page I will be directed to. It also is starting to feel like a bit of a hack. Is there a more natural way to do this? When the form is initially submitted I could use it to create a long string of the desired parameters and use that string in the rendered page as href=" {{ url_for('searchresults') }}?mystring", but this also seems unnatural. How should I handle this?
You have your form configured to submit as a GET request, so you don't really need to force a re-submission through Javascript, you can achieve the same result by setting the next and prev links to URLs that include all the parameters in your form with the page modified to the correct next and previous page numbers.
This is really easy to do with url_for(). Any argument you add that do not match route components will be added to the query string, so you can do something like this:
Next
One thing to keep in mind is CSRF. If you have it enabled in your form, then your next/prev URLs will also need to have a valid token. Or you can disable CSRF, which for a search form might be okay.
Take advantage of the fact that your form arguments are already present in the URL and use request.args to pass the URL parameters into your form:
form = SearchForm(request.args)
Then, if you make your page field an IntegerField with a HiddenInput widget instead of a string field:
from wtforms.widgets import HiddenInput
class SearchForm(Form):
page = HiddenField(widget=HiddenInput, default=1)
you can increment page before you pass the form off to your search results page:
form.page.data += 1
And then, in your page, you simply create the link to the next page:
Next

Alloy user interface (access a tag value)

I'm working with liferay portal 6.2. And I want to get the value of the text in a tag with alloy user interface.
exemple:
<div>
<p> Paragraph </p>
"value"
</div>
the desired result is: value
please help.
AlloyUI, being an extension of YUI3, uses get/set methods to access and manipulate the properties/attributes of the object (YUI3 Node / AlloyUI Node) that is returned when looking up elements from the page.
Some examples can be reviewed in this documentation as well as this documentation.
In general you'll need something unique (i.e. id, css class) to the div in order to fetch only that element. Once you have that element, divNode.get('text') will give you all of the text within the element. There is not a means to easily "skip" the paragraph contents within the div without the value being contained within some other markup. If you have control over the markup and can do this, that would be the best option. Otherwise you are left to using the replace function to strip out the paragraph contents from the text.
<script>
AUI().use('aui-base', function(A) {
var paragraphText = A.one('#myDiv>p').get('text');
var divText = A.one('#myDiv').get('text')
var onlyValue = divText.replace(paragraphText, "").trim()
console.log(onlyValue)
})
</script>

How can I know an object is not visible when any of parent object is not visible in an HTML page using java script?

Let say I have an text box in an HTML page as follows.
<DIV style = "display:none;">
<DIV style = "display:inline;">
<INPUT type = "text" style = "display:inline;">
</DIV>
</DIV>
In this case, the text box will not be visible to the user. How can I identify that text is not currently visible to the user.
Dont say that, I should travel up to the parent objects to find out if they are set to not visible. I have bunch of fields to be validated like this and this would reduce the application performance.
Is there any other way to find out as this object is not visible to the user?
Thanks in advance.
If you don't need it to be pure JavaScript I would suggest using jQuery. Using the :visible or :hidden selector will accomplish what you want:
if ( $('yourElement').is(":hidden") ) {
// The element is not visible
}
http://api.jquery.com/visible-selector/
http://api.jquery.com/hidden-selector/
If you need pure JavaScript and you don't want to travel up through every ancestor element, you could try checking the element's offsetWidth and offsetHeight. If the element is hidden because of an ancestor element, they should both be 0. Note: I've always used jQuery for this, so I don't know how reliable this is.
var yourElement = document.getElementById('yourElementsId');
if ( yourElement.offsetWidth == 0 && yourElement.offsetHeight == 0) {
// The element is not visible
}
https://developer.mozilla.org/en-US/docs/DOM/element.offsetWidth
https://developer.mozilla.org/en-US/docs/DOM/element.offsetHeight

Resources