change the general stats: display #alias, forward, reply, block

This commit is contained in:
Son NK 2020-04-27 09:30:08 +02:00
parent 23c17b8cff
commit 01cc07b9fe
2 changed files with 19 additions and 42 deletions

View file

@ -22,51 +22,35 @@
{% block default_content %}
<!-- Global Stats -->
<div class="row">
<div class="col-6 col-sm-4 col-lg-2">
<div class="col-6 col-sm-3">
<div class="card">
<div class="card-body p-3 text-center">
<div class="h1 m-0 mt-3">{{ stats.nb_alias }}</div>
<div class="text-muted mb-4">Aliases</div>
<div class="h1 m-0">{{ stats.nb_alias }}</div>
<div class="text-muted">Aliases</div>
</div>
</div>
</div>
<div class="col-6 col-sm-4 col-lg-2">
<div class="col-6 col-sm-3">
<div class="card">
<div class="card-body p-3 text-center">
<div class="h1 m-0 mt-3">{{ stats.nb_active_alias }}</div>
<div class="text-muted mb-4">Active Aliases</div>
<div class="h1 m-0">{{ stats.nb_forward }}</div>
<div class="text-muted">Forwards</div>
</div>
</div>
</div>
<div class="col-6 col-sm-4 col-lg-2">
<div class="col-6 col-sm-3">
<div class="card">
<div class="card-body p-3 text-center">
<div class="h1 m-0 mt-3">{{ stats.nb_forward }}</div>
<div class="text-muted mb-4">Forwards</div>
<div class="h1 m-0">{{ stats.nb_reply }}</div>
<div class="text-muted">Replies</div>
</div>
</div>
</div>
<div class="col-6 col-sm-4 col-lg-2">
<div class="col-6 col-sm-3">
<div class="card">
<div class="card-body p-3 text-center">
<div class="h1 m-0 mt-3">{{ stats.nb_reply }}</div>
<div class="text-muted mb-4">Replies</div>
</div>
</div>
</div>
<div class="col-6 col-sm-4 col-lg-2">
<div class="card">
<div class="card-body p-3 text-center">
<div class="h1 m-0 mt-3">{{ stats.nb_directory }}</div>
<div class="text-muted mb-4">Directories</div>
</div>
</div>
</div>
<div class="col-6 col-sm-4 col-lg-2">
<div class="card">
<div class="card-body p-3 text-center">
<div class="h1 m-0 mt-3">{{ stats.nb_domain }}</div>
<div class="text-muted mb-4">Domains</div>
<div class="h1 m-0">{{ stats.nb_block }}</div>
<div class="text-muted">Blocks</div>
</div>
</div>
</div>

View file

@ -24,33 +24,26 @@ from app.models import (
@dataclass
class Stats:
nb_alias: int
nb_active_alias: int
nb_forward: int
nb_reply: int
nb_domain: int
nb_directory: int
nb_block: int
def get_stats(user: User) -> Stats:
nb_alias = Alias.query.filter_by(user_id=user.id).count()
nb_active_alias = Alias.query.filter_by(user_id=user.id, enabled=True).count()
nb_forward = EmailLog.query.filter_by(
user_id=user.id, is_reply=False, blocked=False, bounced=False
).count()
nb_reply = EmailLog.query.filter_by(
user_id=user.id, is_reply=True, blocked=False, bounced=False
).count()
nb_domain = CustomDomain.query.filter_by(user_id=user.id).count()
nb_directory = Directory.query.filter_by(user_id=user.id).count()
nb_block = EmailLog.query.filter_by(
user_id=user.id, is_reply=False, blocked=True, bounced=False
).count()
data = locals()
# to keep only Stats field
data = {
k: v
for (k, v) in data.items()
if k in vars(Stats)["__dataclass_fields__"].keys()
}
return Stats(**data)
return Stats(
nb_alias=nb_alias, nb_forward=nb_forward, nb_reply=nb_reply, nb_block=nb_block
)
@dashboard_bp.route("/", methods=["GET", "POST"])