I am trying to print account ıd, account no, equity, no of share on my website. I want to use Alpaca for this - alpacajs

I am not sure whether I should use broker apı keys or trading apı keys. I tried both of them but none of them worked. I put two photos one of them is api.py and the other one is my home page. The code that is at below is in a template folder in home.html
{% block content %}
{% if user.is_authenticated %}
<div class="text-center" style="padding-top:100px">
<h3>Welcome <b>{{ user.get_username }}</b> to SINO</h3>
</div>
<div class="text-align:left">
<h3>You are connected with Alpaca :)</h3>
</div>
<div class="text-align:left">
<b>Account ID:</b> {{Alaccount.id}}
</div>
</div>
<div class="text-align:left">
<b>Account Number:</b> {{Alaccount.account_number}}
</div>
</div>
<div class="text-align:left">
<b>Equity:</b> {{Alaccount.equity}}
</div>
<div class="text-align:left">
<b>Number of shares:</b> {{alpaccount.position.qty}}
</div>
</div>
</div>
[enter image description here][1]{% else %}

Related

How can I remove the navbar in these three parts in my python project?

I am currently trying to build a website with python django. At the moment I am making a dashboard for the website. On the dashboard I want to show three tiles for different menu options. Dashboard
Ignore the content this is just a placeholder for now. As you can see in every part of the dashboard the navbar is included. My code for the dashboard looks like following:
{% extends 'base.html' %}
{% block titel %}Dashboard{% endblock %}
{% block content%}
<div class="container-fluid">
<h1 class="fw-bold">Dashboard</h1>
<div class="row">
<div class="col-sm-4">
<div class="card">
<div class="card-body" >
{% include 'todolist/index.html' %}
</div>
</div>
</div>
<div class="col-sm-4">
<div class="card">
<div class="card-body">
{% include 'todolist/index.html' %}
</div>
</div>
</div>
<div class="col-sm-4">
<div class="card">
<div class="card-body">
{% include 'todolist/index.html' %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}
The base for all the sites are in a extra file called base.html. In this file is also the navbar defined.
How can I prevent that the navbar will be in every part of the dashboard while still using the extends part?
You can put the navbar section in another template rather than having it in the base template. This way you can decide when to use it separetely than the base template.

Django Calculation inside HTML

I wanted to do something simmilar to this suing django. but somehow i it doesn't work. how do i fix it?
for statik in statistik{
print(statik*total/100)
}
Is there any documentation regarding what I'm trying to implement to my django app? Thank you
Here's the HTML :
{% if statistics %}
{% for statik in statistics|slice:":4" %}
<div class="mb-3">
<div class="small text-gray-500">{{ statik.name }}
<div class="small float-right"><b>{{ statik.voters }} of {{ total }} Voters</b></div>
</div>
<div class="progress" style="height: 12px;">
<div class="progress-bar bg-success" role="progressbar" style="width: {{ statik.voters * total/100 }}%" aria-valuenow="50"
aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
{% endfor %}
{% else %} <p>END TABLE</p>
{% endif %}
It is recommended you do calculations of any sort in view and pass it in context.
If you still want to go this route there are no math template tags except add included so you should create custom template tags or use django-mathfilters

How can I pass an image ID from the view into my routes.py, when the images are displayed in the view via a for loop?

I'm building a simple portfolio website where the owner will be able to manage a gallery page, Adding, Editing and Removing posts. I am printing the images from the DB using a for loop and need a way in order to get either the name of the image or the ID of the image and send the value back to the route in order to delete the row from the DB. Any suggestion would be much appreciated.
Additional information:
Using Flask w/ SQLalchemy & WTforms
Sample of how I'm displaying the images and accompanying data:
{% for image in Posts | reverse %}
<div class="row pt-3">
<div class="col">
<img class="img-fluid rounded" src="static/gallery_images/{{image.image }}" alt="">
</div>
</div>
<div class="row pt-4">
<div class="col">
<h3 style="display: inline">{{image.title}}</h3>
<p class="font-italic text-muted" style="display: inline">
{% if image.sold_flag %}
- Sold
{% else %}
- Available
{% endif %}
</p>
<p class="text-muted">{{image.date_posted.strftime('%d/%m/%Y')}}</p>
</div>
</div>
<div class="row">
<div class="col">
<p class="font-weight-normal">{{ image.description }}</p>
</div>
</div>
<div class="row">
{% if current_user.is_authenticated %}
<div class="col text-left">
<button type="button" class="btn btn-dark">Edit</button>
<button type="button" class="btn btn-danger">Delete</button>
</div>
{% endif %}
</div>
<hr class="border">
{% endfor %}
There are multiple ways to store the id and use it for a route call. Using purely what you have shared, you can add a call to the button to the respective endpoints:
Assuming you have a method images.delete(id) to delete images and that you want to keep with the button tag on your code:
<a href={{url_for('delete.edit', id=image.id)}}>
<button type="button" class="btn btn-dark">
Delete
</button>
</a>
However, I would really recommend for you to use a form to submit the delete, as opposed to a GET request generated above. This way you can have it secured with WTForm CSRF token.
Example:
HTML
<form action="{{url_for('delete.edit', id=image.id)}}" method="POST" role="form">
{{ form.hidden_tag() }}
</form>
Python
## Make sure to create the delete form
class DeleteImage(Form):
pass

