initial commit
All checks were successful
Build and Push Image / build-and-push (push) Successful in 1m26s
All checks were successful
Build and Push Image / build-and-push (push) Successful in 1m26s
This commit is contained in:
parent
3bba1f6db6
commit
b56e866071
36 changed files with 4160 additions and 0 deletions
51
app/models.py
Normal file
51
app/models.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
from datetime import datetime
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_login import UserMixin
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from app import db
|
||||
|
||||
class User(UserMixin, db.Model):
|
||||
"""Gebruiker model voor geregistreerde gebruikers"""
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
email = db.Column(db.String(120), unique=True, nullable=False, index=True)
|
||||
password_hash = db.Column(db.String(255), nullable=False)
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
|
||||
# Relatie met incidents
|
||||
incidents = db.relationship('Incident', backref='user', lazy='dynamic', cascade='all, delete-orphan')
|
||||
|
||||
def set_password(self, password):
|
||||
"""Hash het wachtwoord"""
|
||||
self.password_hash = generate_password_hash(password)
|
||||
|
||||
def check_password(self, password):
|
||||
"""Controleer het wachtwoord"""
|
||||
return check_password_hash(self.password_hash, password)
|
||||
|
||||
def __repr__(self):
|
||||
return f'<User {self.email}>'
|
||||
|
||||
class Incident(db.Model):
|
||||
"""Incident model voor het bijhouden van snauwgedrag"""
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True) # Null voor anonieme gebruikers
|
||||
timestamp = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
|
||||
severity = db.Column(db.Integer, nullable=False) # 1-5 Snauw-index schaal
|
||||
notes = db.Column(db.Text, nullable=True) # Optionele opmerkingen
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
|
||||
# Voor anonieme gebruikers
|
||||
session_id = db.Column(db.String(255), nullable=True, index=True) # Voor anonieme tracking
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Incident {self.id}: severity={self.severity} at {self.timestamp}>'
|
||||
|
||||
def to_dict(self):
|
||||
"""Converteer naar dictionary voor JSON responses"""
|
||||
return {
|
||||
'id': self.id,
|
||||
'timestamp': self.timestamp.isoformat(),
|
||||
'severity': self.severity,
|
||||
'notes': self.notes or '',
|
||||
'created_at': self.created_at.isoformat()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue