I need to show links or may be a form, for just the logged admins.
for example to do something like this :
<%if(IsAdmin()){%>
<div>
Show all orders
<div/>
<%}%>
You can use following check
if (HttpContext.Current.Request.IsAuthenticated && HttpContext.Current.User.IsInRole("Administrators"))
Related
I got receipt url from stripe like:
"receipt_url": "https://pay.stripe.com/receipts/acct_1FpzDdEHHOJvKiFZ/ch_1IsB5REHHOJvKiFZGxagDBoQ/rcpt_JVBS4giqfp3YUoHcqzjQAwMHWq",. I added to template as:
<div class="status-message">{{ transID.receipt_email }}<br/>Find your Receipt here:</div>
When i click on the link i'm redirected to the same page.
view storing fields from stripe:
transID = stripe.PaymentIntent.retrieve(session.payment_intent)
context = {
'customer': customer,
'transID': transID,
}
Is there a way when clicking on the link to redirected to the stripe's receipt_url?
Many thanks.
Is it possible that the receipt_url is empty? That would likely cause the behaviour you're describing. Maybe try logging it to make sure it's actually present.
I am creating a personal website using Django with Wagtail, in which users belonging to different groups can access certain pages. For example, the family group can see my holiday photos, while the co-workers group can see some internal documents.
Setting up permissions access permission is very straightforward through the admin. However, I would like to show a lock next to the link to forbidden pages. This will make it very clear to the user which links can be followed and which ones can't.
Is there any way to verify whether the current user has access to a given page?
After fiddling around with Wagtail's code, I've found that the permissions are handled through a model called PageViewRestriction (the code is very succinct and clear), which in turns inherits BaseViewRestriction that defines a method accept_request. Since the page to which is referring is store in the model, the only missing piece is the user requesting access.
With this, I've managed to put together a very simple template tag, which checks whether the current user can see the given page. The filter looks like this:
#register.simple_tag(takes_context=True)
def can_view(context, page):
pvrs = PageViewRestriction.objects.filter(page=page)
request = context['request']
if pvrs:
for pvr in pvrs:
if pvr.accept_request(request):
return True
return False
return True
Which in turn I use in my template like this:
{% can_view menuitem as permission %}
{% if not permission %}
<i class="fas fa-lock"></i>
{% endif %}
Note that in principle a page can have multiple different permissions specified. For example, members of different groups can view it. I assumed that if the current user belongs to one of those groups, or if the page does not specify view permissions, then the user can access that page.
I want to add three more filed to cart page .()
<input name="pr_name">
<input name="pr_phone >
<input name="pr_add">
can any one help me to add these files to cart .
you will need to modify the following:
the model for the cart /catalog/model/checkout
the controller for the cart /catalog/controller/checkout
the view for the cart whatever theme you are using
finally you will need to do the same for the admin panel and depending on where you would like to see them for example you might want to view them in the invoice you will need to change the model / controller that correspond to that. unfortunately its not like a plug and play thing.
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
I have a web page where the user enters some data and then clicks a submit button. I process the data and then use the same Django template to display the original data, the submit button, and the results. When I am using the Django template to display results, I would like the page to be automatically scrolled down to the part of the page where the results begin. This allows the user to scroll back up the page if she wants to change her original data and click submit again. Hopefully, there's some simple way of doing this that I can't see at the moment.
It should already work if you provide a fragment identifier in the action method of the form:
<form method="post" action="/your/url#results">
<!-- ... -->
</form>
and somewhere below the form, where you want to show the results:
<div id="results">
<!-- your results here -->
</div>
This should make the page jump to the <div> with ID results.
It is complete client site and does not involve Django, JavaScript or similar.
You need to wrap your data into something like this:
<div id="some-id">YOUR DATA TO BE DISPLAYED</div>
and if you make redirect in your view you need to redirect to url: /some-url/#some-id
if you don't make redirect you need to scroll to the bottom using javascript (but note that redirect is preffered way to use in view after saving data).