From 11745f2eb8040df5deca2262e694c718a19bc20c Mon Sep 17 00:00:00 2001 From: Kobe Date: Mon, 2 Jun 2025 11:03:42 +0200 Subject: [PATCH] Better fill codes --- routes/__pycache__/main.cpython-313.pyc | Bin 72482 -> 72779 bytes routes/main.py | 65 +++++++++++------- templates/settings/tabs/mails.html | 33 +++++---- .../__pycache__/notification.cpython-313.pyc | Bin 8061 -> 11525 bytes utils/notification.py | 54 ++++++++++++++- 5 files changed, 112 insertions(+), 40 deletions(-) diff --git a/routes/__pycache__/main.cpython-313.pyc b/routes/__pycache__/main.cpython-313.pyc index 8f667688dd2937122e0b576ede8c1a346759078e..53c4394476a9334553c05ff8df58714fe8411179 100644 GIT binary patch delta 2854 zcmb7GYj9J?6~3#-)!TYlmL*%l4+$griEQwz24koL1Hmr7C?!>?<0p86WmwB3afUic zht~PgiIq)yF_Rcb6ClRKc9q5u2%$5b1csr5svlfbqZ z4R1Si46P^udj$ng5?%>*A=THwB()Z12LISmetfCi zotg&yXS_7{(=*PDEg;lDA!fKgz3#SPup_Xe+oQ!*GqH_w(KQ9_ZB2-kg}(V$N9y$g1fp3J#~AOxQK+VJF-fF10Gxq06&pOmDpx* ztbFxf$jZi9S5I(v zPY{oQM-x3k0>$|eK9*i14$DG+E(R4ipV z1^<-_t&%G_`AP{%7rv!afkkuZ7m$+K!ID%pr|}!&9){tx71Dr=(*@+DX>^G>!1@?> zBG#m57$4h^N@`w9CLjKVO=f+Phs4ZQPG5m&qVyrbWT%ufh*2~jeVxi8&RDsPVVW`- z#&0Fh$L!=rn>xqun4gx3ORhi#^uh-e^>vi4_}_FhmoiUxQ@Z7w^xOsNsSD^5j@Ixg z=BJmy{+#CJlR=aH<@c461}}-Y(xn=Iu^8+dH7hwAmsWui z0j*z6#>*VUaL`PaJ5{-yU0l&Jx?g4S$Yu#KHWD9`I6$L zY8REtD%6)E7vpi(;XLsOQ+b?Etr*)KYzp>t<1fH-8{iIrcqb+hnVz(4d>i3&le+k*xf-dsRv>4F5I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Xa9VC$vduP+7I6s?JkUT`9~b?Pk_8!Y=RbJ3lI5 zJJt>t!Xo@~colqvrh7+VCw_O&o*?zm0b(Cy5aeAAp85ulaELTgkP^UO24lP#BR-xV zt27S(Zj3rc1TO;{FKncJO3*m^0ywa6)Xt9?am{G)6OkJ1{-{y=6}kBc@&RA!G9}= z)Ob}FC$CeKD#Q(8V8P$6#Xt&n&(ulu)Sw=<$vT|zS0o04I(1o=BPv%`rydWnbu&d1 zuQA6Rrj{vD-7OY< zJm)aZVhPdbh|X16x$@aNR$6eVN*z_Fo#13D)t1b~!aX|BV%#ac+!0f%WpT_QnsO;p z^rT2rbJbSPW-e~D;hzUh_;tU+QtPZ<9mmGPoi3bYn+bCm1bMf|>1lA|&Hg#OpYHXM zSOAdx+IUOaN%icBkQfihS*qE;T9wF?TNN)2nD{Xk#@ zO*85A2tIME5^UE0BMMjPF1{f@pLj(HOBFsj$GQ7Be0*oRZ= start_date) if user_id: - query = query.filter(Mail.recipient == User.query.get(user_id).email) + query = query.filter_by(recipient=user_id) + if template_id: + query = query.filter_by(template_id=template_id) + if date_range: + if date_range == '24h': + cutoff = datetime.utcnow() - timedelta(hours=24) + elif date_range == '7d': + cutoff = datetime.utcnow() - timedelta(days=7) + elif date_range == '30d': + cutoff = datetime.utcnow() - timedelta(days=30) + else: + cutoff = None + if cutoff: + query = query.filter(Mail.created_at >= cutoff) - # Get total count for pagination - total_mails = query.count() - total_pages = (total_mails + per_page - 1) // per_page - - # Get paginated mails + # Get paginated results mails = query.order_by(Mail.created_at.desc()).paginate(page=page, per_page=per_page) + total_pages = mails.pages + current_page = mails.page - # Get all users for filter dropdown + # Get all users for the filter dropdown users = User.query.order_by(User.username).all() + # Get all email templates + email_templates = EmailTemplate.query.filter_by(is_active=True).all() + # Check if this is an AJAX request if request.headers.get('X-Requested-With') == 'XMLHttpRequest': return render_template('settings/tabs/mails.html', - mails=mails.items, + mails=mails, total_pages=total_pages, current_page=page, status=status, date_range=date_range, user_id=user_id, + template_id=template_id, users=users, + email_templates=email_templates, csrf_token=session.get('csrf_token')) # For full page requests, render the full settings page site_settings = SiteSettings.get_settings() + company_form = CompanySettingsForm() + return render_template('settings/settings.html', primary_color=site_settings.primary_color, secondary_color=site_settings.secondary_color, active_tab='mails', site_settings=site_settings, - mails=mails.items, + mails=mails, total_pages=total_pages, current_page=page, + status=status, + date_range=date_range, + user_id=user_id, + template_id=template_id, users=users, + email_templates=email_templates, + form=company_form, csrf_token=session.get('csrf_token')) @main_bp.route('/settings/mails/') diff --git a/templates/settings/tabs/mails.html b/templates/settings/tabs/mails.html index e4938c0..be013ae 100644 --- a/templates/settings/tabs/mails.html +++ b/templates/settings/tabs/mails.html @@ -1,4 +1,4 @@ -{% macro mails_tab(mails, csrf_token, users, total_pages, current_page) %} +{% macro mails_tab(mails, csrf_token, users, total_pages, current_page, email_templates, status='', date_range='7d', user_id='', template_id='') %}
@@ -6,20 +6,26 @@
+