Add mac redirect endpoint
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/manual/woodpecker Pipeline was successful

This commit is contained in:
Madis Mägi 2024-09-05 13:40:26 +03:00
parent 5965b56317
commit 943fe2e8cf

View File

@ -4,7 +4,7 @@ import urllib
from datetime import datetime, date, timedelta
from botocore.exceptions import ClientError
from bson.objectid import ObjectId
from flask import Blueprint, abort, g, make_response, redirect, render_template, request
from flask import Blueprint, abort, g, make_response, redirect, render_template, request, url_for
from jpegtran import JPEGImage
from pymongo import MongoClient
from werkzeug.utils import secure_filename
@ -21,6 +21,14 @@ page_inventory = Blueprint("inventory", __name__)
db = MongoClient(const.MONGO_URI).get_default_database()
channel = "inventory"
@login_required
@page_inventory.route("/m/inventory/by-mac/<mac>", methods=['GET'])
def view_inventory_by_mac(mac):
item = db.inventory.find_one({ "mac": mac }, projection = { "_id": 1})
if not item or not item.get("_id", False):
return abort(404)
return redirect(url_for("inventory.view_inventory_view", item_id = item["_id"]))
@page_inventory.route("/m/inventory/<item_id>/view")
def view_inventory_view(item_id):
user = read_user()