Two CSS Elements next to each other - html

I tried several hours to get a django forms on same height as the table but somehow it doesnt work properly the django forms go further and further down as i add more data to my table but i want it to stick on top of the div here is my html code:
<div style="display:inline-block;margin-left:10%;width:30%">
{% if status == "O" %}
<form action="{% url 'aktentabelleadd'%}" method="post" style="margin-left:10%;margin-right:5%;border:solid;border-color:white;border-radius: 5px;width:50%">
{% csrf_token %}
<h3 style="color:white;text-align:center">Akte hinzufügen</h3>
<input type="hidden" name="mitglied" value="{{container}}"/>
<input type="hidden" name="benutzer" value=" {{request.user.username}}"/>
<input type="hidden" name="status" value="{{status}}" />
<div style="color:white;margin-left:12%;margin-top:1%;margin-bottom:1%">{{aktenform}}
<button class="btn btn-primary" type="submit" value="hinzufügen">hinzufügen</button>
</div>
</form>
{% endif %}
</div>
<div style="display:inline-block;width:45%">
<table id="myTable" style="border-color:white;border-radius:6px">
<tr style="border:solid;border-color:white;padding-bottom:1%;padding-left:1%;border-radius:6px;color:white">
<th class="spaltenname" onclick="sortTable(0)">Aktenbarcode</th>
<th class="spaltenname" onclick="sortTable(1)">Ersteller</th>
<th class="spaltenname" onclick="sortTable(2)">Startdatum</th>
<th class="spaltenname" onclick="sortTable(3)">Kundennummer</th>
<th class="spaltenname" onclick="sortTable(4)">Aktionen</th>
</tr>
{%for Akte in akte_list reversed %}
<tr>
<td class="cell">{{Akte.Aktenbarcode}}</td>
<td class="cell">{{Akte.user}}</td>
<td class="cell">{{Akte.Startdatum | date:"d.m.Y" }}</td>
<td class="cell">{{Akte.kundennr}}</td>
<td class="cell">
<form action="{% url 'aktedelete' %}" method="post" name="{{Akte.Aktenbarcode}}">
{% csrf_token %}
<!--<input class="btn btn-primary" type="submit" value="{{Akte.Aktenbarcode}}"/> -->
{% if status == "O" %}
<input class="btn btn-primary" data-toggle="modal" data-target=#myModal-{{ forloop.counter }} form="{{Akte.Aktenbarcode}}" type="submit" value="Akte entfernen"/>
<input type="hidden" name="aktenbarcode" value="{{Akte.Aktenbarcode}}" />
<input type="hidden" name="mitglied" value="{{container}}"/>
<input type="hidden" name="benutzer" value="{{request.user.username}}"/>
<input type="hidden" name="status" value="{{status}}" />
<!-- Modal -->
<div class="modal fade" id="myModal-{{ forloop.counter }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle" style="color:black">Akte: {{Akte.Aktenbarcode}}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" style="color:black"> Wollen Sie diese Akte unwiderruflich aus dem Container löschen?</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" value="Save" onclick="form_submit()">Ja, ich bin mir sicher</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal" value="Cancel">Nein</button>
</div>
</div>
</div>
</div>
<!-- ModalEnd-->
</form></td>
{% endif %}
</tr>
{% endfor %}
</table>
</div>
and here is the img of the problem, i want the akteforms to be on the same height as the table header

Related

How check the user how much time spend on a video in

