Initial Commit
This commit is contained in:
commit
9d88779d4b
44
.gitignore
vendored
Normal file
44
.gitignore
vendored
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# Ideen Ordner
|
||||||
|
_idee/
|
||||||
|
|
||||||
|
# Virtuelle Umgebungen
|
||||||
|
venv/
|
||||||
|
.env/
|
||||||
|
env/
|
||||||
|
|
||||||
|
# IDEs und Editoren
|
||||||
|
*.pyc
|
||||||
|
*.log
|
||||||
|
*.tmp
|
||||||
|
*~
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
*.sublime-workspace
|
||||||
|
*.sublime-project
|
||||||
|
|
||||||
|
# Build-Artifacts
|
||||||
|
build/
|
||||||
|
dist/
|
||||||
|
__pycache__/
|
||||||
|
|
||||||
|
# Test- oder Entwicklungsunterlagen
|
||||||
|
test_results/
|
||||||
|
test_data/
|
||||||
|
tests/__pycache__/
|
||||||
|
tests/*.log
|
||||||
|
|
||||||
|
# Spezifische Plattformdateien
|
||||||
|
*.DS_Store
|
||||||
|
.AppleDouble/
|
||||||
|
.Spotlight-V100/
|
||||||
|
.TemporaryItems/
|
||||||
|
.Trashes/
|
||||||
|
DesktopDB/
|
||||||
|
|
||||||
|
# Sonstige unerwünschte Dateien
|
||||||
|
Thumbs.db
|
||||||
|
ehthumbs.deny
|
||||||
|
ehthumbs.deny~
|
||||||
|
._*
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
30
app.py
Normal file
30
app.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
from flask import Flask, render_template, request, jsonify
|
||||||
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
|
||||||
|
# Initialize the database object
|
||||||
|
db = SQLAlchemy()
|
||||||
|
|
||||||
|
def create_app():
|
||||||
|
# Create a new Flask application instance
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
# Configure the SQLite database URI for the application
|
||||||
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///mydatabase.db'
|
||||||
|
|
||||||
|
# Disable tracking modifications to SQLAlchemy objects
|
||||||
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||||
|
|
||||||
|
# Initialize the database object with the Flask application instance
|
||||||
|
db.init_app(app)
|
||||||
|
|
||||||
|
# Import and initialize models, then create tables within the app context
|
||||||
|
with app.app_context():
|
||||||
|
from models import User # Assuming there is a file named models.py containing the User model
|
||||||
|
from utils import check_and_create_tables # Assuming there is a file named utils.py containing the check_and_create_tables function
|
||||||
|
check_and_create_tables(db) # Call the function to ensure tables are created if they don't exist
|
||||||
|
return app
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# Create and run the Flask application instance with debugging enabled
|
||||||
|
app = create_app()
|
||||||
|
app.run(debug=True)
|
3
config.py
Normal file
3
config.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class Config:
|
||||||
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///learn.db'
|
||||||
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
BIN
instance/learn.db
Normal file
BIN
instance/learn.db
Normal file
Binary file not shown.
7
models.py
Normal file
7
models.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from app import db
|
||||||
|
|
||||||
|
class User(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
username = db.Column(db.String(80), unique=True, nullable=False)
|
||||||
|
password = db.Column(db.String(120), unique=True, nullable=False)
|
||||||
|
email = db.Column(db.String(120), unique=True, nullable=False)
|
10
requirements.txt
Normal file
10
requirements.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
blinker==1.8.2
|
||||||
|
click==8.1.7
|
||||||
|
Flask==3.0.3
|
||||||
|
Flask-SQLAlchemy==3.1.1
|
||||||
|
itsdangerous==2.2.0
|
||||||
|
Jinja2==3.1.4
|
||||||
|
MarkupSafe==2.1.5
|
||||||
|
SQLAlchemy==2.0.31
|
||||||
|
typing_extensions==4.12.2
|
||||||
|
Werkzeug==3.0.3
|
233
templates/index.html
Normal file
233
templates/index.html
Normal file
@ -0,0 +1,233 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="de">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Social Media Layout</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
|
||||||
|
<style>
|
||||||
|
.sidebar {
|
||||||
|
height: 100%;
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
background-color: #f0f2f5;
|
||||||
|
}
|
||||||
|
.main-content {
|
||||||
|
background-color: #f0f2f5;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
.profile-card,
|
||||||
|
.story,
|
||||||
|
.post,
|
||||||
|
.who-to-follow,
|
||||||
|
.news {
|
||||||
|
background-color: #ffffff;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 15px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
.profile-card img,
|
||||||
|
.who-to-follow img {
|
||||||
|
width: 60px;
|
||||||
|
height: 60px;
|
||||||
|
object-fit: cover;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
.story input {
|
||||||
|
border-radius: 30px;
|
||||||
|
}
|
||||||
|
.story button {
|
||||||
|
border-radius: 20px;
|
||||||
|
}
|
||||||
|
.post img {
|
||||||
|
width: 100%;
|
||||||
|
border-radius: 15px;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
.who-to-follow button {
|
||||||
|
border-radius: 20px;
|
||||||
|
}
|
||||||
|
.navbar,
|
||||||
|
footer,
|
||||||
|
body {
|
||||||
|
background-color: #f0f2f5;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm mb-3">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<a class="navbar-brand" href="#"><img src="https://via.placeholder.com/30" alt="Logo" /></a>
|
||||||
|
<button
|
||||||
|
class="navbar-toggler"
|
||||||
|
type="button"
|
||||||
|
data-bs-toggle="collapse"
|
||||||
|
data-bs-target="#navbarNav"
|
||||||
|
aria-controls="navbarNav"
|
||||||
|
aria-expanded="false"
|
||||||
|
aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link active" aria-current="page" href="#">Demo</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">Pages</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">Account</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">My Network</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<form class="d-flex">
|
||||||
|
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<!-- Sidebar -->
|
||||||
|
<div class="col-12 col-md-3 sidebar mb-3">
|
||||||
|
<div class="profile-card text-center p-3">
|
||||||
|
<img src="https://via.placeholder.com/100" alt="Profile Picture" />
|
||||||
|
<h5>Sam Lanson</h5>
|
||||||
|
<p>Web Developer at Webestica</p>
|
||||||
|
<p class="text-muted">I'd love to change the world, but they won’t give me the source code.</p>
|
||||||
|
<div class="d-flex justify-content-around">
|
||||||
|
<span>256 Posts</span>
|
||||||
|
<span>2.5K Followers</span>
|
||||||
|
<span>365 Following</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="list-group">
|
||||||
|
<a href="#" class="list-group-item list-group-item-action">Feed</a>
|
||||||
|
<a href="#" class="list-group-item list-group-item-action">Connections</a>
|
||||||
|
<a href="#" class="list-group-item list-group-item-action">Latest News</a>
|
||||||
|
<a href="#" class="list-group-item list-group-item-action">Events</a>
|
||||||
|
<a href="#" class="list-group-item list-group-item-action">Groups</a>
|
||||||
|
<a href="#" class="list-group-item list-group-item-action">Notifications</a>
|
||||||
|
<a href="#" class="list-group-item list-group-item-action">Settings</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Main Content -->
|
||||||
|
<div class="col-12 col-md-6 main-content mb-3">
|
||||||
|
<!-- Post a Story -->
|
||||||
|
<div class="story p-3 shadow-sm">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<img
|
||||||
|
src="https://via.placeholder.com/50"
|
||||||
|
class="rounded-circle me-3"
|
||||||
|
alt="Profile Picture" />
|
||||||
|
<input type="text" class="form-control" placeholder="Share your thoughts..." />
|
||||||
|
</div>
|
||||||
|
<div class="d-flex justify-content-around mt-3">
|
||||||
|
<button class="btn btn-outline-primary">Photo</button>
|
||||||
|
<button class="btn btn-outline-primary">Video</button>
|
||||||
|
<button class="btn btn-outline-primary">Event</button>
|
||||||
|
<button class="btn btn-outline-primary">Feeling/Activity</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Posts -->
|
||||||
|
<div class="post p-3 shadow-sm">
|
||||||
|
<div class="d-flex">
|
||||||
|
<img
|
||||||
|
src="https://via.placeholder.com/50"
|
||||||
|
class="rounded-circle me-3"
|
||||||
|
alt="Profile Picture" />
|
||||||
|
<div>
|
||||||
|
<h6>Lori Ferguson</h6>
|
||||||
|
<small class="text-muted">Web Developer at Webestica • 2hr</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="mt-3">
|
||||||
|
I'm thrilled to share that I've completed a graduate certificate course in project
|
||||||
|
management with the president's honor roll.
|
||||||
|
</p>
|
||||||
|
<img src="https://via.placeholder.com/600x300" alt="Post Image" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Right Sidebar -->
|
||||||
|
<div class="col-12 col-md-3 mb-3">
|
||||||
|
<!-- Who to Follow -->
|
||||||
|
<div class="who-to-follow p-3 shadow-sm">
|
||||||
|
<h6>Who to follow</h6>
|
||||||
|
<div class="d-flex align-items-center my-2">
|
||||||
|
<img
|
||||||
|
src="https://via.placeholder.com/50"
|
||||||
|
class="rounded-circle me-3"
|
||||||
|
alt="Profile Picture" />
|
||||||
|
<div>
|
||||||
|
<h6 class="mb-0">Judy Nguyen</h6>
|
||||||
|
<small class="text-muted">News anchor</small>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-outline-primary ms-auto">+</button>
|
||||||
|
</div>
|
||||||
|
<div class="d-flex align-items-center my-2">
|
||||||
|
<img
|
||||||
|
src="https://via.placeholder.com/50"
|
||||||
|
class="rounded-circle me-3"
|
||||||
|
alt="Profile Picture" />
|
||||||
|
<div>
|
||||||
|
<h6 class="mb-0">Amanda Reed</h6>
|
||||||
|
<small class="text-muted">Web Developer</small>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-outline-primary ms-auto">+</button>
|
||||||
|
</div>
|
||||||
|
<div class="d-flex align-items-center my-2">
|
||||||
|
<img
|
||||||
|
src="https://via.placeholder.com/50"
|
||||||
|
class="rounded-circle me-3"
|
||||||
|
alt="Profile Picture" />
|
||||||
|
<div>
|
||||||
|
<h6 class="mb-0">Billy Vasquez</h6>
|
||||||
|
<small class="text-muted">News anchor</small>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-outline-primary ms-auto">+</button>
|
||||||
|
</div>
|
||||||
|
<div class="text-center mt-3">
|
||||||
|
<button class="btn btn-link">View more</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Today's News -->
|
||||||
|
<div class="news p-3 shadow-sm">
|
||||||
|
<h6>Today's news</h6>
|
||||||
|
<ul class="list-unstyled">
|
||||||
|
<li class="mb-2">
|
||||||
|
Ten questions you should answer truthfully <small class="text-muted">2hr</small>
|
||||||
|
</li>
|
||||||
|
<li class="mb-2">
|
||||||
|
Five unbelievable facts about money <small class="text-muted">3hr</small>
|
||||||
|
</li>
|
||||||
|
<li class="mb-2">
|
||||||
|
Best Pinterest Boards for learning about business <small class="text-muted">4hr</small>
|
||||||
|
</li>
|
||||||
|
<li class="mb-2">
|
||||||
|
Skills that you can learn from ... <small class="text-muted">4hr</small>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer class="bg-white text-center py-3 shadow-sm mt-3">
|
||||||
|
<div class="container">
|
||||||
|
<small>© 2024 Webestica. Alle Rechte vorbehalten.</small>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
30
utils.py
Normal file
30
utils.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
from sqlalchemy import inspect, Integer, String
|
||||||
|
|
||||||
|
def check_and_create_tables(db):
|
||||||
|
inspector = inspect(db.engine)
|
||||||
|
|
||||||
|
# Überprüfen, ob die Tabelle 'user' existiert
|
||||||
|
if not inspector.has_table('user'):
|
||||||
|
print("Tabelle 'user' existiert nicht, sie wird erstellt.")
|
||||||
|
db.create_all()
|
||||||
|
else:
|
||||||
|
print("Tabelle 'user' existiert.")
|
||||||
|
# Überprüfen der Spalten
|
||||||
|
columns = inspector.get_columns('user')
|
||||||
|
column_names = [col['name'] for col in columns]
|
||||||
|
|
||||||
|
# Benötigte Spalten
|
||||||
|
required_columns = {
|
||||||
|
'id': Integer,
|
||||||
|
'username': String,
|
||||||
|
'email': String
|
||||||
|
}
|
||||||
|
|
||||||
|
for col_name, col_type in required_columns.items():
|
||||||
|
if col_name not in column_names:
|
||||||
|
print(f"Spalte '{col_name}' fehlt, sie wird hinzugefügt.")
|
||||||
|
with db.engine.connect() as conn:
|
||||||
|
if col_type == Integer:
|
||||||
|
conn.execute(f'ALTER TABLE user ADD COLUMN {col_name} INTEGER')
|
||||||
|
elif col_type == String:
|
||||||
|
conn.execute(f'ALTER TABLE user ADD COLUMN {col_name} STRING')
|
Loading…
Reference in New Issue
Block a user