Using Instagram API to make users populate images into my Django application directly from Instagram Pictures

My use case or what I want to do is:
Users click a Upload button,
it authenticates user,
its shows Instagram images,
users select, and
user click upload button to upload images or videos (media) from
Instagram directly into my django app.
What I have done is:
Instagram integration:
pip install python-instagram
views.py:
#login_required()
def instagram_pictures(request, template='dashboard/add-instagram-pictures.html'):
user = request.user
gallery = []
gallery = Gallery.objects.filter(service_provider=user.service_provider_profile)
context = {'gallery': gallery}
return render(request, template, context)
#login_required()
def add_instagram_pictures(request, template='dashboard/add-instagram-pictures.html'):
access_token = "YOUR_ACCESS_TOKEN" # Dont know how this gets factored in for any user
client_secret = settings.SECRET_ID
api = InstagramAPI(access_token=access_token, client_secret=client_secret)
recent_media, next_ = api.user_recent_media(user_id="userid", count=10)
for media in recent_media:
print(media.caption.text)
template/my-gallery.html:
{% extends 'base.html' %}
{% load static %}
{% block title %}My Dashboard{% endblock %}
{% block content %}
<div class="page-header" style="background: url({% static 'img/banner1.jpg' %});">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 class="page-title">My Gallery</h1>
</div>
</div>
</div>
</div>
<div id="content">
<div class="container">
<div class="row">
{% include '_side_menu.html' %}
<div class="col-md-8 page-content">
<div class="inner-box text-center">
<a href="{% url 'dashboard:add-instagram-pictures' %}" class="btn btn-md btn-success">
<span class="fa fa-plus-circle"> Upload from Instagram</span>
</a>
<ul>
<!-- I will re-write this loop to redefine how images are rendered for the project. Maybe in Carousels-->
{% for p in photos %}
<li>{{ p.name }}</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
template/add-instagram-pictures.html:
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Gallery{% endblock %}
{% block content %}
<div class="page-header" style="background: url({% static 'img/banner1.jpg' %});">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 class="page-title">Add Instagram Pictures</h1>
</div>
</div>
</div>
</div>
<div id="content">
<div class="container">
<div class="row">
{% include '_side_menu.html' %}
<div class="col-md-8 page-content">
<div class="inner-box text-center">
<a href="{% url 'dashboard:my-gallery' %}" class="btn btn-md btn-success">
<span class="fa fa-chevron-circle-left"> Back to Album List</span>
</a>
</div>
</div>
</div>
</div>
</div> {% endblock %}Add
url.py:
from django.conf.urls import url, include
from dashboard.views import dashboard, my_services, add_service, my_gallery, add_gallery, bank_profile, add_bank_profile, add_instagram_pictures
def ajax_photo_upload_view(args):
pass
urlpatterns = [
url(r'^$', dashboard, {}, name='home'),
url(r'^bank-profile/$', bank_profile, {}, name='bank-profile'),
url(r'^add-bank-profile/$', add_bank_profile, name='add-bank-profile'),
url(r'^my-services/$', my_services, name='my-services'),
url(r'^add-service/$', add_service, name='add-service'),
url(r'^add-gallery/$', add_gallery, name='add-gallery'),
url(r'^my-gallery/$', my_gallery, name='my-gallery'),
url(r'^add-gallery/$', add_instagram_pictures, name='add-instagram-pictures'),
]
settings.py:
# instagram settings
CLIENT_ID = "XXXXXXXXXXXXXXXXXXXX"
SECRET_ID = "XXXXXXXXXXXXXXXXXXXX"
How do I go about my use case as I have stated, my solution is in no way closer to what I want to do.

How can I set a custom Template for djangocms-blog?

