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 Web.modules.log.audit_log as al
|
||||||
import push_notifications as pn
|
import push_notifications as pn
|
||||||
import Web.modules.inventarsystem.pdf_export as pdf_export
|
import Web.modules.inventarsystem.pdf_export as pdf_export
|
||||||
|
import Web.modules.inventarsystem.excel_export as excel_export
|
||||||
import datetime
|
import datetime
|
||||||
from apscheduler.schedulers.background import BackgroundScheduler
|
from apscheduler.schedulers.background import BackgroundScheduler
|
||||||
from bson.objectid import ObjectId
|
from bson.objectid import ObjectId
|
||||||
@@ -2979,33 +2980,50 @@ def library_export_excel(scope='all'):
|
|||||||
username = session['username']
|
username = session['username']
|
||||||
is_admin_user = us.check_admin(username)
|
is_admin_user = us.check_admin(username)
|
||||||
|
|
||||||
import Web.modules.inventarsystem.excel_export as excel_export
|
# Base query
|
||||||
client = MongoClient(MONGODB_HOST, MONGODB_PORT)
|
query = {
|
||||||
db = client[cfg.MONGODB_DB]
|
'ItemType': {'$in': LIBRARY_ITEM_TYPES},
|
||||||
items_collection = db['items']
|
'Deleted': {'$ne': True}
|
||||||
|
}
|
||||||
query = {'ItemType': {'$in': LIBRARY_ITEM_TYPES}, 'Deleted': {'$ne': True}}
|
|
||||||
|
|
||||||
|
# Scope modifications
|
||||||
if scope == 'borrowed_by_me':
|
if scope == 'borrowed_by_me':
|
||||||
query['User'] = username
|
query['User'] = username
|
||||||
query['Verfuegbar'] = False
|
query['Verfuegbar'] = False
|
||||||
filename = f"Bibliothek_Ausgeliehen_{username}.xlsx"
|
filename = f"Bibliothek_Ausgeliehen_{username}.xlsx"
|
||||||
|
|
||||||
elif scope == 'all_borrowed':
|
elif scope == 'all_borrowed':
|
||||||
if not is_admin_user:
|
if not is_admin_user:
|
||||||
|
# Consider adding a flash message here before redirecting
|
||||||
return redirect('/library')
|
return redirect('/library')
|
||||||
query['Verfuegbar'] = False
|
query['Verfuegbar'] = False
|
||||||
filename = "Bibliothek_Alle_Ausleihen.xlsx"
|
filename = "Bibliothek_Alle_Ausleihen.xlsx"
|
||||||
|
|
||||||
elif scope == 'schulbuecher':
|
elif scope == 'schulbuecher':
|
||||||
|
# Overwrites the base $in query, which is fine
|
||||||
query['ItemType'] = 'schulbuch'
|
query['ItemType'] = 'schulbuch'
|
||||||
filename = "Schulbuecher_Bestand.xlsx"
|
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:
|
else:
|
||||||
# 'all'
|
# 'all' scope
|
||||||
filename = "Bibliothek_Gesamtbestand.xlsx"
|
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))
|
items = list(items_collection.find(query))
|
||||||
client.close()
|
client.close()
|
||||||
|
|
||||||
|
# Generate and send file
|
||||||
excel_file = excel_export.generate_library_excel(items)
|
excel_file = excel_export.generate_library_excel(items)
|
||||||
|
|
||||||
return send_file(
|
return send_file(
|
||||||
excel_file,
|
excel_file,
|
||||||
mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
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>
|
<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
|
Alle ausgeliehen Excel
|
||||||
</button>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user