List items are missing after submitting the request - list

I have one request form and I have submitted the request successfully and popup appears on successful submission of the request which I have received.But when I went to the list items at the backend,I could not find the item that was submitted.
I have checked the recycle bin also and no where it is.
What might be the reason for the request not appearing in the list?Is that because of network issue?Looking weird as I have got the successful notification popup on submitting the request

Related

How to make Django view accessible only when a GET request is issued by HTMX?

I am trying to learn HTMX for using it with Django.
I have a simple HTMX button that when you click you get some filtered results on the page.
The problem is that when users go to the specified URL provided for the purpose of showing content through the GET request, they can see the content of the page.
They should only be able to see this content when they press the HTMX button though, not by navigating to the URL HTMX gets in order to show the content.
Is there any way on how to handle this?
You can achieve this by checking for a specific header called HX-Request that is always set to true by HTMX. So if a user visits a HTMX only endpoint and the request header does not have the HX-Request key you can response with an error, 404, or forward the user to a different endpoint.

Is there a way to Verify return a form Validation error back to the UI in Django within an Ajax request

I currently have an issue where i am sending formData from the UI through Ajax to the backend, however, i also created an helper function within the form to allow Image compression whilst it receives the data from the frontend. When the form encounters an exception while compressing, it doesn't return the error to the User until the AJAX request has gotten a response from the server and then i reload the page, I am thinking of using JS to reload the page if the response if false to display the error. Is this a better implementation or how should i go about it?

Sails/Waterlock password reset flow

G'day all,
Does anyone have any experience with the Waterlock flow for passsword resets? I've hit a wall which I can see a work-around for, but it seems really in-elegant, so I'm probably missing something.
When I send through an auth/reset POST with an email element, the system proceeds to shoot the email out as planned.
When I then submit the received link in a POST request, with a password element, I see a "404" response.
HOWEVER
If I submit that link as a GET request first, and then submit the POST it works.
When I look into the waterlock-local-auth source, the reset POST action is testing for the presence of a decrypted token in the request object before allowing it to proceed.
SO
Either I code my front end to send a get request (which doesn't respond properly) and then resubmit as a POST, or I go in and hack the waterlock-local-auth code to include a decode of the token (which is what I'm thinking is the most elegant solution).
Any clues?
Thanks,
Andy
I have got a similar problem, but I use angularjs as my frontend. This discussion thread is very helpful:
https://github.com/waterlock/waterlock-local-auth/issues/7
Basically, you are expected to submit a GET request to the url received in the password reset email. After you click the link with the token, you will find in your database that a new ResetToken record has been created and the value in the token column is exactly the one you see in the url. Then you should be redirected to the forwardUrl in waterlock.js setting, where there should be a form or anything that can make you post to:
http://yourdomain.com/auth/reset?password=newpassword
Then the password is reset and the ResetToken record will be removed from your database.
If you look at the handlePost function here:
https://github.com/waterlock/waterlock-local-auth/blob/master/lib/controllers/actions/reset.js#L68
This can explain why POSTing to the url sent to you in the reset password email returns 404. The resetToken must exist in session already in order that issuePasswordReset to be invoked. And the only place to set req.session.resetToken is within validateToken method:
https://github.com/waterlock/waterlock-local-auth/blob/master/lib/controllers/actions/reset.js#L188
So you need a get request first. Hope this helps.

Does Django process requests as queue?

I am building a voting mechanism for a site. A similar one seen on Stackoverflow.
For instance, if user clicked up-arrow, vote = True. If he clicks again on it, vote = None. The app is working fine except if we submit votes very fastly.
We tried to click arrows very very fastly and see how voting is happening by logging the data. Unfortunately, we are seeing some misbehavior. By fast, I mean, clicking the arrow continuously without stopping for some seconds!
The expected log data should be like
vote=True
vote=None
vote=True
vote=None
..
But I observed it like
vote=True
vote=True
vote=None
vote=None
The observed log data mentioned as second case, seems to be a bit unordered..
This could mean that the requests received by django are not handled as a queue! Which in our case is a bit dangerous. Or database is taking some time to store and during that period another requests are handled which is causing the error.
I hope you are understanding my issue. So, I am wondering if you can let me know what's going on here and how to control it.
You cannot make assumptions about the order in which a browser sends (asynchronous) requests, the order in which they arrive at the server and the order in which they are handled by a single or multi-instance (threaded, worker) Django application.
So what you describe above is what you actually might expect. Doing synchronous requests may help a bit. The best option is probably to (asynchronously) wait for the server's response before allowing further clicks.
You must be having a flow similar to this:
-> User clicks button
-> check if user has already voted up
-> if no:
-> vote up request goes
-> vote up after validation
-> response is sent back to browser
-> else:
-> vote none request goes
-> remove the vote after validation
-> response is sent back to browser
If you don't disable the button for the time when a request has already been sent and its response is awaited, then you will get into such situations.
Say, request1 was considered a vote up and request was sent.
Before request1's response came and user clicked again, then this request will also be considered as a vote up, which is not what you expect.
You should either disable the button, just before making the ajax call and enable it again when the response is received.
Or whenever user clicks, you should flip the button type i.e. make it vote-none for vote-up request and vice versa, even before making the ajax call. And when the ajax response is received, validate the previous action again. It will vary only in cases, when any validation fails on server side, like the user might not have permission to vote up.
You can see this happening in SO if you try to vote-up your own post. It first changes to vote-none mode and then later when the response is received from server, it changes back and also gives an error message.
PS: I tried to vote-up my own posts for educational purposes only ;)

django messages get displayed only on the next request

I have a django app and I use messages in order to show some limits that user passes.
My problem is that all my messages are shown after the second request.
I mean, after adding a message and going to a page where the the message should be shown, I don't see it, but I start seeing it after a refresh.
What am I doing wrong?
This is probably how those messages are intended to work: You "trigger" them e.g. to show success/failure and then redirect to another page where it's displayed. Remember: In case an action succeeded you should never stay on the page requested via POST but redirect so reloading won't re-POST whatever was sent.