- Changes to the list views - now using tabulator with filtering and sorting, client-side pagination, ...
- Adaptation of all list views in the app
This commit is contained in:
@@ -17,6 +17,8 @@ from .entitlements_forms import LicenseTierForm, LicenseForm
|
||||
from common.utils.view_assistants import prepare_table_for_macro, form_validation_failed
|
||||
from common.utils.nginx_utils import prefixed_url_for
|
||||
from common.utils.document_utils import set_logging_information, update_logging_information
|
||||
from .list_views.entitlement_list_views import get_license_tiers_list_view, get_license_list_view
|
||||
from .list_views.list_view_utils import render_list_view
|
||||
|
||||
entitlements_bp = Blueprint('entitlements_bp', __name__, url_prefix='/entitlements')
|
||||
|
||||
@@ -45,48 +47,23 @@ def license_tier():
|
||||
current_app.logger.info(f"Successfully created license tier {new_license_tier.id}")
|
||||
flash(f"Successfully created tenant license tier {new_license_tier.id}", 'success')
|
||||
|
||||
return redirect(prefixed_url_for('entitlements_bp.view_license_tiers'))
|
||||
return redirect(prefixed_url_for('entitlements_bp.license_tiers'))
|
||||
else:
|
||||
form_validation_failed(request, form)
|
||||
|
||||
return render_template('entitlements/license_tier.html', form=form)
|
||||
|
||||
|
||||
@entitlements_bp.route('/view_license_tiers', methods=['GET', 'POST'])
|
||||
@entitlements_bp.route('/license_tiers', methods=['GET', 'POST'])
|
||||
@roles_accepted('Super User', 'Partner Admin')
|
||||
def view_license_tiers():
|
||||
page = request.args.get('page', 1, type=int)
|
||||
per_page = request.args.get('per_page', 10, type=int)
|
||||
today = dt.now(tz.utc)
|
||||
def license_tiers():
|
||||
config = get_license_tiers_list_view()
|
||||
|
||||
query = LicenseTier.query.filter(
|
||||
or_(
|
||||
LicenseTier.end_date == None,
|
||||
LicenseTier.end_date >= today
|
||||
)
|
||||
)
|
||||
if current_user_has_role('Partner Admin'):
|
||||
try:
|
||||
license_tier_ids = PartnerServices.get_allowed_license_tier_ids()
|
||||
except EveAIException as e:
|
||||
flash(f"Cannot retrieve License Tiers: {str(e)}", 'danger')
|
||||
current_app.logger.error(f'Cannot retrieve License Tiers for partner: {str(e)}')
|
||||
return render_template("index.html")
|
||||
if license_tier_ids and len(license_tier_ids) > 0:
|
||||
query = query.filter(LicenseTier.id.in_(license_tier_ids))
|
||||
# Check if there was an error in getting the configuration
|
||||
if config.get('error'):
|
||||
return render_template("index.html")
|
||||
|
||||
query = query.order_by(LicenseTier.start_date.desc(), LicenseTier.id)
|
||||
|
||||
pagination = query.paginate(page=page, per_page=per_page, error_out=False)
|
||||
license_tiers = pagination.items
|
||||
|
||||
rows = prepare_table_for_macro(license_tiers, [('id', ''), ('name', ''), ('version', ''), ('start_date', ''),
|
||||
('end_date', '')])
|
||||
|
||||
return render_template('entitlements/view_license_tiers.html',
|
||||
rows=rows,
|
||||
pagination=pagination,
|
||||
can_assign_license=UserServices.can_user_assign_license())
|
||||
return render_list_view('list_view.html', **config)
|
||||
|
||||
|
||||
@entitlements_bp.route('/handle_license_tier_selection', methods=['POST'])
|
||||
@@ -110,7 +87,7 @@ def handle_license_tier_selection():
|
||||
LicenseTierServices.associate_license_tier_with_partner(license_tier_id)
|
||||
|
||||
# Add more conditions for other actions
|
||||
return redirect(prefixed_url_for('entitlements_bp.view_license_tiers'))
|
||||
return redirect(prefixed_url_for('entitlements_bp.license_tiers'))
|
||||
|
||||
|
||||
@entitlements_bp.route('/license_tier/<int:license_tier_id>', methods=['GET', 'POST'])
|
||||
@@ -253,79 +230,16 @@ def edit_license(license_id):
|
||||
return render_template('entitlements/license.html', form=form, ext_readonly_fields=readonly_fields)
|
||||
|
||||
|
||||
@entitlements_bp.route('/view_usages')
|
||||
@entitlements_bp.route('/licenses')
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def view_usages():
|
||||
page = request.args.get('page', 1, type=int)
|
||||
per_page = request.args.get('per_page', 10, type=int)
|
||||
def licenses():
|
||||
config = get_license_list_view()
|
||||
|
||||
if not session.get('tenant', None):
|
||||
flash('You can only view usage for a Tenant. Select a Tenant to continue!', 'danger')
|
||||
return redirect(prefixed_url_for('user_bp.select_tenant'))
|
||||
# Check if there was an error in getting the configuration
|
||||
if config.get('error'):
|
||||
return render_template("index.html")
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@entitlements_bp.route('/handle_usage_selection', methods=['POST'])
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def handle_usage_selection():
|
||||
usage_identification = request.form['selected_row']
|
||||
usage_id = ast.literal_eval(usage_identification).get('value')
|
||||
the_usage = LicenseUsage.query.get_or_404(usage_id)
|
||||
|
||||
action = request.form['action']
|
||||
|
||||
pass # Currently, no actions are defined
|
||||
|
||||
|
||||
@entitlements_bp.route('/view_licenses')
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def view_licenses():
|
||||
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')
|
||||
# Get current date in UTC
|
||||
current_date = dt.now(tz=tz.utc).date()
|
||||
|
||||
# Query licenses for the tenant, with ordering and active status
|
||||
# TODO - Check validity
|
||||
query = (
|
||||
License.query
|
||||
.join(LicenseTier) # Join with LicenseTier
|
||||
.filter(License.tenant_id == tenant_id)
|
||||
.add_columns(
|
||||
License.id,
|
||||
License.start_date,
|
||||
License.nr_of_periods,
|
||||
LicenseTier.name.label('license_tier_name'), # Access name through LicenseTier
|
||||
(License.start_date <= current_date).label('active')
|
||||
)
|
||||
.order_by(License.start_date.desc())
|
||||
)
|
||||
|
||||
pagination = query.paginate(page=page, per_page=per_page)
|
||||
lics = pagination.items
|
||||
|
||||
# prepare table data
|
||||
rows = prepare_table_for_macro(lics, [('id', ''), ('license_tier_name', ''), ('start_date', ''),
|
||||
('nr_of_periods', ''), ('active', '')])
|
||||
|
||||
# Render the licenses in a template
|
||||
return render_template('entitlements/view_licenses.html', rows=rows, pagination=pagination)
|
||||
return render_list_view('list_view.html', **config)
|
||||
|
||||
|
||||
@entitlements_bp.route('/handle_license_selection', methods=['POST'])
|
||||
@@ -343,7 +257,7 @@ def handle_license_selection():
|
||||
case 'view_periods':
|
||||
return redirect(prefixed_url_for('entitlements_bp.view_license_periods', license_id=license_id))
|
||||
case _:
|
||||
return redirect(prefixed_url_for('entitlements_bp.view_licenses'))
|
||||
return redirect(prefixed_url_for('entitlements_bp.licenses'))
|
||||
|
||||
|
||||
@entitlements_bp.route('/license/<int:license_id>/periods')
|
||||
@@ -356,7 +270,7 @@ def view_license_periods(license_id):
|
||||
tenant_id = session.get('tenant').get('id')
|
||||
if license.tenant_id != tenant_id:
|
||||
flash('Access denied to this license', 'danger')
|
||||
return redirect(prefixed_url_for('entitlements_bp.view_licenses'))
|
||||
return redirect(prefixed_url_for('entitlements_bp.licenses'))
|
||||
|
||||
# Get all periods for this license
|
||||
periods = (LicensePeriod.query
|
||||
@@ -402,6 +316,13 @@ def transition_period_status(license_id, period_id):
|
||||
return redirect(prefixed_url_for('entitlements_bp.view_license_periods', license_id=license_id))
|
||||
|
||||
|
||||
@entitlements_bp.route('/view_licenses')
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def view_licenses_redirect():
|
||||
# Redirect to the new licenses route
|
||||
return redirect(prefixed_url_for('entitlements_bp.licenses'))
|
||||
|
||||
|
||||
@entitlements_bp.route('/active_usage')
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def active_license_usage():
|
||||
@@ -409,7 +330,7 @@ def active_license_usage():
|
||||
tenant_id = session.get('tenant', {}).get('id')
|
||||
if not tenant_id:
|
||||
flash('No active or pending license period found for this tenant', 'warning')
|
||||
return redirect(prefixed_url_for('user_bp.select_tenant'))
|
||||
return redirect(prefixed_url_for('user_bp.tenants'))
|
||||
|
||||
active_period = LicensePeriod.query \
|
||||
.join(License) \
|
||||
|
||||
Reference in New Issue
Block a user