ModX Revolution: method get pass encoded character - search

I am using SimpleSearch snippet in Modx Revolution CMS for searching webpage content.
Using form like this:
<form class="sisea-search-form" action="[[~[[+landing]]]]" method=get>
<input type="text" name="hledej" id="hledej" value="[[+searchValue:default=`Hledej...`]]" onfocus="if (this.value == 'Hledej...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Hledej...';}" />
Searching on webpage works, except for strings with specials characters like "ěščřžýáá" (different language). Problem is that method get encode pass this character in url like this:
../search-result.html?search=str%25C3%25A1nce&id=13
and find 0 results....
if the search string in url is not encoded (tried to rewrite it manually), it returns some results...
I also tried to use method post, but id doesnt work at all...
Any idea?

It works correctly on different hosting, so problem is probably somewhere else.
I am closing this topic.

Related

Warning: Text content did not match... but it does

I'm experimenting with SSR since I've never touched the subject before and want to learn more about it. I've built a simple SSR and it works fine, except when I add some variables in the mix.
This works fine:
<span>msg: hello</span>
This cast an error:
const txt = 'hello';
...
<span>msg: {txt}</span>
Warning: Text content did not match. Server: "msg: hello" Client: "msg: "
If I check the doc request this is what I get from localhost:
<span>msg: hello</span>
and when I inspect element:
<span>
"msg: "
"hello"
</span>
My initial thinking is that the hydration does not read the next line, and just see "msg: ", even tho, it looks fine in the dom and all the data is correct.
I can, however make it work with a templatestring <span>{`msg: $txt}`}</span>
but I have several cases where I check what to print with a function.
Anyone got more information on this one, how can I make React hydration to be more open minded and check for the next line?
check if you use renderToString, and not renderToStaticMarkup.
Similar problem: https://lihautan.com/hydrating-text-content/

How to redirect a wrong url with the same pattern that a user messed up in django, without javascript

assume the following:
Your model has: Products.slug
urls: path('<int:id>/<slug:slug>/', views.product_detail, name='product_detail'),
views: products = Products.objects.get(id=id, slug=slug)
Someone goes to /products/1/brazil-nuts/, and it goes to the right page.
But then someone copy/pastes the url wrong to: /products/1/brazil-nu/
Then you get a DoesNotExist error... Now you could "fix" this by not forcing the slug=slug argument in your query, but then the url is incorrect, and people could link from /products/1/brazil-nu-sjfhkjfg-dfh, which is sloppy.
So how would I redirect an incorrect url to the correct one with the same url structure as the correct one (only id and slug arguments), without relying on JavaScript's window.history.pushState(null, null, proper_url); every time the page loads?
I've already tried making the same url pattern to redirect, but since django uses the first pattern match, it won't work no matter where you put the url in your list.
Just update your view:
products_q = Products.objects.filter(id=id, slug__startswith=slug)
products_count = products_q.count()
if products_count == 1:
product = products_q.first()
return reverse_lazy('product_detail', args=[product.id, product.slug])

How to delete an NDB object from a Google Database using its key, not even compiling

I am new to Python, using currently versión 3.8. I uploaded a basic Project into the Google Cloud platform. Unfortunately and despite trying all answers here, using urlsafe and reconstructing strings as a way to identify my object, the Google cloud either does not compile the code or once executed gives me errors I cannot trace because all are "proven solutions"
I created an object inherited from NDB
from google.cloud import ndb
class Contact(ndb.Model):
name = ndb.StringProperty()
phone = ndb.StringProperty()
email = ndb.StringProperty()
In my deletion form, I refer to its "id" using this call
<form action="/delete" method="post">
<input type="hidden" name="uid" value="{{ contact.key.id() }}">
<button type="submit">Eliminar</button>
</form>
in my main program, the delete function (method) I use this:
#app.route(r'/delete', methods=['POST'])
def delete_contact():
client = ndb.Client()
with client.context():
contact = Contact.get_by_id(int(request.form.get('uid')))
contact.key.delete()
return render_template('contact.html')
This is the original code and it is supposed to work. I check the documentation and tried other alternatives that compile but give me execution errors such as the urlsafe. It compiles but does not work even when I get the key in my handler.
The line that does not compile is "contact.key.delete()". The contact is indeed retreived but somehow the method to delete it does not work.
Any ideas? I am new to Python, so I will prefer a solution rather than an explanation, thanks.
Carlos
Even though nobody answered me, I finally got it fixed despite the errors. I had a serialization error, a defname error in that method (I had to separate def from the name of the method itself), an ahref error fixed by writing "a href", an indentation error and an invalid method error. Since I was uploading everything into the Google Cloud, it suddenly started working by itself!

How can I click a link in an HtmlNode

I am creating a headless C# application and one of my HTML elements looks like
<input name="SUBMIT-chn.pss" title="Select" class="image selectIcon" type="image" alt="Select" src="docs/pics/select.png">
My method looks like
private void AddInputElement(HtmlNode element)
{
string name = element.GetAttributeValue("name", "");
string value = element.GetAttributeValue("value", "");
string type = element.GetAttributeValue("type", "");
if (string.IsNullOrEmpty(name)) return;
switch (type.ToLower())
{
case "image":
'I would like to do something like element.Click to go to the next page.
default:
Add(name, value);
break;
}
}
I am using HtmlAgilityPack 1.4.9 with .Net 4.5.2
Thank you
HtmlAgilityPack (HAP) is the wrong tool for this kind of task. It is only a HTML parser, which enable you to extract information from the source HTML, modify a bit of the HTML, and so on. HAP works on HTML markup level, and you can't interact with the HTML controls through HAP.
To click on a link, type on a textbox and so on, you need a real browser or something that emulate a real browser. You might want to look into .NET binding of Selenium WebDriver using PhantomJS headless browser to accomplish this. See a simple example here.

DustJS logic to verify empty string

I need to write logic to check whether the value is empty or it has string. Any help on this.. i tried this following. but it doesn't work in nodejs and throwing error
{#if cond="'{notes}' != '' || '{errors}' != '' "}
display html
{/if}
The #if helper is deprecated and should not be used. However, based on the code you've given, you should probably be able to use an exists check.
{?notes}
{?errors}
{! Display HTML !}
{/errors}
{/notes}
If that doesn't work for some reason, you could use the #ne helper.
{#ne key=notes value=""}
...
{/ne}
If that still isn't good enough, you could try writing a context helper. The documentation on dustjs.com is excellent.
{?notes}
Display HTML
{:else}
{?errors}
Display HTML
{/errors}
{/notes}
should do the trick.

Resources