better excel export
This commit is contained in:
+25
-7
@@ -42,6 +42,7 @@ import Web.modules.database.termine as termin
|
||||
import Web.modules.log.audit_log as al
|
||||
import push_notifications as pn
|
||||
import Web.modules.inventarsystem.pdf_export as pdf_export
|
||||
import Web.modules.inventarsystem.excel_export as excel_export
|
||||
import datetime
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from bson.objectid import ObjectId
|
||||
@@ -2979,33 +2980,50 @@ def library_export_excel(scope='all'):
|
||||
username = session['username']
|
||||
is_admin_user = us.check_admin(username)
|
||||
|
||||
import Web.modules.inventarsystem.excel_export as excel_export
|
||||
client = MongoClient(MONGODB_HOST, MONGODB_PORT)
|
||||
db = client[cfg.MONGODB_DB]
|
||||
items_collection = db['items']
|
||||
|
||||
query = {'ItemType': {'$in': LIBRARY_ITEM_TYPES}, 'Deleted': {'$ne': True}}
|
||||
# Base query
|
||||
query = {
|
||||
'ItemType': {'$in': LIBRARY_ITEM_TYPES},
|
||||
'Deleted': {'$ne': True}
|
||||
}
|
||||
|
||||
# Scope modifications
|
||||
if scope == 'borrowed_by_me':
|
||||
query['User'] = username
|
||||
query['Verfuegbar'] = False
|
||||
filename = f"Bibliothek_Ausgeliehen_{username}.xlsx"
|
||||
|
||||
elif scope == 'all_borrowed':
|
||||
if not is_admin_user:
|
||||
# Consider adding a flash message here before redirecting
|
||||
return redirect('/library')
|
||||
query['Verfuegbar'] = False
|
||||
filename = "Bibliothek_Alle_Ausleihen.xlsx"
|
||||
|
||||
elif scope == 'schulbuecher':
|
||||
# Overwrites the base $in query, which is fine
|
||||
query['ItemType'] = 'schulbuch'
|
||||
filename = "Schulbuecher_Bestand.xlsx"
|
||||
|
||||
elif scope == 'all_books':
|
||||
# FIX: Keep the library item types restriction, but exclude 'general'
|
||||
query['ItemType'] = {'$in': [t for t in LIBRARY_ITEM_TYPES if t != 'general']}
|
||||
filename = "Bibliothek_Buecher.xlsx"
|
||||
|
||||
else:
|
||||
# 'all'
|
||||
# 'all' scope
|
||||
filename = "Bibliothek_Gesamtbestand.xlsx"
|
||||
|
||||
# Database interaction
|
||||
client = MongoClient(MONGODB_HOST, MONGODB_PORT)
|
||||
db = client[cfg.MONGODB_DB]
|
||||
items_collection = db['items']
|
||||
|
||||
items = list(items_collection.find(query))
|
||||
client.close()
|
||||
|
||||
# Generate and send file
|
||||
excel_file = excel_export.generate_library_excel(items)
|
||||
|
||||
return send_file(
|
||||
excel_file,
|
||||
mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
|
||||
@@ -503,6 +503,10 @@
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="8" y1="13" x2="16" y2="13"></line><line x1="8" y1="17" x2="16" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg>
|
||||
Alle ausgeliehen Excel
|
||||
</button>
|
||||
<button class="button" style="background: #10b981; color: white; display: flex; align-items: center; gap: 0.5rem;" onclick="window.location.href='/library/export/all_books'">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="8" y1="13" x2="16" y2="13"></line><line x1="8" y1="17" x2="16" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg>
|
||||
Alle Bücher Excel
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user