POST the data from a modal form of bootstrap: What am I missing? - bootstrap-modal

Ask Question
No.1 for booking in our surroundings
No hidden costs
Attractive offers with price advantage
Name
Email address
Question
</footer>

Related

Can you get the price of the currently selected product option?

I'm implementing a Paypal Pay in 4 message and can't figure out how to update the message with the price of the currently selected product option. Is this functionality available?
I'm currently using product.default_price, but for products with a variable price I have to display the default paypal message where I would prefer to use the price of the currently selected option as reflected in the "Add to Cart" button. The html for the theme I am using doesn't reveal how that data is obtained.
Paypal message:
<div
data-pp-message
data-pp-style-layout="text"
data-pp-style-logo-type="primary"
data-pp-style-text-color="black"
data-pp-amount="{{ product.default_price }}">
</div>
Thanks for any suggestions.

amp-form session based backend and 3rd party cookies

Trying to grok this e-commerce scenario...
I build an amp product page in amp that has the new amp-form
The add to cart button is an XHR to my backend (that is session based, using
cookies by default)
User searches for product and results take them
to my amp product page, but they've never been to my site
They submit the add to cart form
the CORS preflight makes it's way to my backend, and i set all the correct allows as per https://github.com/ampproject/amphtml/blob/master/spec/amp-cors-requests.md
Now the actual request is made... backend initializes a session,
returns session identifier as a cookie, but since user never went to
my site...just the google amp cache it's treated as a 3rd party
cookie and browser discards it (cause user disables 3rd party cookies)
users session is lost, as is their add to cart action
So the question is, how do i keep the session around and the item in the cart?
Am i missing something? is there a trick i'm not seeing?
appreciate any insights.
Associating the shopping cart with the CLIENT_ID would be the best way to solve this problem. Unfortunately, transferring the CLIENT_ID via forms is not yet supported in AMP. It's currently being implemented, you can watch this issue for the current status.
Here is an approach that works right now: the idea is to encode the shopping cart content into a string that is returned in the form result. This way we can generate "View Cart" and "Checkout" links including the shopping cart content. Once the user clicks on one of those links, you can create the actual shopping cart in your backend and store the user id in a cookie.
For example:
<form action-xhr="/add-to-cart" method="POST">
<input type="hidden" name="itemId" value="headphones-123">
<!-- Hide after form submit success -->
<input type="submit" name="add" value="Add to Cart">
<div submit-success>
<template type="amp-mustache">
<!-- shopping cart contents, e.g headphones-123 -->
{#shoppingCartContent}
View In Cart
Checkout
{/shoppingCartContent}
</template>
</div>
<div submit-error>
<template type="amp-mustache">
{{message}} <!-- e.g. Only 2 Headphones are left. -->
</template>
</div>
</form>
The disadvantage of this approach is that the shopping cart will be lost when the user leaves the page without viewing the cart first. This will be solved once the CLIENT_ID can be passed via amp-form.
I also know very limited info about AMP pages but I suggest that you please read through the use of User identification and try using an AMP-generated client ID. As mentioned in the documentation:
By default, AMP will manage the provision of a client ID whether the page is accessed from the publisher's original website or through a cache.
Likewise, learn more about client ID substitution, including how to add an optional user notification ID, in Variables supported in AMP analytics.
Hope that helps!

Append information at the end of the URL

I have an application which is very similar to forum. Users can participate in posting content. When user click on a topic it goes to that topics page which shows all the discussion related to that topic. I have a side bar just like in the stackoverflow where it shows similar questions which shows topics related to the title of the topic in the current page.
Here is the sidebar template code:
<div class="box">
<h2>{% trans %}Related Topics{% endtrans %}</h2>
<div class="topic-related">
{% for thread_dict in similar_threads.data() %}
<p>
{{ thread_dict.title|escape }}
</p>
{% endfor %}
</div>
</div>
I have an application that tracks user clicks. Assume that user went to a topic and after seeing the related topics she clicks on a topics and go to that page. But I have no way of distinguishing if the user directly went to this topics other than using related topics section.
So I thought may be I can add something like fromRelatedTOpics to the end of the url. What is the best way to accomplish this?
{{ thread_dict.title|escape }}
Is this possible?
The keyword you are looking for is referer. If the user clicked a link to your site, the referer may tell you where he came from (this depends on the browser setting). To access the referer from a view, you have to access the META attribute of the request, i.e.:
request.META.get('HTTP_REFERER')
You may want to look into this django snippet to get some inspiration.
If you want this information inside the template, you can try this:
{{ request.META.HTTP_REFERER }}
What you can do is to redirect all clicks to "related topics" to a single view, also pass the related topic id (or any unique value which can identify that topic in backend) to this view.
Now whenever this view is executed you can safely assume that someone clicked on "related topic", so record this behavior. Using referer (as described by #steinar) you can also record the parent page url from where relative link was clicked.
After recording the behavior you can redirect user to "related topic" using the unique id passed to this view.

Need user to pick from a list to connect two users in YESOD

I need general guidance on how to structure a YESOD app. I would like to keep the app as "RESTful" in design as possible.
The user searches all the other users to find one to connect with. I show the possible connections using Hamlet:
$forall (pid, person, mEmail, mPhone) <- displayPeopleRecs
<p>
<a href=#{CreateFundR pid}>#{personNickName person}
$maybe email <- mEmail
#{emailEmail email}
$maybe phone <- mPhone
#{phoneNumber phone}
However, now when a user clicks on a link they go to the /createfund/ page as a GET request which is not what I want, I want to use POST or something else.
Can anyone explain what the correct solution is here? Do I make a form for each person what the search produces and have a submit button for each possible person? That seems silly. Is it better to use Julius and change the onclick handler for the link to submit a POST instead of a GET to /createfund ?
Here is the relevant line from my config/routes:
/createfund/#PersonId CreateFundR POST
By the way, I can see how to make this work by using a form and a submit button:
$forall (pid, person, mEmail, mPhone) <- displayPeopleRecs
<p>
<form method="post" action="#{CreateFundR pid}">
<table>
<tr>
<td>
#{personNickName person}
$maybe email <- mEmail
<br>
#{emailEmail email}
$maybe phone <- mPhone
<br>
#{phoneNumber phone}
<td>
<input type="submit" value="Create Fund">
That will work for my needs, but I'd really like to allow the user to just click the link. Is this poor design? Or just a matter of taste?
If you use an AForm / MForm, the form will be automatically generated for you (using Tables or Divs). That should simplify things for you.
If you want to manually style it, you can do something like this when using a form: How to make button look like a link?. Most people end up creating styled buttons for such actions anyways (think of your standard CRUD app with Edit, Delete buttons, etc.).
If you go down the path of trapping link clicks and do ajax Post, it will not degrade nicely if javascript is disabled so something you need to watch out for.
HTH

sqllite read/write queue concern with django

I'm building a website where college students can order delivery food. One special attribute about our site is that customers have to choose a preset delivery time. For example we have a drop at 7pm, 10pm, and at midnight.
All the information about the food is static (ie price, description, name), except the quantity remaining for that specific drop time.
Obviously i didn't want to hardcode the HTML for all the food items on my menu page, so i wrote a forloop in the html template. So i need to store the quantity remaining for the specific time somewhere in my model. the only problem is that I'm scared that if i use the same variable to transport the quantity remaining number to my template, i'll give out wrong information if alot of people are accessing the menu page at the same time.
For example, lets say the 7pm drop has 10 burritos remaining. And the 10pm drop has 40 burritos. Is there a chance that if someone has faster internet than the other customer, the wrong quantity remaining will display?
how would you guys go around to solve this problem?
i basically need a way to tell my template the quantity remaining for that specific time. and using the solution i have now, doesn't make me feel at ease. Esp if many people are going to be accessing the site at the same time.
view.py
orders = OrderItem.objects.filter(date__range=[now - timedelta(hours=20), now]).filter(time=hour)
steak_and_egg = 0
queso = 0
for food in orders:
if food.product.name == "Steak and Egg Burrito":
steak_and_egg = steak_and_egg + food.quantity
elif food.product.name == "Queso Burrito":
queso = queso + food.quantity
#if burritos are sold out, then tell template not to display "buy" link
quantity_steak_and_egg = max_cotixan_steak_and_egg - steak_and_egg
quantity_queso = max_cotixan_queso - queso
#psuedocode
steakandegg.quantity_remaining = quantity_steak_and_egg
queso.quantity_remaining = quantity_queso
HTML:
{% for item in food %}
<div id="food_set">
<img src="{{item.photo_menu.url}}" alt="" id="thumbnail photo" />
<div style='overflow:hidden'>
<p id="food_name">{{item.name}}</p>
<p id="price">${{item.price}}</p>
</div>
<p id="food_restaurant">By {{item.restaurant}}</p>
<div id="food_footer">
<img src="{{MEDIA_URL}}/images/order_dots.png" alt="" id="order_dots" />
<a id ="order_button" href="{{item.slug}}"></a>
<p id="quantity_remaining">{{item.quantity_remaining}} left</p>
</div><!-- end food_footer-->
</div><!-- end food_set-->
I don't understand what "faster Internet" or "using the same variable" have to do with anything here (or, indeed, what it has to do with sqlite particularly).
This question is about a fundamental property of web apps: that they are request/response based. That is, the client makes a request, and the server replies with a response, which represents the status of the data at that time. There's simply no getting around that: you can make it more dynamic, by using Ajax to update the page after the initial load, which is what StackOverflow does to show update messages while you're on the page. But even then, there's still a delay.
(I should note that there are ways of doing real-time updates, but they're complicated, and almost certainly overkill for a college food-ordering website.)
Now the issue is, why does this matter? It shouldn't. The user sees a page saying there is 1 burrito left - perhaps with a red warning saying "order quickly! almost gone!" - and they press the order button. On submission of that order, your code presumably checks for the actual status at that time. And, guess what, in the meantime you've processed another order and the burrito has already gone. So what? You simply show a message to the user, "sorry, it's gone, try something else". Anyone with any experience ordering things on the web - say, concert tickets - will understand what's happened.