removed secrets from the code (reom from chatgpt)
This commit is contained in:
@@ -2,6 +2,7 @@ from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_login import UserMixin
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from datetime import datetime
|
||||
from sqlalchemy import func
|
||||
|
||||
db = SQLAlchemy() # Create the extension object
|
||||
|
||||
@@ -72,12 +73,26 @@ class User(UserMixin, db.Model):
|
||||
return 0
|
||||
|
||||
class ListOfItems(db.Model):
|
||||
__table_args__ = (
|
||||
db.UniqueConstraint("owner_user_id", "name", name="uq_list_owner_name"),
|
||||
)
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
updated_at = db.Column(db.TIMESTAMP, default=datetime.now(), onupdate=datetime.now(), nullable=False)
|
||||
owner_user_id = db.Column(db.Integer, nullable=False)
|
||||
name = db.Column(db.String(40), unique=True, nullable=False)
|
||||
name = db.Column(db.String(40), nullable=False)
|
||||
is_active = db.Column(db.Boolean, default=False)
|
||||
|
||||
@classmethod
|
||||
def name_exists_for_owner(cls, owner_user_id, name, exclude_id=None):
|
||||
query = cls.query.filter(
|
||||
cls.owner_user_id == owner_user_id,
|
||||
func.lower(cls.name) == name.strip().lower(),
|
||||
)
|
||||
if exclude_id is not None:
|
||||
query = query.filter(cls.id != exclude_id)
|
||||
return query.first() is not None
|
||||
|
||||
def as_dict(self):
|
||||
result = {}
|
||||
for p in ['id','name','owner_user_id','is_active']:
|
||||
|
||||
Reference in New Issue
Block a user