I am using django framework. I embed the youtube video link in html, I want to know that the user spend how much time on the video and save the time in database with his deatils.
the details of the user is stored in cookies. like email.
here is my code.
<div id="request" class="modal fade" {% if request.session.email %} data-backdrop="static" {% endif %} role="dialog">
{% if 'email' not in request.session %}
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<span class="close" data-dismiss="modal" aria-label="Close">×</span>
<h2 class="modal-title">Get start</h2>
</div>
<div class="modal-body text-center">
<form class="form-request" action="" method="post">
{% csrf_token %}
<div class="row-fields row">
<div class="form-group col-field">
<input type="text" class="form-control" name="name" required placeholder="Name *" id="name">
</div>
<div class="form-group col-field">
<input type="email" class="form-control" name="email" required placeholder="Email *" id="email">
</div>
<div class="form-group col-field">
<input type="number" class="form-control" name="phone" required placeholder="Phone *" id="phone">
</div>
<div class="col-sm-12 buttons">
<button type="submit" class="bttn-hover color-1" data-text-hover="Submit">Send request</button>
</div>
</div>
</form>
</div>
</div>
</div>
{% elif request.session.email %} {% comment %} <a href="http://www.youtube.com/watch?v=ANwf8AE3_d0"> {% endcomment %}
<iframe class="embed-responsive-item set-style-of-iframe" src="https://www.youtube.com/embed/tgbNymZ7vqY/?autoplay=1;enablejsapi=1"
allowfullscreen style="height:50%; width:65%" id="myvideo-iframe"></iframe>
<button class="btn btn-close button-closing-style" aria-label="Close" onclick="my_video_pause();"
class="close" data-dismiss="modal">close</button>
<a href="http://cdn.onlinewebfonts.com/svg/img_414950.png" class="button-closing-style" onclick="my_video_pause();" data-dismiss="modal">
</a>
{% endif %}
</div>
</div>

Cannot retrieve data from my flask CRUD application from mysql table even though its getting inserted without any error

Here's the python snippet
#app.route('/oxygenadmin')
#is_logged_in
def oxygenadmin():
cur=mysql.connection.cursor()
cur.execute("SELECT * FROM oxygen")
data =cur.fetchall()
cur.close()
return render_template('oxygenadmin.html', oxygen=data)
#app.route('/insert', methods=['POST'])
#is_logged_in
def insert():
if request.method == 'POST':
name = request.form['name']
contact = request.form['contact']
email = request.form['email']
place = request.form['place']
cur = mysql.connection.cursor()
cur.execute("INSERT INTO oxygen(name, contact, email, place) VALUES (%s, %s, %s, %s)",(name,contact,email,place))
mysql.connection.commit()
flash("Data inserted successfully", 'success')
return redirect (url_for('oxygenadmin'))
return render_template ('oxygenadmin.html')
And here's the html snippet
<div class="row">
<div class="col md-12">
<h2> Oxygen Details <button type="button" class="btn btn-success pull-right" data-toggle="modal" data-target="#mymodal">Enter New Data</button> </h2>
<table class="table table-striped">
<tr>
<th>ID</th>
<th>Name</th>
<th>Contact No.</th>
<th>Email</th>
<th>Place</th>
<th>Action</th>
</tr>
{% for row in oxygen %}
<tr>
<td>{{row.0}}</td>
<td>{{row.1}}</td>
<td>{{row.2}}</td>
<td>{{row.3}}</td>
<td>{{row.4}}</td>
<td>
Edit
Delete
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
and...
<div id="mymodal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Please insert data!</h4>
</div>
<div class="modal-body">
<form action="{{url_for('insert')}}" method="POST">
<div class="form-group">
<label>Name:</label>
<input type="text" class="form-control" name="name" required='1'>
</div>
<div class="form-group">
<label>Contact No. :</label>
<input type="text" class="form-control" name="contact" required='1'>
</div>
<div class="form-group">
<label>Email</label>
<input type="text" class="form-control" name="email">
</div>
<div class="form-group">
<label>Place</label>
<input type="text" class="form-control" name="place" required='1'>
</div>
<div class="form-group">
<button class="btn btn-primary" type="submit">Insert Data</button>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
I somehow just cant get it to appear on my page
Here's how it looks
in the website itself
But it's getting inserted in the actual database though
Didnt paste the entire picture because there are some personal details
The table name is oxygen, I probably think it's doing something with the name itself , I just cant get it
Changing this...
{% for row in oxygen %}
<tr>
<td>{{row.0}}</td>
<td>{{row.1}}</td>
<td>{{row.2}}</td>
<td>{{row.3}}</td>
<td>{{row.4}}</td>
<td>
Edit
Delete
</td>
</tr>
{% endfor %}
to
{% for row in oxygen %}
<tr>
<td>{{row["id"]}}</td>
<td>{{row["name"]}}</td>
<td>{{row["contact"]}}</td>
<td>{{row["email"]}}</td>
<td>{{row["place"]}}</td>
<td>
Edit
Delete
</td>
</tr>
{% endfor %}
solves the issue

Pass ID into Bootstrap delete Modal

