- License Usage Calculation realised
- View License Usages - Celery Beat container added - First schedule in Celery Beat for calculating usage (hourly) - repopack can now split for different components - Various fixes as consequece of changing file_location / file_name ==> bucket_name / object_name - Celery Routing / Queuing updated
This commit is contained in:
@@ -2,18 +2,14 @@ import uuid
|
||||
from datetime import datetime as dt, timezone as tz
|
||||
from flask import request, redirect, flash, render_template, Blueprint, session, current_app, jsonify
|
||||
from flask_security import hash_password, roles_required, roles_accepted, current_user
|
||||
from itsdangerous import URLSafeTimedSerializer
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy import or_
|
||||
from sqlalchemy import or_, desc
|
||||
import ast
|
||||
|
||||
from common.models.entitlements import License, LicenseTier, LicenseUsage, BusinessEventLog
|
||||
from common.extensions import db, security, minio_client, simple_encryption
|
||||
from common.utils.security_utils import send_confirmation_email, send_reset_email
|
||||
from .entitlements_forms import LicenseTierForm, LicenseForm
|
||||
from common.utils.database import Database
|
||||
from common.utils.view_assistants import prepare_table_for_macro, form_validation_failed
|
||||
from common.utils.simple_encryption import generate_api_key
|
||||
from common.utils.nginx_utils import prefixed_url_for
|
||||
|
||||
entitlements_bp = Blueprint('entitlements_bp', __name__, url_prefix='/entitlements')
|
||||
@@ -174,14 +170,14 @@ def create_license(license_tier_id):
|
||||
db.session.add(new_license)
|
||||
db.session.commit()
|
||||
flash('License created successfully', 'success')
|
||||
return redirect(prefixed_url_for('entitlements_bp/edit_license', license_id=new_license.id))
|
||||
return redirect(prefixed_url_for('entitlements_bp.edit_license', license_id=new_license.id))
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
flash(f'Error creating license: {str(e)}', 'error')
|
||||
else:
|
||||
form_validation_failed(request, form)
|
||||
|
||||
return render_template('entitlements/license.html', form=form)
|
||||
return render_template('entitlements/license.html', form=form, ext_disabled_fields=[])
|
||||
|
||||
|
||||
@entitlements_bp.route('/license/<int:license_id>', methods=['GET', 'POST'])
|
||||
@@ -215,3 +211,25 @@ def edit_license(license_id):
|
||||
|
||||
return render_template('entitlements/license.html', form=form, license_tier_id=license_tier.id,
|
||||
ext_disabled_fields=disabled_fields)
|
||||
|
||||
|
||||
@entitlements_bp.route('/view_usages')
|
||||
@roles_accepted('Super User', 'Tenant Admin')
|
||||
def view_usages():
|
||||
page = request.args.get('page', 1, type=int)
|
||||
per_page = request.args.get('per_page', 10, type=int)
|
||||
|
||||
tenant_id = session.get('tenant').get('id')
|
||||
query = LicenseUsage.query.filter_by(tenant_id=tenant_id).order_by(desc(LicenseUsage.id))
|
||||
|
||||
pagination = query.paginate(page=page, per_page=per_page)
|
||||
lus = pagination.items
|
||||
|
||||
# prepare table data
|
||||
|
||||
rows = prepare_table_for_macro(lus, [('id', ''), ('period_start_date', ''), ('period_end_date', ''),
|
||||
('storage_mb_used', ''), ('embedding_mb_used', ''),
|
||||
('interaction_total_tokens_used', '')])
|
||||
|
||||
# Render the users in a template
|
||||
return render_template('entitlements/view_usages.html', rows=rows, pagination=pagination)
|
||||
|
||||
Reference in New Issue
Block a user