Apr 06 2026: enhanced - update the dynamic QR code
This commit is contained in:
+2
-2
@@ -14,11 +14,11 @@ def set_db(database):
|
||||
|
||||
# Now import all models (they will use base.db)
|
||||
from .user import User
|
||||
from .qrcode import QRCode, QRCodeStyle
|
||||
from .qrcode import QRCode, QRCodeStyle, QRCodeLocation # ADDED: QRCodeLocation
|
||||
from .project import Project
|
||||
from .attendance import AttendanceData
|
||||
from .employee import Employee
|
||||
from .time_attendance import TimeAttendance
|
||||
from .permissions import UserProjectPermission, UserLocationPermission
|
||||
|
||||
return User, QRCode, QRCodeStyle, Project, AttendanceData, Employee, TimeAttendance, UserProjectPermission, UserLocationPermission
|
||||
return User, QRCode, QRCodeStyle, QRCodeLocation, Project, AttendanceData, Employee, TimeAttendance, UserProjectPermission, UserLocationPermission
|
||||
|
||||
@@ -33,6 +33,8 @@ class AttendanceData(base.db.Model):
|
||||
altitude = base.db.Column(base.db.Float, nullable=True)
|
||||
location_source = base.db.Column(base.db.String(50), default='manual')
|
||||
address = base.db.Column(base.db.String(500), nullable=True)
|
||||
# Stores the QR-side address for dynamic QR check-ins (overrides qr_codes.location_address join)
|
||||
qr_address = base.db.Column(base.db.Text, nullable=True)
|
||||
verification_photo = base.db.Column(base.db.Text, nullable=True) # Base64 encoded image
|
||||
verification_required = base.db.Column(base.db.Boolean, default=False)
|
||||
verification_status = base.db.Column(base.db.String(20), nullable=True) # 'pending', 'approved', 'rejected'
|
||||
|
||||
+41
-6
@@ -1,6 +1,6 @@
|
||||
"""
|
||||
QRCode and QRCodeStyle Models for QR Attendance Management System
|
||||
================================================================
|
||||
QRCode, QRCodeStyle, and QRCodeLocation Models for QR Attendance Management System
|
||||
===================================================================================
|
||||
|
||||
QRCode models to manage QR code records and metadata with customization options.
|
||||
Extracted from app.py for better code organization.
|
||||
@@ -17,8 +17,9 @@ class QRCode(base.db.Model):
|
||||
|
||||
id = base.db.Column(base.db.Integer, primary_key=True)
|
||||
name = base.db.Column(base.db.String(100), nullable=False)
|
||||
location = base.db.Column(base.db.String(100), nullable=False)
|
||||
location_address = base.db.Column(base.db.Text, nullable=False)
|
||||
# nullable=True for dynamic QR codes which have no single fixed location/address
|
||||
location = base.db.Column(base.db.String(100), nullable=True)
|
||||
location_address = base.db.Column(base.db.Text, nullable=True)
|
||||
location_event = base.db.Column(base.db.String(200), nullable=False)
|
||||
qr_code_image = base.db.Column(base.db.Text, nullable=False) # Base64 encoded image
|
||||
created_by = base.db.Column(base.db.Integer, base.db.ForeignKey('users.id'), nullable=True)
|
||||
@@ -38,7 +39,11 @@ class QRCode(base.db.Model):
|
||||
border = base.db.Column(base.db.Integer, default=4)
|
||||
error_correction = base.db.Column(base.db.String(1), default='L')
|
||||
style_id = base.db.Column(base.db.Integer, base.db.ForeignKey('qr_code_styles.id'), nullable=True)
|
||||
|
||||
# --- ADDED: QR Code Type ---
|
||||
# 'standard' = fixed single location (existing behavior, default)
|
||||
# 'dynamic' = employee selects location from a list at scan time
|
||||
qr_type = base.db.Column(base.db.String(20), nullable=False, default='standard')
|
||||
|
||||
# Relationship to style
|
||||
style = base.db.relationship('QRCodeStyle', backref='qr_codes')
|
||||
|
||||
@@ -78,4 +83,34 @@ class QRCodeStyle(base.db.Model):
|
||||
created_by = base.db.Column(base.db.Integer, base.db.ForeignKey('users.id'))
|
||||
|
||||
def __repr__(self):
|
||||
return f'<QRCodeStyle {self.name}>'
|
||||
return f'<QRCodeStyle {self.name}>'
|
||||
|
||||
|
||||
# --- ADDED: QRCodeLocation model ---
|
||||
class QRCodeLocation(base.db.Model):
|
||||
"""
|
||||
Selectable locations for dynamic QR codes.
|
||||
Each record represents one location option displayed to the employee at scan time.
|
||||
Only relevant when the parent QRCode.qr_type == 'dynamic'.
|
||||
"""
|
||||
__tablename__ = 'qr_code_locations'
|
||||
|
||||
id = base.db.Column(base.db.Integer, primary_key=True)
|
||||
qr_code_id = base.db.Column(
|
||||
base.db.Integer,
|
||||
base.db.ForeignKey('qr_codes.id', ondelete='CASCADE'),
|
||||
nullable=False
|
||||
)
|
||||
location_name = base.db.Column(base.db.String(100), nullable=False)
|
||||
location_address = base.db.Column(base.db.Text, nullable=True)
|
||||
address_latitude = base.db.Column(base.db.Float, nullable=True)
|
||||
address_longitude = base.db.Column(base.db.Float, nullable=True)
|
||||
sort_order = base.db.Column(base.db.Integer, default=0, nullable=False)
|
||||
active_status = base.db.Column(base.db.Boolean, default=True, nullable=False)
|
||||
created_date = base.db.Column(base.db.DateTime, default=datetime.utcnow)
|
||||
|
||||
# Back-reference: qr_code_instance.locations → list of QRCodeLocation rows
|
||||
qr_code = base.db.relationship('QRCode', backref='locations')
|
||||
|
||||
def __repr__(self):
|
||||
return f'<QRCodeLocation "{self.location_name}" (QR #{self.qr_code_id})>'
|
||||
|
||||
Reference in New Issue
Block a user