Compare commits
3 Commits
idhub
...
feature/bi
Author | SHA1 | Date |
---|---|---|
Santiago L | deec522dfb | |
Santiago L | 407abf79b8 | |
Santiago L | b06e863f91 |
|
@ -0,0 +1,38 @@
|
|||
{% extends "ereuse_devicehub/base_site.html" %}
|
||||
{% block main %}
|
||||
|
||||
<div class="pagetitle">
|
||||
<h1>Billing</h1>
|
||||
<nav>
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item active">{{ page_title }}</li>
|
||||
</ol>
|
||||
</nav>
|
||||
</div><!-- End Page Title -->
|
||||
|
||||
<section class="section">
|
||||
Current usage
|
||||
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Year</th>
|
||||
<th scope="col">Month</th>
|
||||
<th scope="col">Snapshot (register)</th>
|
||||
<th scope="col">Snapshot (update)</th>
|
||||
<th scope="col">Drives Erasure (uniques)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">{{ current_month_usage.year }}</th>
|
||||
<th scope="row">{{ current_month_usage.month }}</th>
|
||||
<td>{{ current_month_usage.snapshot_register }}</td>
|
||||
<td>{{ current_month_usage.snapshot_update }}</td>
|
||||
<td>{{ current_month_usage.drives_erasure }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</section>
|
||||
{% endblock main %}
|
|
@ -0,0 +1,60 @@
|
|||
import logging
|
||||
|
||||
import flask
|
||||
from flask import Blueprint
|
||||
from flask.views import View
|
||||
from flask_login import current_user, login_required
|
||||
from sqlalchemy.sql import extract
|
||||
|
||||
from ereuse_devicehub import __version__
|
||||
from ereuse_devicehub.resources.action.models import Snapshot
|
||||
|
||||
billing = Blueprint(
|
||||
"billing", __name__, url_prefix="/billing", template_folder="templates"
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class BillingIndexView(View):
|
||||
methods = ["GET"]
|
||||
decorators = [login_required]
|
||||
template_name = "billing/home.html"
|
||||
|
||||
def dispatch_request(self):
|
||||
# TODO (@slamora): replace hardcoded and get current time
|
||||
# https://dateutil.readthedocs.io/en/stable/_modules/dateutil/tz/tz.html?highlight=now()
|
||||
# datetime.now(tzutc())
|
||||
year = 2022
|
||||
month = 9
|
||||
snapshot_register, snapshot_update = self.count_snapshot(year, month)
|
||||
|
||||
current_month_usage = {
|
||||
"year": year,
|
||||
"month": month,
|
||||
"snapshot_register": snapshot_register,
|
||||
"snapshot_update": snapshot_update,
|
||||
# TODO (@slamora): data erasure count
|
||||
}
|
||||
context = {
|
||||
"current_month_usage": current_month_usage,
|
||||
"page_title": "Billing",
|
||||
"version": __version__,
|
||||
}
|
||||
return flask.render_template(self.template_name, **context)
|
||||
|
||||
def count_snapshot(self, year, month):
|
||||
query = Snapshot.query.filter(
|
||||
Snapshot.author_id == current_user.id,
|
||||
extract('year', Snapshot.created) == year,
|
||||
extract('month', Snapshot.created) == month,
|
||||
)
|
||||
|
||||
all = query.count()
|
||||
register = query.distinct(Snapshot.device_id).count()
|
||||
update = all - register
|
||||
|
||||
return (register, update)
|
||||
|
||||
|
||||
billing.add_url_rule("/", view_func=BillingIndexView.as_view("billing_index"))
|
|
@ -7,6 +7,7 @@ Use this as a starting point.
|
|||
from decouple import config
|
||||
|
||||
from ereuse_devicehub.api.views import api
|
||||
from ereuse_devicehub.billing.views import billing
|
||||
from ereuse_devicehub.config import DevicehubConfig
|
||||
from ereuse_devicehub.devicehub import Devicehub
|
||||
from ereuse_devicehub.inventory.views import devices
|
||||
|
@ -43,6 +44,7 @@ app.register_blueprint(devices)
|
|||
app.register_blueprint(labels)
|
||||
app.register_blueprint(api)
|
||||
app.register_blueprint(workbench)
|
||||
app.register_blueprint(billing)
|
||||
|
||||
# configure & enable CSRF of Flask-WTF
|
||||
# NOTE: enable by blueprint to exclude API views
|
||||
|
|
Reference in New Issue