updated / print module / keypairing options
This commit is contained in:
@@ -19,7 +19,7 @@ from app.settings import (
|
||||
delete_user_handler,
|
||||
save_external_db_handler
|
||||
)
|
||||
from .print_module import get_unprinted_orders_data
|
||||
from .print_module import get_unprinted_orders_data, get_printed_orders_data
|
||||
from .access_control import (
|
||||
requires_role, superadmin_only, admin_plus, manager_plus,
|
||||
requires_quality_module, requires_warehouse_module, requires_labels_module,
|
||||
@@ -1933,10 +1933,11 @@ def print_module():
|
||||
|
||||
@bp.route('/print_lost_labels')
|
||||
def print_lost_labels():
|
||||
"""Print lost labels module"""
|
||||
"""Print lost labels module - shows orders with printed labels for reprinting"""
|
||||
try:
|
||||
# Get orders data for lost labels (could be different logic than print_module)
|
||||
orders_data = get_unprinted_orders_data(limit=100)
|
||||
# Get orders that have already been printed (printed_labels = 1)
|
||||
# Limited to 50 most recent orders for performance
|
||||
orders_data = get_printed_orders_data(limit=50)
|
||||
return render_template('print_lost_labels.html', orders=orders_data)
|
||||
except Exception as e:
|
||||
print(f"Error loading print lost labels data: {e}")
|
||||
@@ -1995,16 +1996,19 @@ import secrets
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
@bp.route('/generate_pairing_key', methods=['POST'])
|
||||
@superadmin_only
|
||||
def generate_pairing_key():
|
||||
"""Generate a secure pairing key for a printer and store it."""
|
||||
printer_name = request.form.get('printer_name', '').strip()
|
||||
validity_days = int(request.form.get('validity_days', 90)) # Default to 90 days
|
||||
|
||||
if not printer_name:
|
||||
flash('Printer name is required.', 'danger')
|
||||
return redirect(url_for('main.download_extension'))
|
||||
|
||||
# Generate a secure random key
|
||||
pairing_key = secrets.token_urlsafe(32)
|
||||
warranty_until = (datetime.utcnow() + timedelta(days=365)).strftime('%Y-%m-%d')
|
||||
warranty_until = (datetime.utcnow() + timedelta(days=validity_days)).strftime('%Y-%m-%d')
|
||||
|
||||
# Load existing keys
|
||||
keys_path = os.path.join(current_app.instance_path, 'pairing_keys.json')
|
||||
@@ -2021,13 +2025,16 @@ def generate_pairing_key():
|
||||
keys.append({
|
||||
'printer_name': printer_name,
|
||||
'pairing_key': pairing_key,
|
||||
'warranty_until': warranty_until
|
||||
'warranty_until': warranty_until,
|
||||
'validity_days': validity_days
|
||||
})
|
||||
|
||||
# Save updated keys
|
||||
with open(keys_path, 'w') as f:
|
||||
json.dump(keys, f, indent=2)
|
||||
|
||||
flash(f'Pairing key generated successfully for "{printer_name}" (valid for {validity_days} days).', 'success')
|
||||
|
||||
# Pass new key and all keys to template
|
||||
return render_template('download_extension.html',
|
||||
pairing_key=pairing_key,
|
||||
@@ -2035,6 +2042,42 @@ def generate_pairing_key():
|
||||
warranty_until=warranty_until,
|
||||
pairing_keys=keys)
|
||||
|
||||
@bp.route('/delete_pairing_key', methods=['POST'])
|
||||
@superadmin_only
|
||||
def delete_pairing_key():
|
||||
"""Delete a pairing key."""
|
||||
pairing_key = request.form.get('pairing_key', '').strip()
|
||||
|
||||
if not pairing_key:
|
||||
flash('Pairing key is required.', 'danger')
|
||||
return redirect(url_for('main.download_extension'))
|
||||
|
||||
# Load existing keys
|
||||
keys_path = os.path.join(current_app.instance_path, 'pairing_keys.json')
|
||||
try:
|
||||
if os.path.exists(keys_path):
|
||||
with open(keys_path, 'r') as f:
|
||||
keys = json.load(f)
|
||||
else:
|
||||
keys = []
|
||||
except Exception as e:
|
||||
flash('Error loading pairing keys.', 'danger')
|
||||
return redirect(url_for('main.download_extension'))
|
||||
|
||||
# Find and remove the key
|
||||
original_count = len(keys)
|
||||
keys = [k for k in keys if k['pairing_key'] != pairing_key]
|
||||
|
||||
if len(keys) < original_count:
|
||||
# Save updated keys
|
||||
with open(keys_path, 'w') as f:
|
||||
json.dump(keys, f, indent=2)
|
||||
flash('Pairing key deleted successfully.', 'success')
|
||||
else:
|
||||
flash('Pairing key not found.', 'warning')
|
||||
|
||||
return redirect(url_for('main.download_extension'))
|
||||
|
||||
@bp.route('/download_extension')
|
||||
@superadmin_only
|
||||
def download_extension():
|
||||
|
||||
Reference in New Issue
Block a user