I was following a tutorial online to try and create a delete modal from Bootstrap, but it is not picking up on the userid from my users table. The users table is stored on a sql database.
I keep getting the error: jinja2.exceptions.UndefinedError: 'list object' has no attribute 'id'
I have tried looking at similar questions on the stackoverflow site but I am unable to get this working, as I am still learning code and struggling with relating the answers to my setup.
Thanks in advance for anyone that can help.
So below is my delete function.
#app.route("/user/<int:user_id>/delete", methods=['POST'])
#login_required
def delete_user(user_id):
user = User.query.get_or_404(user_id)
db.session.delete(user)
db.session.commit()
flash('The account has been deleted', 'success')
return redirect(url_for('view_user'))
Then this is my html page.
{% extends "layout.html" %}
{% block content %}
<div class="container">
<div class="table-wrapper">
{% with messages = get_flashed_messages(with_categories=true)%}
{% if messages%}
{% for category, message in messages %}
<div class="alert alert-{{category}}">
{{ message}}
</div>
{% endfor %}
{% endif %}
{% endwith %}
<div class="table-title">
<div class="row">
<div class="col-sm-8">
<h2>User Account <b>Details</b></h2>
</div>
<div class="col-sm-4">
<div class="search-box">
<i class="fas fa-search"></i>
<input type="text" class="form-control" placeholder="Search…">
</div>
</div>
</div>
</div>
<table class="table table-striped table-hover table-bordered">
<thead>
<tr>
<th>#</th>
<th>Username<i class="fa fa-sort"></i></th>
<th>Email Address<i class="fa fa-sort"></i></th>
<th>Role<i class="fa fa-sort"></i></th>
<th>Actions</th>
</tr>
</thead>
{% for user in user %}
<tbody>
<tr>
<td>{{user.id}}</td>
<td>{{user.username}}</td>
<td>{{user.email}}</td>
<td>{{user.role}}</td>
<td>
<a href="{{url_for('update_user', user_id=user.id)}}" class="edit" title="Edit"
data-toggle="tooltip"><i class="fas fa-edit"></i></a>
<button type="button" class="btn btn-danger btn-sm m-1" data-toggle="modal" data-target="#deleteModal">Delete</button>
</td>
</tr>
</tbody>
{% endfor %}
</table>
<!-- Modal -->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteModalLabel">Delete User?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<form action="{{ url_for('delete_user', user_id=user.id) }}" method="POST">
<input class="btn btn-danger" type="submit" value="Delete">
</form>
</div>
</div>
</div>
</div>
<div class="clearfix">
<div class="hint-text">Showing <b>5</b> out of <b>25</b> entries</div>
<ul class="pagination">
<li class="page-item disabled"><i class="fa fa-angle-double-left"></i></li>
<li class="page-item">1</li>
<li class="page-item">2</li>
<li class="page-item active">3</li>
<li class="page-item">4</li>
<li class="page-item">5</li>
<li class="page-item"><i class="fa fa-angle-double-right"></i></li>
</ul>
</div>
</div>
{% endblock content %}
Just in case it is needed this is my user table
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), nullable=False, unique=True)
email = db.Column(db.String(80), nullable=False, unique=True)
password = db.Column(db.String(120), nullable=False)
role = db.Column(db.String(80))
<form action="{{ url_for('delete_user', user_id=user.id) }}" method="POST">
<input class="btn btn-danger" type="submit" value="Delete">
</form>
user is python list so you can't able to use here that is why you are getting this error, so inorder to delete specific user you should use one user's route then you can deal with that user.
or
<td>
<i class="fas fa-edit"></i>
<button type="button" class="btn btn-danger btn-sm m-1" data-toggle="modal" data-target="#deleteModal">Delete</button>
</td>
change to
<td class="btn btn-danger" onclick="return confirm('Are you to delete this user?')">Drop</td>
and remove the whole model.
This one will help you to have default model instread of Bootstrap model
Hope that will help you

how to load modal form dynamically

