Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
from flask import render_template, request, redirect, url_for, flash, jsonify, current_app
|
|
|
|
|
from . import admin_bp
|
|
|
|
|
from app.models import TenantModel, ProductModel, ARFieldModel
|
|
|
|
|
from app.services import ProductService
|
2025-05-14 15:30:27 -04:00
|
|
|
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
@admin_bp.route('/add', methods=['GET', 'POST'])
|
2025-06-19 14:25:42 -04:00
|
|
|
def add_product(tenant_id):
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
"""Add a new product"""
|
|
|
|
|
custom_fields = ARFieldModel.get_all(tenant_id)
|
|
|
|
|
|
2025-05-14 15:30:27 -04:00
|
|
|
if request.method == 'POST':
|
|
|
|
|
product_id = request.form.get('product_id')
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
if not product_id:
|
|
|
|
|
flash('Product ID is required.')
|
|
|
|
|
return render_template('admin/add_product.html', tenant_id=tenant_id, custom_fields=custom_fields)
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-05-14 15:30:27 -04:00
|
|
|
# Check if product ID already exists
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
products = ProductModel.get_all(tenant_id)
|
2025-05-14 15:30:27 -04:00
|
|
|
if product_id in products:
|
|
|
|
|
flash('Product ID already exists.')
|
2025-06-19 15:46:22 -04:00
|
|
|
return render_template('admin/add_product.html', tenant_id=tenant_id, custom_fields=custom_fields)
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
# Handle backward compatibility image upload
|
2025-06-19 11:57:47 -04:00
|
|
|
image_data = None
|
|
|
|
|
image_mime_type = None
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
# Create product data structure based on custom fields
|
|
|
|
|
product_data = []
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
# Always include _id field
|
|
|
|
|
product_data.append({
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
"fieldName": "_id",
|
|
|
|
|
"label": "Item ID",
|
|
|
|
|
"value": product_id,
|
|
|
|
|
"editable": "false",
|
2025-06-19 15:46:22 -04:00
|
|
|
"fieldType": "TEXT"
|
|
|
|
|
})
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
# Process images after product is saved
|
|
|
|
|
images_to_save = []
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
# Add other fields based on custom configuration
|
|
|
|
|
for field in custom_fields:
|
|
|
|
|
field_name = field['fieldName']
|
|
|
|
|
if field_name == '_id':
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if field['fieldType'] == 'IMAGE_URI':
|
2025-06-19 15:46:22 -04:00
|
|
|
image_field_name = f'image_{field_name}'
|
|
|
|
|
if image_field_name in request.files:
|
|
|
|
|
file = request.files[image_field_name]
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
allowed_extensions = current_app.config['ALLOWED_EXTENSIONS']
|
|
|
|
|
if file and file.filename and ProductService.allowed_file(file.filename, allowed_extensions):
|
2025-06-19 15:46:22 -04:00
|
|
|
file.seek(0)
|
|
|
|
|
img_data = file.read()
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
extension = file.filename.rsplit('.', 1)[1].lower()
|
|
|
|
|
mime_types = {
|
|
|
|
|
'jpg': 'image/jpeg',
|
|
|
|
|
'jpeg': 'image/jpeg',
|
|
|
|
|
'png': 'image/png',
|
|
|
|
|
'gif': 'image/gif'
|
|
|
|
|
}
|
|
|
|
|
mime_type = mime_types.get(extension, 'image/jpeg')
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
images_to_save.append({
|
|
|
|
|
'field_name': field_name,
|
|
|
|
|
'data': img_data,
|
|
|
|
|
'mime_type': mime_type
|
|
|
|
|
})
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-10-20 16:45:58 -04:00
|
|
|
field_suffix = field_name[1:] if field_name.startswith('_') else field_name
|
|
|
|
|
image_path = f"/images/{product_id}_{field_suffix}.{extension}"
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
if field_name == '_image':
|
|
|
|
|
image_data = img_data
|
|
|
|
|
image_mime_type = mime_type
|
|
|
|
|
else:
|
|
|
|
|
image_path = ""
|
|
|
|
|
else:
|
|
|
|
|
image_path = ""
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
product_data.append({
|
|
|
|
|
"fieldName": field_name,
|
|
|
|
|
"label": field['label'],
|
|
|
|
|
"value": image_path,
|
|
|
|
|
"editable": field['editable'],
|
|
|
|
|
"fieldType": field['fieldType']
|
|
|
|
|
})
|
|
|
|
|
else:
|
|
|
|
|
value = request.form.get(f'field_{field_name}', '')
|
|
|
|
|
product_data.append({
|
|
|
|
|
"fieldName": field_name,
|
|
|
|
|
"label": field['label'],
|
|
|
|
|
"value": value,
|
|
|
|
|
"editable": field['editable'],
|
|
|
|
|
"fieldType": field['fieldType']
|
|
|
|
|
})
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
|
|
|
|
# Handle backward compatibility fields
|
2025-06-19 15:46:22 -04:00
|
|
|
if '_name' not in [f['fieldName'] for f in custom_fields]:
|
|
|
|
|
name = request.form.get('name', '')
|
|
|
|
|
if name:
|
|
|
|
|
product_data.append({
|
|
|
|
|
"fieldName": "_name",
|
|
|
|
|
"label": "Product Name",
|
|
|
|
|
"value": name,
|
|
|
|
|
"editable": "true",
|
|
|
|
|
"fieldType": "TEXT"
|
|
|
|
|
})
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
if '_price' not in [f['fieldName'] for f in custom_fields]:
|
|
|
|
|
price = request.form.get('price', '')
|
|
|
|
|
if price:
|
|
|
|
|
product_data.append({
|
|
|
|
|
"fieldName": "_price",
|
|
|
|
|
"label": "Sale Price",
|
|
|
|
|
"value": f"${price}",
|
|
|
|
|
"editable": "true",
|
|
|
|
|
"fieldType": "TEXT"
|
|
|
|
|
})
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 11:57:47 -04:00
|
|
|
# Save to database
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
ProductModel.save(product_id, tenant_id, product_data, image_data, image_mime_type)
|
|
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
# Save additional images
|
|
|
|
|
for img in images_to_save:
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
ProductModel.save_image(product_id, tenant_id, img['field_name'], img['data'], img['mime_type'])
|
|
|
|
|
|
2025-05-14 15:30:27 -04:00
|
|
|
flash('Product added successfully!')
|
2025-10-20 17:11:26 -04:00
|
|
|
return redirect(f'/{tenant_id}/')
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
return render_template('admin/add_product.html', tenant_id=tenant_id, custom_fields=custom_fields)
|
2025-05-14 15:30:27 -04:00
|
|
|
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
@admin_bp.route('/edit/<product_id>', methods=['GET', 'POST'])
|
2025-06-19 14:25:42 -04:00
|
|
|
def edit_product(tenant_id, product_id):
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
"""Edit an existing product"""
|
|
|
|
|
products = ProductModel.get_all(tenant_id)
|
|
|
|
|
custom_fields = ARFieldModel.get_all(tenant_id)
|
2025-10-20 17:11:26 -04:00
|
|
|
|
2025-05-14 15:30:27 -04:00
|
|
|
if product_id not in products:
|
|
|
|
|
flash('Product not found.')
|
2025-10-20 17:11:26 -04:00
|
|
|
return redirect(f'/{tenant_id}/')
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-05-14 15:30:27 -04:00
|
|
|
if request.method == 'POST':
|
2025-06-19 15:46:22 -04:00
|
|
|
image_data = None
|
|
|
|
|
image_mime_type = None
|
|
|
|
|
images_to_save = []
|
2025-10-20 17:11:26 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
# Update fields based on form data
|
|
|
|
|
updated_product = []
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
# Always include _id field
|
|
|
|
|
for field in products[product_id]:
|
|
|
|
|
if field["fieldName"] == "_id":
|
|
|
|
|
updated_product.append(field)
|
|
|
|
|
break
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
# Process each custom field
|
|
|
|
|
for custom_field in custom_fields:
|
|
|
|
|
field_name = custom_field['fieldName']
|
|
|
|
|
if field_name == '_id':
|
|
|
|
|
continue
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
# Find existing field data
|
|
|
|
|
existing_field = None
|
|
|
|
|
for field in products[product_id]:
|
|
|
|
|
if field["fieldName"] == field_name:
|
|
|
|
|
existing_field = field.copy()
|
|
|
|
|
break
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
if not existing_field:
|
|
|
|
|
existing_field = {
|
|
|
|
|
"fieldName": field_name,
|
|
|
|
|
"label": custom_field['label'],
|
|
|
|
|
"value": "",
|
|
|
|
|
"editable": custom_field['editable'],
|
|
|
|
|
"fieldType": custom_field['fieldType']
|
2025-06-19 11:57:47 -04:00
|
|
|
}
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
if custom_field['fieldType'] == 'IMAGE_URI':
|
|
|
|
|
image_field_name = f'image_{field_name}'
|
|
|
|
|
if image_field_name in request.files and request.files[image_field_name].filename:
|
|
|
|
|
file = request.files[image_field_name]
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
allowed_extensions = current_app.config['ALLOWED_EXTENSIONS']
|
|
|
|
|
if ProductService.allowed_file(file.filename, allowed_extensions):
|
2025-06-19 15:46:22 -04:00
|
|
|
file.seek(0)
|
|
|
|
|
img_data = file.read()
|
2025-10-20 16:45:58 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
extension = file.filename.rsplit('.', 1)[1].lower()
|
|
|
|
|
mime_types = {
|
|
|
|
|
'jpg': 'image/jpeg',
|
|
|
|
|
'jpeg': 'image/jpeg',
|
|
|
|
|
'png': 'image/png',
|
|
|
|
|
'gif': 'image/gif'
|
|
|
|
|
}
|
|
|
|
|
mime_type = mime_types.get(extension, 'image/jpeg')
|
2025-10-20 16:45:58 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
images_to_save.append({
|
|
|
|
|
'field_name': field_name,
|
|
|
|
|
'data': img_data,
|
|
|
|
|
'mime_type': mime_type
|
|
|
|
|
})
|
2025-10-20 16:45:58 -04:00
|
|
|
|
|
|
|
|
field_suffix = field_name[1:] if field_name.startswith('_') else field_name
|
|
|
|
|
existing_field["value"] = f"/images/{product_id}_{field_suffix}.{extension}"
|
|
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
if field_name == '_image':
|
|
|
|
|
image_data = img_data
|
|
|
|
|
image_mime_type = mime_type
|
|
|
|
|
else:
|
|
|
|
|
value = request.form.get(f'field_{field_name}', '')
|
|
|
|
|
if field_name == '_price' and value and not value.startswith('$'):
|
|
|
|
|
value = f"${value}"
|
|
|
|
|
existing_field["value"] = value
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
updated_product.append(existing_field)
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
# Handle backward compatibility fields
|
|
|
|
|
if '_name' not in [f['fieldName'] for f in custom_fields]:
|
|
|
|
|
name = request.form.get('name', '')
|
|
|
|
|
if name:
|
|
|
|
|
for field in products[product_id]:
|
|
|
|
|
if field["fieldName"] == "_name":
|
|
|
|
|
field["value"] = name
|
|
|
|
|
updated_product.append(field)
|
|
|
|
|
break
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
if '_price' not in [f['fieldName'] for f in custom_fields]:
|
|
|
|
|
price = request.form.get('price', '')
|
|
|
|
|
if price:
|
2025-05-14 15:30:27 -04:00
|
|
|
for field in products[product_id]:
|
2025-06-19 15:46:22 -04:00
|
|
|
if field["fieldName"] == "_price":
|
|
|
|
|
field["value"] = f"${price}"
|
|
|
|
|
updated_product.append(field)
|
|
|
|
|
break
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 11:57:47 -04:00
|
|
|
# Save to database
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
ProductModel.save(product_id, tenant_id, updated_product, image_data, image_mime_type)
|
|
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
# Save additional images
|
|
|
|
|
for img in images_to_save:
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
ProductModel.save_image(product_id, tenant_id, img['field_name'], img['data'], img['mime_type'])
|
|
|
|
|
|
2025-05-14 15:30:27 -04:00
|
|
|
flash('Product updated successfully!')
|
2025-10-20 17:11:26 -04:00
|
|
|
return redirect(f'/{tenant_id}/')
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
|
|
|
|
return render_template('admin/edit_product.html',
|
|
|
|
|
product_id=product_id,
|
|
|
|
|
product=products[product_id],
|
2025-06-19 15:46:22 -04:00
|
|
|
tenant_id=tenant_id,
|
|
|
|
|
custom_fields=custom_fields)
|
2025-05-14 15:30:27 -04:00
|
|
|
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
@admin_bp.route('/delete/<product_id>', methods=['POST'])
|
2025-06-19 14:25:42 -04:00
|
|
|
def delete_product(tenant_id, product_id):
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
"""Delete a product"""
|
|
|
|
|
products = ProductModel.get_all(tenant_id)
|
2025-10-20 17:11:26 -04:00
|
|
|
|
2025-05-14 15:30:27 -04:00
|
|
|
if product_id not in products:
|
|
|
|
|
flash('Product not found.')
|
2025-10-20 17:11:26 -04:00
|
|
|
return redirect(f'/{tenant_id}/')
|
|
|
|
|
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
ProductModel.delete(product_id, tenant_id)
|
2025-05-14 15:30:27 -04:00
|
|
|
flash('Product deleted successfully!')
|
2025-10-20 17:11:26 -04:00
|
|
|
return redirect(f'/{tenant_id}/')
|
2025-05-14 15:30:27 -04:00
|
|
|
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
@admin_bp.route('/generate_barcode/<product_id>/<code_type>')
|
2025-06-19 14:25:42 -04:00
|
|
|
def generate_barcode(tenant_id, product_id, code_type):
|
2025-06-19 11:57:47 -04:00
|
|
|
"""Redirect to the main barcode generation endpoint"""
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
products = ProductModel.get_all(tenant_id)
|
2025-05-14 15:30:27 -04:00
|
|
|
if product_id not in products:
|
|
|
|
|
return jsonify({"error": "Product not found"}), 404
|
2025-10-20 17:56:52 -04:00
|
|
|
|
2025-06-19 11:57:47 -04:00
|
|
|
type_mapping = {
|
|
|
|
|
'qrcode': 'qr',
|
|
|
|
|
'ean13': 'ean13',
|
|
|
|
|
'code128': 'code128'
|
|
|
|
|
}
|
2025-10-20 17:56:52 -04:00
|
|
|
|
2025-06-19 11:57:47 -04:00
|
|
|
barcode_type = type_mapping.get(code_type, code_type)
|
2025-06-19 14:25:42 -04:00
|
|
|
return redirect(f'/{tenant_id}/barcodes/{product_id}_{barcode_type}.png')
|
2025-05-14 15:30:27 -04:00
|
|
|
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
@admin_bp.route('/barcodes', methods=['GET'])
|
2025-10-20 17:56:52 -04:00
|
|
|
def view_all_barcodes(tenant_id):
|
|
|
|
|
"""Display all product barcodes for printing"""
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
products = ProductModel.get_all(tenant_id)
|
|
|
|
|
tenant = TenantModel.get_or_create(tenant_id)
|
2025-10-20 17:56:52 -04:00
|
|
|
|
|
|
|
|
barcode_type = tenant.get('barcode_type', 'qr')
|
|
|
|
|
|
|
|
|
|
return render_template('admin/all_barcodes.html',
|
|
|
|
|
products=products,
|
|
|
|
|
tenant=tenant,
|
|
|
|
|
barcode_type=barcode_type)
|
|
|
|
|
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
@admin_bp.route('/ar_fields', methods=['GET', 'POST'])
|
2025-06-19 15:46:22 -04:00
|
|
|
def manage_ar_fields(tenant_id):
|
|
|
|
|
"""Manage custom AR content fields"""
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
tenant = TenantModel.get_or_create(tenant_id)
|
|
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
if request.method == 'POST':
|
|
|
|
|
action = request.form.get('action')
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
if action == 'add':
|
|
|
|
|
field_data = {
|
|
|
|
|
'fieldName': request.form.get('fieldName'),
|
|
|
|
|
'label': request.form.get('label'),
|
|
|
|
|
'fieldType': request.form.get('fieldType'),
|
|
|
|
|
'editable': request.form.get('editable', 'true'),
|
|
|
|
|
'displayOrder': int(request.form.get('displayOrder', 0))
|
|
|
|
|
}
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
if field_data['fieldName'] and field_data['label']:
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
ARFieldModel.save(tenant_id, field_data)
|
2025-06-19 15:46:22 -04:00
|
|
|
flash('Custom field added successfully!')
|
|
|
|
|
else:
|
|
|
|
|
flash('Field name and label are required.')
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
elif action == 'delete':
|
|
|
|
|
field_id = request.form.get('field_id')
|
|
|
|
|
if field_id:
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
ARFieldModel.delete(tenant_id, int(field_id))
|
2025-06-19 15:46:22 -04:00
|
|
|
flash('Custom field deleted successfully!')
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
elif action == 'update':
|
|
|
|
|
field_data = {
|
|
|
|
|
'id': int(request.form.get('field_id')),
|
|
|
|
|
'fieldName': request.form.get('fieldName'),
|
|
|
|
|
'label': request.form.get('label'),
|
|
|
|
|
'fieldType': request.form.get('fieldType'),
|
|
|
|
|
'editable': request.form.get('editable', 'true'),
|
|
|
|
|
'displayOrder': int(request.form.get('displayOrder', 0))
|
|
|
|
|
}
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
if field_data['fieldName'] and field_data['label']:
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
ARFieldModel.save(tenant_id, field_data)
|
2025-06-19 15:46:22 -04:00
|
|
|
flash('Custom field updated successfully!')
|
|
|
|
|
else:
|
|
|
|
|
flash('Field name and label are required.')
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
return redirect(url_for('admin.manage_ar_fields', tenant_id=tenant_id))
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
# Get existing custom fields
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
custom_fields = ARFieldModel.get_all(tenant_id)
|
|
|
|
|
|
2025-06-19 15:46:22 -04:00
|
|
|
# Available field types
|
|
|
|
|
field_types = [
|
|
|
|
|
'TEXT',
|
|
|
|
|
'IMAGE_URI'
|
|
|
|
|
]
|
Refactor application to MVC architecture with Flask blueprints
Major architectural refactoring to improve code organization, maintainability, and scalability:
- Implement MVC pattern with clear separation of concerns
- Organize code into blueprints for different functional areas (main, tenant, admin, api)
- Create models layer to encapsulate all database operations
- Create services layer for business logic (auth, product, barcode)
- Implement application factory pattern for better testability
- Add environment-based configuration management
- Remove old monolithic app.py and consolidate routes
New structure:
- app/models/ - Database operations (Tenant, Product, ARField, Settings)
- app/services/ - Business logic (Auth, Product, Barcode services)
- app/blueprints/ - Controllers organized by function
- app/config.py - Environment configurations
- run.py - Application entry point
All routes remain backward compatible. No changes to API or templates functionality.
2025-10-20 18:11:16 -04:00
|
|
|
|
|
|
|
|
return render_template('admin/ar_fields.html',
|
|
|
|
|
tenant=tenant,
|
2025-06-19 15:46:22 -04:00
|
|
|
tenant_id=tenant_id,
|
|
|
|
|
custom_fields=custom_fields,
|
|
|
|
|
field_types=field_types)
|