I have a djangocms based website and now I would like to have an app which will help with a small blog section.
Now, I have successfully integrate djangocms-blog in my website, but when I am trying to see a post, the template (a custom template made by me) is not rendered and the post (made from blog admin) is just thrown on the page.
Can anybody help me out with this issue ? Would you like any additional info in order to help me out with this ?
My template looks like this:
{% extends "base.html" %}
{% load cms_tags %}
{% block title %}{% page_attribute "page_title" %}{% endblock title %}
{% block content %}
<div class="spacer"></div>
<div class="page-header page-header-blog-post-1 white">
<div class="page-header-container container">
<div class="page-header-content">
<h1 class="heading">BLOG</h1>
</div>
</div>
</div>
<div class="blog-container blog-single container">
<div class="row">
<div class="col-md-8 blog-content margin-bottom-70 clearfix">
{% placeholder banner_leaderboard_top %}
</div>
</div>
<div class="row">
<div class="col-md-8 blog-content margin-bottom-70 clearfix">
<article id="post-1" class="post-1 post format-standard">
<header class="entry-header">
<div class="post-thumbnail-area">
{% placeholder "post_header_image" or %}
<img src="/static/img/onepage-slide9.jpg" alt="image_blog"/>
{% endplaceholder %}
</div>
</header>
<div class="entry-content">
<div class="entry-title blog-info">
<h1 class="heading">{% placeholder "post_header_title" or %}POST_TITLE{% endplaceholder %}</h1>
</div>
{% placeholder "POST_BODY" or %}POST_BODY{% endplaceholder %}
</div>
<footer class="entry-footer">
<div class="entry-description">
<h6 class="post-date-classic">{% placeholder "post_date" or %}POST_DATE{% endplaceholder %}</h6>
</div>
</footer>
</article>
<div class="post-additional">
<script type="text/javascript">
// Popup window code
function newPopup(url) {
popupWindow = window.open(
url, 'popUpWindow', 'height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
<ul class="post-share list-inline">
<li><a href="JavaScript:newPopup('https://www.facebook.com/sharer/sharer.php?u='+window.location.href)"><i
class="icon ion-social-facebook"></i></a></li>
<li><a href="JavaScript:newPopup('http://twitter.com/home/?status=Nice blog post - '+window.location.href);"><i
class="icon ion-social-twitter"></i></a></li>
<li><a href="JavaScript:newPopup('https://plus.google.com/share?url='+window.location.href); "><i
class="icon ion-social-googleplus"></i></a></li>
</ul>
<div class="post-navigation nav-links">
<ul class="post-controls list-inline">
<li>
{% placeholder "prev_post" or %}
<a class="post-prev" href="#"><i class="icon ion-ios7-arrow-thin-left"></i></a></li>
{% endplaceholder %}
<li>
{% placeholder "next_post" or %}
<a class="post-next" href="#"><i class="icon ion-ios7-arrow-thin-right"></i></a></li>
{% endplaceholder %}
</ul>
</div>
</div>
<div class="author-bio">
<div class="row">
<div class="author-avatar col-xs-4 col-sm-3 col-md-3 visible-desktop">
{% placeholder "author_img" or %}
<img src="/static/img/image-8.jpg" alt="image_blog"></div>
{% endplaceholder %}
<div class="author-details white col-md-9">
<h3>{% placeholder "author_name" or %}AUTHOR_NAME{% endplaceholder %}</h3>
<p>{% placeholder "author_body" or %}AUTHOR_BODY{% endplaceholder %}</p>
</div>
</div>
</div>
{% placeholder banner_leaderboard_bottom %}
</div>
<div class="col-md-4">
<div class="sidebar">
<aside id="recent-posts-2" class="widget widget_recent_entries">
<div class="widget-title">
<h5 class="heading">RECENT POSTS</h5>
<div class="fancy-line-small"></div>
</div>
{% placeholder "post_recent" or %}
<ul>
<li>Recent blog post</li>
</ul>
{% endplaceholder %}
</aside>
{% placeholder banner_square_right %}
</div>
</div>
</div>
</div>
{% endblock %}
Some image with administration of djangocms-blog:
So, I'd like the Title from Blog admin to be applied on my template instead of <h1 class="heading">BLOG</h1> and so on for date , category and so on
If you want to override a template used by an app that you've installed you simply need to mimic the same template path in your template directory.
The CMS blog templates can be found here.
So to override the CMS blog templates you should decide which template needs to be overridden, in this case it sounds like post_detail.html because you're concerned with how a post displays.
So in your project you need to create something like; myproj/templates/djangocms_blog/post_detail.html
Then the system will load that one instead of the post_detail.html from the site-packages folder.