i have a template that shows list of items in a cart and each items can be edited again eg. quantity etc.
The issue am having is that if i intend editing the second or third items, the bootstrap modal form that loads, displays the first item in the list,
Here is my template:
{% if show_delete_btn = True %}
<tr>
<td>{{ order_item.signer }}</td>
<td>{{ order_item.quantity }}</td>
<td>{{ order_item.item_value }}</td>
<td>{{ order_item.auth_fee }}</td>
<!-- <td>{{ order_item.id }}</td> -->
<td>
<div class="hlinks">
<a href="#" data-toggle="modal" data-target="#myModal" class="add_cert_no" title="Edit this item">
<i class="fa fa-pencil-square-o"></i>
</a>
<a href="{% url 'client:delete_item' order_item.id %}" onclick="return confirm('Are you sure you want to delete this item?')";>
<i class="fa fa-trash-o"></i>
</a>
</div>
<!--<p>{{order_item.id}}</p>-->
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog" id="{{order_item.id}}" attr="{{order_item.id}}">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content" align="left">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Edit or Update Item </h4>
</div>
<div class="modal-body">
<div class="alert hidden" id="alert1" role="alert">
</div>
<p id="item_make"></p>
<!--form action="{% url 'jsa_admin:duplicate_remove_item' %}" method="POST" class="special"-->
<!-- <form id="{{order_item.id}}"> -->
<form action="{% url 'client:edit_orderItem' %}" method="post" class="special" name="myForm" enctype="multipart/form-data" id="{{order_item.id}}">
{% csrf_token %}
<div class="col-md-12">
<label>Signer Name or Theme</label>
<input type="text" id="id_signer" maxlength="30" name="signer" value="{{ order_item.signer }}" placeholder = "" required/>
</div>
<div class="col-md-12">
<input type="hidden" id="id_item_id" maxlength="30" name="item_id" value="{{order_item.id}}" placeholder="" required/>
</div>
<div class="col-md-12">
<label>Quantity</label>
<input id="id_quantity" maxlength="30" name="item_quantity" type="number" value="{{ order_item.quantity }}" required/>
</div>
<div class="col-md-12">
<label>Declared Value($)</label>
<input type="number" id="id_item_value" maxlength="30" name="item_value" type="text" value="{{ order_item.item_value }}" required/>
</div>
<div class="col-md-12">
<input id="id_packing_list" maxlength="30" name="packing_list" type="hidden" placeholder="Packing List" value= "n/a" />
</div>
<div class="col-md-12">
</div>
<!-- Continue -->
<div class="modal-body">
<input type="submit" name="edit" id="edit_item" class='btn pull-right' value="Edit"/>
</div>
</form><br>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
{% endif %}
how can i make it load other items on the list also

Bootstrap Modal not greying out 100%

Trying to get a Bootstrap Modal to grey out the background when clicked. It works great but the left sidebar does not grey out. Any idea of why?
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li>Customers</li>
<li>Company</li>
</ul>
</div>
</div>
<!-- Button trigger modal -->
<button type="button" class="btn btn-info btn-md" data-toggle="modal" data-target="#myModal">
New company
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Add company</h4>
</div>
<div class="modal-body">
{% from "_formhelpers.html" import render_field %}
<form action="/company/create" method="POST">
<div class="form-group">
{{ render_field(form.name, class="form-control") }}
</div>
{{ error }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div>
</div>
<button type="button" class="btn btn-success btn-md" data-toggle="modal" data-target="#myNewModal">
New customer
</button>
<!-- Modal -->
<div class="modal fade" id="myNewModal" tabindex="-1" role="dialog" aria-labelledby="myNewModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Add customer</h4>
</div>
<div class="modal-body">
{% from "_formhelpers.html" import render_field %}
<form action="/customer/create" method="POST">
<div class="form-group">
{{ render_field(forms.name, class="form-control") }}
</div>
<div class="form-group">
{{ render_field(forms.email, class="form-control") }}
</div>
<div class="form-group">
{{ render_field(forms.summary, class="form-control") }}
</div>
<div class="form-group">
{{ render_field(forms.purpose, cols="100", rows="10", class="form-control") }}
</div>
<div class="form-group">
{{ render_field(forms.company, class="form-control") }}
</div>
{{ error }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div>
</div>
<h2 class="sub-header">Customers</h2>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Number</th>
<th>Name</th>
<th>Company</th>
</tr>
</thead>
{% for customer in customers %}
<tbody>
<tr>
<td>{{ customer.id }}</td>
<td>{{ customer.name }}</td>
<td>{{ customer.company.name }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
It's a Flask application on local. Let me know if I can provide more information.
Thanks