Skip to content

Commit

Permalink
bootstrap inner tabs not working
Browse files Browse the repository at this point in the history
  • Loading branch information
N1Keey committed Mar 24, 2022
1 parent e087f2d commit 59a9ec8
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 49 deletions.
Binary file modified __pycache__/database.cpython-38.pyc
Binary file not shown.
76 changes: 31 additions & 45 deletions database.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
from sqlalchemy import create_engine, ForeignKey, Column, Integer, String, Table, text
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relationship
import json
import random
import math

engine = create_engine('sqlite:///users.db',
connect_args={'check_same_thread': False})
engine = create_engine('sqlite:///users.db',connect_args={'check_same_thread': False})

connection = engine.connect()
Base = declarative_base()
Session = sessionmaker(bind=engine)
session = Session()
connection=engine.connect()
Base=declarative_base()
Session= sessionmaker(bind=engine)
session=Session()

roles_users = Table(
'roles_users', Base.metadata,
roles_users = Table('roles_users',Base.metadata,
Column('user_id', Integer, ForeignKey('users.id', ondelete="CASCADE")),
Column('role_id', Integer, ForeignKey('roles.id', ondelete="CASCADE")))

Column('role_id', Integer, ForeignKey('roles.id', ondelete="CASCADE"))
)

class User(Base):
__tablename__ = 'users'
__tablename__='users'

id = Column(Integer, primary_key=True)
email = Column(String(100), unique=True)
password = Column(String(255))
roles = relationship('Role', secondary=roles_users)

roles = relationship('Role', secondary=roles_users)
def regist(user_email, user_password):
"""Adds User to Database and gives the standard-role: 'User'
Parameter: user_email = String
Parameter: user_password = String
"""
new_User = User(email=user_email, password=user_password)
new_user_role = session.query(Role).filter(Role.name == 'User').first()
new_User.roles = [new_user_role]
new_User=User(email=user_email, password=user_password)
new_user_role=session.query(Role).filter(Role.name=='User').first()
new_User.roles=[new_user_role]
session_add_and_commit(new_User)

def login(user_email, user_password):
Expand All @@ -43,44 +38,38 @@ def login(user_email, user_password):
Parameter: user_email = String
Parameter: user_password = String
"""
login_bool = False
users = session.query(User)
login_bool=False
users=session.query(User)
for user in users:
if user_email == user.email and user_password == user.password:
login_bool = True
if user_email==user.email and user_password==user.password:
login_bool=True
return login_bool

def getall2Dict():
""" returns Userdata of all Users with roles in a list of Dictionarys
Dict={'ID':user.id,'Email':user.email,'Password':user.password,'Roles':userrolelist}
Return: userdicts = List (dict)
"""
userdicts = []
users = session.query(User).join(User.roles).all()
userdicts=[]
users=session.query(User).join(User.roles).all()
for user in users:
userrolelist = []
userrolelist=[]
for role in user.roles:
userrolelist.append(role.name)
userdict = {
'ID': user.id,
'Email': user.email,
'Password': user.password,
'Roles': userrolelist
}
userdicts.append(userdict)
userrolelist.append(role.name)
userdict={'ID':user.id,'Email':user.email,'Password':user.password,'Roles':userrolelist}
userdicts.append(userdict)
return userdicts

def delete(user_ID):
"""Deletes User with given user_ID
Parameter: user_ID = String"""
user = session.query(User).filter(User.id == user_ID)
user=session.query(User).filter(User.id==user_ID)
if user.first().email != '[email protected]':
user.delete()
session.commit()


class Role(Base):
__tablename__ = 'roles'
__tablename__='roles'

id = Column(Integer, primary_key=True)
name = Column(String(40), unique=True)
Expand All @@ -90,25 +79,22 @@ def add(role_name, role_description):
"""Adds Role to Database
Parameter: role_name = String, role_description = String
"""
new_Role = Role(name=role_name, description=role_description)
new_Role=Role(name=role_name, description=role_description)
session_add_and_commit(new_Role)

def role2User(user_email, role_name):
"""Adds Role with role_name to User with user_email
Parameter: role_name = String, role_description = String
"""
user_roles = []
user = session.query(User).join(
User.roles).filter(User.email == user_email).first()
user_roles=[]
user=session.query(User).join(User.roles).filter(User.email==user_email).first()
for role in user.roles:
user_roles.append(role)
new_user_role = session.query(Role).filter(
Role.name == role_name).first()
new_user_role=session.query(Role).filter(Role.name==role_name).first()
user_roles.append(new_user_role)
user.roles = user_roles
user.roles=user_roles
session.commit()


def session_add_and_commit(new_obj_name):
"""speichert new_obj_name in Datenbank ein
Parameter: new_obj_name = sqlelement
Expand Down
5 changes: 5 additions & 0 deletions static/bootstrap.min.css

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions static/bootstrap.min.js

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions templates/_base.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<link rel="stylesheet" href="static/bootstrap.css">
<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="{{ url_for('static', filename='bootstrap.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='bootstrap.min.css') }}" rel="stylesheet">

{% block styles %}
<style>
html, body {margin: 0; height: 100%; overflow: hidden}
Expand Down Expand Up @@ -61,10 +65,11 @@
{% block title %} <title>Title</title> {% endblock %}
{% block navbar %}
<nav class="navbar navbar-expand-sm bg-light navbar-light sticky-top">
<a class="navbar-brand" href="/home">schick-services</a>
<a class="navbar-brand" href="/home">schick.services</a>
</div>
<ul class="navbar-nav">
<li {% if active_link == 'Home' %} class="active" {% endif %}> <a class = "nav-link" href="/home">Home</a></li>
<li {% if active_link == 'Kalender' %} class="active" {% endif %}> <a class = "nav-link" href="/kalender">Kalender</a></li>
</ul>
<ul class="navbar-nav mr-auto">
<li {% if active_link == 'Usermanagement' %} class="active" {% endif %}><a class = "nav-link" href="/admin_auth">Usermanagement</a></li>
Expand All @@ -80,5 +85,7 @@
{% endblock %}
{% block content %}
<div class='content'>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="{{ url_for('static', filename='bootstrap.min.js') }}"></script>
</div>
{% endblock %}
30 changes: 30 additions & 0 deletions templates/kalender.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends "_base.j2" %}
{% set active_link = 'Kalender' %}
{% block styles %}
{{ super() }}
<style>
</style>
{% endblock %}
{% block title %} <title>Kalender</title> {% endblock %}
{% block content %}
<div>

<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li>
<li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
<li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
<li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="home">...</div>
<div role="tabpanel" class="tab-pane" id="profile">...</div>
<div role="tabpanel" class="tab-pane" id="messages">...</div>
<div role="tabpanel" class="tab-pane" id="settings">...</div>
</div>

</div>
{% endblock %}

10 changes: 8 additions & 2 deletions website.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ def home():
return redirect('/')
return render_template('home.j2')

@app.route('/kalender', methods=['GET', 'POST'])
def kalender():
if not session.get('logged_in'):
return redirect('/')
return render_template('kalender.j2')


@app.route('/admin_auth', methods=['GET', 'POST'])
def admin_auth():
Expand Down Expand Up @@ -108,5 +114,5 @@ def test():


if __name__ == '__main__':
#app.run()
app.run(host='0.0.0.0', port=5000)
app.run()
#app.run(host='0.0.0.0', port=5000)

0 comments on commit 59a9ec8

Please sign in to comment.