consider to get rid of dataclass dependent
This commit is contained in:
parent
37ca4eaf20
commit
d42eea39cc
|
@ -1,6 +1,3 @@
|
||||||
from dataclasses import dataclass
|
|
||||||
|
|
||||||
import arrow
|
|
||||||
from flask import render_template, flash, redirect, url_for, abort
|
from flask import render_template, flash, redirect, url_for, abort
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
|
|
||||||
|
@ -8,20 +5,25 @@ from app.dashboard.base import dashboard_bp
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.models import GenEmail, ForwardEmailLog, ForwardEmail
|
from app.models import GenEmail, ForwardEmailLog, ForwardEmail
|
||||||
|
|
||||||
LIMIT = 3
|
LIMIT = 15
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class AliasLog:
|
class AliasLog:
|
||||||
website_email: str
|
__slots__ = [
|
||||||
website_from: str
|
"website_email",
|
||||||
alias: str
|
"website_from",
|
||||||
when: arrow.Arrow
|
"alias",
|
||||||
is_reply: bool
|
"when",
|
||||||
blocked: bool
|
"is_reply",
|
||||||
|
"blocked",
|
||||||
|
] # memory efficiency
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
for k, v in kwargs.items():
|
||||||
|
setattr(self, k, v)
|
||||||
|
|
||||||
|
|
||||||
@dashboard_bp.route("/alias_log/<alias>", methods=["GET"], defaults={'page_id': 0})
|
@dashboard_bp.route("/alias_log/<alias>", methods=["GET"], defaults={"page_id": 0})
|
||||||
@dashboard_bp.route("/alias_log/<alias>/<int:page_id>")
|
@dashboard_bp.route("/alias_log/<alias>/<int:page_id>")
|
||||||
@login_required
|
@login_required
|
||||||
def alias_log(alias, page_id):
|
def alias_log(alias, page_id):
|
||||||
|
@ -39,9 +41,7 @@ def alias_log(alias, page_id):
|
||||||
logs = get_alias_log(gen_email, page_id)
|
logs = get_alias_log(gen_email, page_id)
|
||||||
last_page = len(logs) < LIMIT # lightweight pagination without counting all objects
|
last_page = len(logs) < LIMIT # lightweight pagination without counting all objects
|
||||||
|
|
||||||
return render_template(
|
return render_template("dashboard/alias_log.html", **locals())
|
||||||
"dashboard/alias_log.html", **locals()
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def get_alias_log(gen_email: GenEmail, page_id=0):
|
def get_alias_log(gen_email: GenEmail, page_id=0):
|
||||||
|
@ -49,10 +49,10 @@ def get_alias_log(gen_email: GenEmail, page_id=0):
|
||||||
|
|
||||||
q = (
|
q = (
|
||||||
db.session.query(ForwardEmail, ForwardEmailLog)
|
db.session.query(ForwardEmail, ForwardEmailLog)
|
||||||
.filter(ForwardEmail.id == ForwardEmailLog.forward_id)
|
.filter(ForwardEmail.id == ForwardEmailLog.forward_id)
|
||||||
.filter(ForwardEmail.gen_email_id == gen_email.id)
|
.filter(ForwardEmail.gen_email_id == gen_email.id)
|
||||||
.limit(LIMIT)
|
.limit(LIMIT)
|
||||||
.offset(page_id * LIMIT)
|
.offset(page_id * LIMIT)
|
||||||
)
|
)
|
||||||
|
|
||||||
for fe, fel in q:
|
for fe, fel in q:
|
||||||
|
@ -65,7 +65,6 @@ def get_alias_log(gen_email: GenEmail, page_id=0):
|
||||||
blocked=fel.blocked,
|
blocked=fel.blocked,
|
||||||
)
|
)
|
||||||
logs.append(al)
|
logs.append(al)
|
||||||
|
|
||||||
logs = sorted(logs, key=lambda l: l.when, reverse=True)
|
logs = sorted(logs, key=lambda l: l.when, reverse=True)
|
||||||
|
|
||||||
return logs
|
return logs
|
||||||
|
|
Loading…
Reference in a new issue