Spaces:
Runtime error
Runtime error
Download app/models/document.py from lmends/MoneyCouple: direct link, hf CLI and curl.
- Browser
- Download file 3.56 kB
-
https://huggingface.co/spaces/lmends/MoneyCouple/resolve/main/app/models/document.py
- Command line
-
hf download hf://spaces/lmends/MoneyCouple/app/models/document.py
-
curl -L -o document.py https://huggingface.co/spaces/lmends/MoneyCouple/resolve/main/app/models/document.py
3.56 kB
| import uuid | |
| from datetime import datetime, timezone | |
| from app import db | |
| from app.services.crypto import encrypt, decrypt | |
| class Document(db.Model): | |
| """Insurance policies, contracts, and other important documents.""" | |
| __tablename__ = "documents" | |
| id = db.Column(db.String(36), primary_key=True, default=lambda: str(uuid.uuid4())) | |
| name = db.Column(db.String(150), nullable=False) | |
| doc_type = db.Column(db.String(30), nullable=False) # insurance | contract | warranty | other | |
| provider = db.Column(db.String(100), nullable=True) | |
| expiry_date = db.Column(db.Date, nullable=True) | |
| premium_amount = db.Column(db.Float, nullable=True) # monthly or annual cost | |
| premium_cycle = db.Column(db.String(10), default="monthly") # monthly | yearly | |
| notes = db.Column(db.Text, nullable=True) | |
| file_name = db.Column(db.String(255), nullable=True) | |
| file_data = db.Column(db.LargeBinary, nullable=True) | |
| file_mime = db.Column(db.String(100), nullable=True) | |
| color = db.Column(db.String(7), default="#6366f1") | |
| user_id = db.Column(db.String(36), db.ForeignKey("users.id"), nullable=False) | |
| couple_id = db.Column(db.String(36), db.ForeignKey("couples.id"), nullable=True) | |
| created_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc)) | |
| def to_dict(self): | |
| return { | |
| "id": self.id, | |
| "name": self.name, | |
| "doc_type": self.doc_type, | |
| "provider": self.provider, | |
| "expiry_date": self.expiry_date.isoformat() if self.expiry_date else None, | |
| "premium_amount": self.premium_amount, | |
| "premium_cycle": self.premium_cycle, | |
| "notes": self.notes, | |
| "has_file": self.file_data is not None, | |
| "file_name": self.file_name, | |
| "color": self.color, | |
| "user_id": self.user_id, | |
| "couple_id": self.couple_id, | |
| "created_at": self.created_at.isoformat(), | |
| } | |
| class VaultEntry(db.Model): | |
| """Highly encrypted entries for master passwords and emergency data.""" | |
| __tablename__ = "vault_entries" | |
| id = db.Column(db.String(36), primary_key=True, default=lambda: str(uuid.uuid4())) | |
| title_enc = db.Column(db.Text, nullable=False) | |
| content_enc = db.Column(db.Text, nullable=False) | |
| category = db.Column(db.String(30), default="password") # password | document | note | emergency | |
| user_id = db.Column(db.String(36), db.ForeignKey("users.id"), nullable=False) | |
| couple_id = db.Column(db.String(36), db.ForeignKey("couples.id"), nullable=True) | |
| created_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc)) | |
| updated_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc), | |
| onupdate=lambda: datetime.now(timezone.utc)) | |
| def title(self): | |
| return decrypt(self.title_enc) | |
| def title(self, value): | |
| self.title_enc = encrypt(value) | |
| def content(self): | |
| return decrypt(self.content_enc) | |
| def content(self, value): | |
| self.content_enc = encrypt(value) | |
| def to_dict(self, reveal=False): | |
| return { | |
| "id": self.id, | |
| "title": self.title, | |
| "content": self.content if reveal else "••••••••", | |
| "category": self.category, | |
| "user_id": self.user_id, | |
| "couple_id": self.couple_id, | |
| "created_at": self.created_at.isoformat(), | |
| "updated_at": self.updated_at.isoformat(), | |
| } | |