- Fixes
- ADD list view for allocations
- ADD hide dhcp option (list view)
This commit is contained in:
Lucas committed 2026-01-22 16:39:38 +01:00
1 parent 03e543e7f8
commit 800ff061b7
8 files changed
+100 -33

No files matched your search

+2 -2
View File
@@ -5,12 +5,12 @@ import random, string
## Flask Server (For DEV) ## Flask Server (For DEV)
app_ip = '127.0.0.1' app_ip = '127.0.0.1'
app_port = 80 app_port = 5000
app_debug = True app_debug = True
app_maintenance = False app_maintenance = False
app_name = 'takeus-ipam' app_name = 'takeus-ipam'
app_version = 'V1.6' app_version = 'V2026.1'
app_release_date = '11/2025' app_release_date = '11/2025'
app_url = "http://0.0.0.0" app_url = "http://0.0.0.0"
+1
View File
@@ -8,6 +8,7 @@ class User(UserMixin, db.Model):
is_admin = db.Column(db.Boolean(),default=False) is_admin = db.Column(db.Boolean(),default=False)
is_reado = db.Column(db.Boolean(),default=False) is_reado = db.Column(db.Boolean(),default=False)
ui_theme = db.Column(db.String(16)) ui_theme = db.Column(db.String(16))
ui_lmode = db.Column(db.Boolean(),default=False)
dat_last = db.Column(db.DateTime()) dat_last = db.Column(db.DateTime())
class Network(db.Model): class Network(db.Model):
+52 -23
View File
@@ -46,26 +46,55 @@ def networks():
@network.route('/<int:net_id>/allocations',methods=['GET','POST']) @network.route('/<int:net_id>/allocations',methods=['GET','POST'])
@login_required @login_required
def allocations(net_id): def allocations(net_id):
# CHANGE VIEW
active_page = request.args.get('page', type=int) if request.args.get('view') == "change":
if active_page == None: db_user = User.query.filter_by(id=current_user.id).first()
active_page = 1 if current_user.ui_lmode == False:
db_user.ui_lmode = True
next_page = active_page+1 else:
prev_page = active_page-1 db_user.ui_lmode = False
db.session.commit()
if request.args.get('items', type=int) != None: return redirect(url_for('network.allocations',net_id=net_id))
session['items'] = request.args.get('items', type=int) # HIDE DHCP
try: try:
if session['items'] == None: session['hide_dhcp']
session['items'] = 15
except: except:
session['items'] = 15 session['hide_dhcp'] = False
if request.args.get('view') == "hide_dhcp":
db_network = Network.query.filter_by(id=net_id).first() if session['hide_dhcp'] == False:
db_allocations = db.paginate(db.select(Allocation).filter_by(net_id=net_id), per_page=session['items'] ) session['hide_dhcp'] = True
else:
return render_template('panel/allocations.html', title="Allocations", is_networks=True, app_version=app_version, allocations=db_allocations, network=db_network, Inventory=Inventory, active_page=active_page, next_page=next_page, prev_page=prev_page, navcolor='dark') session['hide_dhcp'] = False
return redirect(url_for('network.allocations',net_id=net_id))
print(session['hide_dhcp'])
# PAGINATION MODE
if current_user.ui_lmode == False:
active_page = request.args.get('page', type=int)
if active_page == None:
active_page = 1
next_page = active_page+1
prev_page = active_page-1
if request.args.get('items', type=int) != None:
session['items'] = request.args.get('items', type=int)
try:
if session['items'] == None:
session['items'] = 15
except:
session['items'] = 15
db_network = Network.query.filter_by(id=net_id).first()
db_allocations = db.paginate(db.select(Allocation).filter_by(net_id=net_id), per_page=session['items'] )
return render_template('panel/allocations.html', title="Allocations", is_networks=True, app_version=app_version, allocations=db_allocations, network=db_network, Inventory=Inventory, active_page=active_page, next_page=next_page, prev_page=prev_page, navcolor='dark')
# LIST MODE
else:
db_network = Network.query.filter_by(id=net_id).first()
db_allocations = Allocation.query.filter_by(net_id=net_id).all()
return render_template('panel/allocations.html', title="Allocations", is_networks=True, app_version=app_version, allocations=db_allocations, network=db_network, Inventory=Inventory, navcolor='dark')
## MODAL ROUTES ## MODAL ROUTES
@@ -94,7 +123,7 @@ def allocation_del_modal(net_id,ipv4):
'action_text': 'Remove', 'action_text': 'Remove',
'action_url': url_for('network.allocation_delete',net_id=net_id,ipv4=ipv4) 'action_url': url_for('network.allocation_delete',net_id=net_id,ipv4=ipv4)
} }
return render_template('panel/_modal.html', modal=modal, net_id=net_id, ipv4=ipv4, old_page=request.args.get('page', type=int), pagination_active=True) return render_template('panel/_modal.html', modal=modal, net_id=net_id, ipv4=ipv4, old_page=str(request.args.get('page', type=int))+f"#{ipv4}", pagination_active=True)
@network.route('/<int:net_id>/allocations/<string:ipv4>/edit_modal', methods=['GET','POST']) @network.route('/<int:net_id>/allocations/<string:ipv4>/edit_modal', methods=['GET','POST'])
@@ -128,7 +157,7 @@ def allocation_edit_modal(net_id, ipv4):
db.session.commit() db.session.commit()
flash("Allocation Updated", 'success') flash("Allocation Updated", 'success')
return redirect(url_for('network.allocations',net_id=net_id,page=request.args.get('page', type=int))) return redirect(url_for('network.allocations',net_id=net_id,page=request.args.get('page', type=int),_anchor=request.args.get('item', type=str)))
modal = { modal = {
'title': 'Update Allocation', 'title': 'Update Allocation',
@@ -151,7 +180,7 @@ def allocation_edit_modal(net_id, ipv4):
form.is_special.default = 2 form.is_special.default = 2
form.process() form.process()
return render_template('panel/_modal.html', modal=modal, form=form, old_page=old_page, pagination_active=True) return render_template('panel/_modal.html', modal=modal, form=form, old_page=str(old_page)+f"#{ipv4}", pagination_active=True)
## MODIFICATION ROUTES ## MODIFICATION ROUTES
@network.get('/<int:net_id>/allocations/<string:ipv4>/unallocate') @network.get('/<int:net_id>/allocations/<string:ipv4>/unallocate')
@@ -169,7 +198,7 @@ def allocation_delete(net_id,ipv4):
db_alloc.is_decom = False db_alloc.is_decom = False
db.session.commit() db.session.commit()
flash("Allocation Removed", 'warning') flash("Allocation Removed", 'warning')
return redirect(url_for('network.allocations',net_id=net_id,page=request.args.get('page', type=int))) return redirect(url_for('network.allocations',net_id=net_id,page=request.args.get('page', type=int),_anchor=request.args.get('item', type=str)))
@network.get('/<int:net_id>/allocations/<string:ipv4>/decom/<int:action>') @network.get('/<int:net_id>/allocations/<string:ipv4>/decom/<int:action>')
@login_required @login_required
@@ -183,7 +212,7 @@ def allocation_decom(net_id,ipv4,action):
else: else:
db_alloc.is_decom = False db_alloc.is_decom = False
db.session.commit() db.session.commit()
return redirect(url_for('network.allocations',net_id=net_id,page=request.args.get('page', type=int))) return redirect(url_for('network.allocations',net_id=net_id,page=request.args.get('page', type=int),_anchor=request.args.get('item', type=str)))
@network.get('/<int:net_id>/delete') @network.get('/<int:net_id>/delete')
@login_required @login_required
+4
View File
@@ -6,4 +6,8 @@
pre { pre {
margin: 0; margin: 0;
padding: 0; padding: 0;
}
html {
scroll-behavior: auto !important;
} }
+27
View File
@@ -0,0 +1,27 @@
if (history.scrollRestoration) {
history.scrollRestoration = 'manual';
}
function instantCenter() {
const hash = window.location.hash;
if (!hash) return;
const targetId = hash.substring(1);
const element = document.getElementById(targetId);
if (element) {
setTimeout(() => {
const elementRect = element.getBoundingClientRect();
const absoluteElementTop = elementRect.top + window.scrollY;
const middle = absoluteElementTop - (window.innerHeight / 2) + (elementRect.height / 2);
window.scrollTo({
top: middle,
behavior: 'auto'
});
}, 0);
}
}
window.addEventListener('load', instantCenter);
+1 -1
View File
@@ -1 +1 @@
<footer class="test-center" style="text-align: center;">Flask IPAM - 2025 - {{app_version}}</footer> <footer class="test-center" style="text-align: center;">Flask IPAM - {{app_version}}</footer>
+9 -6
View File
@@ -1,6 +1,8 @@
{% for allocation in allocations %} {% for allocation in allocations %}
{% if session['hide_dhcp'] and allocation.is_dhcp %}
{% else %}
<tr> <tr>
<td><b>{{allocation.ipv4}}</b></td> <td id="{{allocation.ipv4}}"><b>{{allocation.ipv4}}</b></td>
<td>{{allocation.hostname}}</td> <td>{{allocation.hostname}}</td>
<td>{{allocation.description}}</td> <td>{{allocation.description}}</td>
<td> <td>
@@ -26,7 +28,7 @@
<td> <td>
{% if allocation.is_used %} {% if allocation.is_used %}
<button <button
hx-get="{{ url_for('network.allocation_edit_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}" hx-get="{{ url_for('network.allocation_edit_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}&item={{allocation.ipv4}}"
hx-trigger="click" hx-trigger="click"
hx-target="#modal-edit" hx-target="#modal-edit"
data-bs-toggle="modal" data-bs-toggle="modal"
@@ -36,12 +38,12 @@
> Edit > Edit
</button> </button>
{% if allocation.is_decom %} {% if allocation.is_decom %}
<a href="{{ url_for('network.allocation_decom',action=2,net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}" class="btn btn-sm btn-outline-primary" style="padding-top:1px;padding-bottom:1px">Undecom</a> <a href="{{ url_for('network.allocation_decom',action=2,net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}&item={{allocation.ipv4}}" class="btn btn-sm btn-outline-primary" style="padding-top:1px;padding-bottom:1px">Undecom</a>
{% else %} {% else %}
<a href="{{ url_for('network.allocation_decom',action=1,net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}" class="btn btn-sm btn-outline-warning" style="padding-top:1px;padding-bottom:1px">Decom</a> <a href="{{ url_for('network.allocation_decom',action=1,net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}&item={{allocation.ipv4}}" class="btn btn-sm btn-outline-warning" style="padding-top:1px;padding-bottom:1px">Decom</a>
{% endif %} {% endif %}
<button <button
hx-get="{{ url_for('network.allocation_del_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}" hx-get="{{ url_for('network.allocation_del_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}&item={{allocation.ipv4}}"
hx-trigger="click" hx-trigger="click"
hx-target="#modal-del" hx-target="#modal-del"
data-bs-toggle="modal" data-bs-toggle="modal"
@@ -52,7 +54,7 @@
</button> </button>
{% else %} {% else %}
<button <button
hx-get="{{ url_for('network.allocation_edit_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}" hx-get="{{ url_for('network.allocation_edit_modal',net_id=network.id,ipv4=allocation.ipv4) }}?page={{active_page}}&item={{allocation.ipv4}}"
hx-trigger="click" hx-trigger="click"
hx-target="#modal-edit" hx-target="#modal-edit"
data-bs-toggle="modal" data-bs-toggle="modal"
@@ -65,4 +67,5 @@
</td> </td>
{% endif %} {% endif %}
</tr> </tr>
{% endif %}
{% endfor %} {% endfor %}
+4 -1
View File
@@ -6,7 +6,7 @@
<div class="row"> <div class="row">
<!-- Search BAR --> <!-- Search BAR -->
<div class="col-12"> <div class="col-12">
<div class="mb-3"> <div class="input-group mb-3">
<input class="form-control" type="search" <input class="form-control" type="search"
name="search" placeholder="Begin Typing To Search Allocation(s)..." name="search" placeholder="Begin Typing To Search Allocation(s)..."
hx-post="{{ url_for('network.allocation_search',net_id=network.id) }}" hx-post="{{ url_for('network.allocation_search',net_id=network.id) }}"
@@ -14,6 +14,8 @@
hx-target="#search-results" hx-target="#search-results"
hx-indicator=".htmx-indicator" hx-indicator=".htmx-indicator"
> >
<a class="btn btn-outline-secondary" href="?view=change">change view</a>
<a class="btn btn-outline-secondary" href="?view=hide_dhcp">Hide DHCP</a>
</div> </div>
</div> </div>
<!-- IPV4 TABLE --> <!-- IPV4 TABLE -->
@@ -82,4 +84,5 @@
<div class="modal-content"></div> <div class="modal-content"></div>
</div> </div>
</div> </div>
<script src="{{ url_for('static',filename='js/custom.js') }}"></script>
{% endblock %} {% endblock %}