upfdated to ptint plugin

This commit is contained in:
2025-09-20 13:56:57 +03:00
parent c4d82e36f2
commit beeaa02c35
14 changed files with 1062 additions and 0 deletions

View File

@@ -932,6 +932,162 @@ def upload_data():
def print_module():
return render_template('print_module.html')
@bp.route('/download_extension')
def download_extension():
"""Route for downloading the Chrome extension"""
return render_template('download_extension.html')
@bp.route('/extension_files/<path:filename>')
def extension_files(filename):
"""Serve Chrome extension files for download"""
import os
from flask import send_from_directory, current_app
extension_dir = os.path.join(os.path.dirname(current_app.root_path), 'chrome_extension')
return send_from_directory(extension_dir, filename)
@bp.route('/create_extension_package', methods=['POST'])
def create_extension_package():
"""Create and serve ZIP package of Chrome extension"""
import os
import zipfile
from flask import current_app, jsonify, send_file
import tempfile
try:
# Use correct path to chrome_extension directory (it's in py_app, not py_app/app)
extension_dir = os.path.join(os.path.dirname(current_app.root_path), 'chrome_extension')
print(f"Looking for extension files in: {extension_dir}")
if not os.path.exists(extension_dir):
return jsonify({
'success': False,
'error': f'Extension directory not found: {extension_dir}'
}), 500
# List files in extension directory for debugging
all_files = []
for root, dirs, files in os.walk(extension_dir):
for file in files:
file_path = os.path.join(root, file)
all_files.append(file_path)
print(f"Found files: {all_files}")
# Create static directory if it doesn't exist
static_dir = os.path.join(current_app.root_path, 'static')
os.makedirs(static_dir, exist_ok=True)
zip_filename = 'quality_recticel_print_helper.zip'
zip_path = os.path.join(static_dir, zip_filename)
# Create ZIP file directly in static directory
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
files_added = 0
# Add all extension files to ZIP
for root, dirs, files in os.walk(extension_dir):
for file in files:
# Include all relevant files
if file.endswith(('.json', '.js', '.html', '.css', '.png', '.md', '.txt')):
file_path = os.path.join(root, file)
# Create relative path for archive
arcname = os.path.relpath(file_path, extension_dir)
print(f"Adding file: {file_path} as {arcname}")
zipf.write(file_path, arcname)
files_added += 1
# Add a README file with installation instructions
readme_content = """# Quality Recticel Print Helper Chrome Extension
## Installation Instructions:
1. Extract this ZIP file to a folder on your computer
2. Open Chrome and go to: chrome://extensions/
3. Enable "Developer mode" in the top right
4. Click "Load unpacked" and select the extracted folder
5. The extension icon 🖨️ should appear in your toolbar
## Usage:
1. Go to the Print Module in the Quality Recticel application
2. Select an order from the table
3. Click the "🖨️ Print Direct" button
4. The label will print automatically to your default printer
## Troubleshooting:
- Make sure your default printer is set up correctly
- Click the extension icon to test printer connection
- Check Chrome printer settings: chrome://settings/printing
For support, contact your system administrator.
"""
zipf.writestr('README.txt', readme_content)
files_added += 1
print(f"Total files added to ZIP: {files_added}")
# Verify ZIP was created and has content
if os.path.exists(zip_path):
zip_size = os.path.getsize(zip_path)
print(f"ZIP file created: {zip_path}, size: {zip_size} bytes")
if zip_size > 0:
return jsonify({
'success': True,
'download_url': f'/static/{zip_filename}',
'files_included': files_added,
'zip_size': zip_size
})
else:
return jsonify({
'success': False,
'error': 'ZIP file was created but is empty'
}), 500
else:
return jsonify({
'success': False,
'error': 'Failed to create ZIP file'
}), 500
except Exception as e:
print(f"Error creating extension package: {e}")
import traceback
traceback.print_exc()
return jsonify({
'success': False,
'error': str(e)
}), 500
@bp.route('/test_extension_files')
def test_extension_files():
"""Test route to check extension files"""
import os
from flask import current_app, jsonify
extension_dir = os.path.join(os.path.dirname(current_app.root_path), 'chrome_extension')
result = {
'extension_dir': extension_dir,
'dir_exists': os.path.exists(extension_dir),
'files': []
}
if os.path.exists(extension_dir):
for root, dirs, files in os.walk(extension_dir):
for file in files:
file_path = os.path.join(root, file)
file_size = os.path.getsize(file_path)
result['files'].append({
'path': file_path,
'relative_path': os.path.relpath(file_path, extension_dir),
'size': file_size
})
return jsonify(result)
@bp.route('/label_templates')
def label_templates():
return render_template('label_templates.html')