This commit is contained in:
pika 2025-03-30 22:01:42 +02:00
parent be6f7cfcbb
commit 9433d9d235
7 changed files with 189 additions and 84 deletions

View file

@ -10,13 +10,31 @@ bp = Blueprint('api', __name__, url_prefix='/api')
@bp.route('/subnets', methods=['GET'])
def get_subnets():
"""Get all subnets"""
"""Get all subnets grouped by site"""
subnets = Subnet.query.all()
return jsonify([{
'id': subnet.id,
'cidr': subnet.cidr,
'location': subnet.location
} for subnet in subnets])
# Group subnets by location (site)
sites = {}
for subnet in subnets:
location = subnet.location
if location not in sites:
sites[location] = []
sites[location].append({
'id': subnet.id,
'cidr': subnet.cidr,
'location': location
})
# Convert to list of site objects
result = [
{
'name': site_name,
'subnets': subnets
} for site_name, subnets in sites.items()
]
return jsonify(result)
@bp.route('/subnets/<int:subnet_id>', methods=['GET'])
@login_required

View file

@ -305,8 +305,8 @@ def app_edit(app_id):
# Check if name changed and already exists on the same server
existing_app = App.query.filter(App.name == name,
App.server_id == server_id,
App.id != app.id).first()
App.server_id == server_id,
App.id != app.id).first()
if existing_app:
flash('Application with this name already exists on the selected server', 'danger')
return render_template(
@ -321,10 +321,13 @@ def app_edit(app_id):
app.server_id = server_id
app.documentation = documentation
db.session.commit()
flash('Application updated successfully', 'success')
return redirect(url_for('dashboard.app_view', app_id=app.id))
try:
db.session.commit()
flash('Application updated successfully', 'success')
return redirect(url_for('dashboard.app_view', app_id=app.id))
except Exception as e:
db.session.rollback()
flash(f'Error updating application: {str(e)}', 'danger')
return render_template(
'dashboard/app_form.html',