create regular exp added and change model
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
from app import db
|
from app import db
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from sqlalchemy import event
|
from sqlalchemy import event
|
||||||
import re
|
from app.utils.regex_utils import RegularExpression
|
||||||
# REGEX PATTERN
|
|
||||||
PIPE_MM_PATTERN = re.compile(r"^pipe_\d+_mm$")
|
|
||||||
|
|
||||||
class LayingClient(db.Model):
|
class LayingClient(db.Model):
|
||||||
__tablename__ = "laying_client"
|
__tablename__ = "laying_client"
|
||||||
@@ -53,13 +51,13 @@ class LayingClient(db.Model):
|
|||||||
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
|
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
|
||||||
|
|
||||||
|
|
||||||
def sum_laying_fields():
|
# def sum_laying_fields():
|
||||||
return [
|
# return [
|
||||||
"pipe_150_mm", "pipe_200_mm", "pipe_250_mm",
|
# "pipe_150_mm", "pipe_200_mm", "pipe_250_mm",
|
||||||
"pipe_300_mm", "pipe_350_mm", "pipe_400_mm",
|
# "pipe_300_mm", "pipe_350_mm", "pipe_400_mm",
|
||||||
"pipe_450_mm", "pipe_500_mm", "pipe_600_mm",
|
# "pipe_450_mm", "pipe_500_mm", "pipe_600_mm",
|
||||||
"pipe_700_mm", "pipe_900_mm", "pipe_1200_mm"
|
# "pipe_700_mm", "pipe_900_mm", "pipe_1200_mm"
|
||||||
]
|
# ]
|
||||||
|
|
||||||
# ===============================
|
# ===============================
|
||||||
# AUTO TOTAL USING REGEX
|
# AUTO TOTAL USING REGEX
|
||||||
@@ -68,7 +66,7 @@ def calculate_laying_total(mapper, connection, target):
|
|||||||
total = 0
|
total = 0
|
||||||
|
|
||||||
for column in target.__table__.columns:
|
for column in target.__table__.columns:
|
||||||
if PIPE_MM_PATTERN.match(column.name):
|
if RegularExpression.PIPE_MM_PATTERN.match(column.name):
|
||||||
total += getattr(target, column.name) or 0
|
total += getattr(target, column.name) or 0
|
||||||
|
|
||||||
target.Total = total
|
target.Total = total
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
from app import db
|
from app import db
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from sqlalchemy import event
|
from sqlalchemy import event
|
||||||
import re
|
|
||||||
# REGEX PATTERN
|
from app.utils.regex_utils import RegularExpression
|
||||||
PIPE_MM_PATTERN = re.compile(r"^pipe_\d+_mm$")
|
|
||||||
|
|
||||||
class Laying(db.Model):
|
class Laying(db.Model):
|
||||||
__tablename__ = "laying"
|
__tablename__ = "laying"
|
||||||
@@ -49,13 +48,13 @@ class Laying(db.Model):
|
|||||||
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
|
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
|
||||||
|
|
||||||
|
|
||||||
def sum_laying_fields():
|
# def sum_laying_fields():
|
||||||
return [
|
# return [
|
||||||
"pipe_150_mm", "pipe_200_mm", "pipe_250_mm",
|
# "pipe_150_mm", "pipe_200_mm", "pipe_250_mm",
|
||||||
"pipe_300_mm", "pipe_350_mm", "pipe_400_mm",
|
# "pipe_300_mm", "pipe_350_mm", "pipe_400_mm",
|
||||||
"pipe_450_mm", "pipe_500_mm", "pipe_600_mm",
|
# "pipe_450_mm", "pipe_500_mm", "pipe_600_mm",
|
||||||
"pipe_700_mm", "pipe_900_mm", "pipe_1200_mm"
|
# "pipe_700_mm", "pipe_900_mm", "pipe_1200_mm"
|
||||||
]
|
# ]
|
||||||
|
|
||||||
# ===============================
|
# ===============================
|
||||||
# AUTO TOTAL USING REGEX
|
# AUTO TOTAL USING REGEX
|
||||||
@@ -64,7 +63,7 @@ def calculate_laying_total(mapper, connection, target):
|
|||||||
total = 0
|
total = 0
|
||||||
|
|
||||||
for column in target.__table__.columns:
|
for column in target.__table__.columns:
|
||||||
if PIPE_MM_PATTERN.match(column.name):
|
if RegularExpression.PIPE_MM_PATTERN.match(column.name):
|
||||||
total += getattr(target, column.name) or 0
|
total += getattr(target, column.name) or 0
|
||||||
|
|
||||||
target.Total = total
|
target.Total = total
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
from app import db
|
from app import db
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from sqlalchemy import event
|
from sqlalchemy import event
|
||||||
import re
|
from app.utils.regex_utils import RegularExpression
|
||||||
|
|
||||||
# REGEX PATTERN
|
|
||||||
D_RANGE_PATTERN = re.compile(r"^d_\d+(?:_\d+)?_to_\d+(?:_\d+)?$")
|
|
||||||
|
|
||||||
class ManholeDomesticChamber(db.Model):
|
class ManholeDomesticChamber(db.Model):
|
||||||
__tablename__ = "manhole_domestic_chamber"
|
__tablename__ = "manhole_domestic_chamber"
|
||||||
@@ -56,15 +53,15 @@ class ManholeDomesticChamber(db.Model):
|
|||||||
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
|
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
|
||||||
|
|
||||||
|
|
||||||
def sum_mh_dc_fields():
|
# def sum_mh_dc_fields():
|
||||||
return [
|
# return [
|
||||||
"d_0_to_0_75", "d_0_76_to_1_05", "d_1_06_to_1_65",
|
# "d_0_to_0_75", "d_0_76_to_1_05", "d_1_06_to_1_65",
|
||||||
"d_1_66_to_2_15", "d_2_16_to_2_65", "d_2_66_to_3_15",
|
# "d_1_66_to_2_15", "d_2_16_to_2_65", "d_2_66_to_3_15",
|
||||||
"d_3_16_to_3_65", "d_3_66_to_4_15", "d_4_16_to_4_65",
|
# "d_3_16_to_3_65", "d_3_66_to_4_15", "d_4_16_to_4_65",
|
||||||
"d_4_66_to_5_15", "d_5_16_to_5_65", "d_5_66_to_6_15",
|
# "d_4_66_to_5_15", "d_5_16_to_5_65", "d_5_66_to_6_15",
|
||||||
"d_6_16_to_6_65", "d_6_66_to_7_15", "d_7_16_to_7_65",
|
# "d_6_16_to_6_65", "d_6_66_to_7_15", "d_7_16_to_7_65",
|
||||||
"d_7_66_to_8_15", "d_8_16_to_8_65", "d_8_66_to_9_15",
|
# "d_7_66_to_8_15", "d_8_16_to_8_65", "d_8_66_to_9_15",
|
||||||
"d_9_16_to_9_65"]
|
# "d_9_16_to_9_65"]
|
||||||
|
|
||||||
# ===============================
|
# ===============================
|
||||||
# AUTO TOTAL USING REGEX
|
# AUTO TOTAL USING REGEX
|
||||||
@@ -73,7 +70,7 @@ def calculate_mh_dc_total(mapper, connection, target):
|
|||||||
total = 0
|
total = 0
|
||||||
|
|
||||||
for column in target.__table__.columns:
|
for column in target.__table__.columns:
|
||||||
if D_RANGE_PATTERN.match(column.name):
|
if RegularExpression.D_RANGE_PATTERN.match(column.name):
|
||||||
total += getattr(target, column.name) or 0
|
total += getattr(target, column.name) or 0
|
||||||
|
|
||||||
target.Total = total
|
target.Total = total
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ class TrenchExcavationClient(db.Model):
|
|||||||
# ==========================================
|
# ==========================================
|
||||||
# AUTO CALCULATE GRAND TOTAL
|
# AUTO CALCULATE GRAND TOTAL
|
||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
def calculate_trench_client_total(mapper, connection, target):
|
def calculate_trench_client_total(mapper, connection, target):
|
||||||
total = 0
|
total = 0
|
||||||
for column in target.__table__.columns:
|
for column in target.__table__.columns:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import matplotlib
|
import matplotlib
|
||||||
matplotlib.use("Agg")
|
matplotlib.use("Agg")
|
||||||
|
|
||||||
from flask import Blueprint, render_template, session, redirect, url_for, jsonify
|
from flask import Blueprint, render_template, session, redirect, url_for, jsonify, request
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import io
|
import io
|
||||||
import base64
|
import base64
|
||||||
@@ -93,6 +93,9 @@ def subcontractor_chart():
|
|||||||
if subcontractor_id:
|
if subcontractor_id:
|
||||||
query = query.filter(TrenchExcavation.subcontractor_id == subcontractor_id)
|
query = query.filter(TrenchExcavation.subcontractor_id == subcontractor_id)
|
||||||
|
|
||||||
|
if category:
|
||||||
|
query = query.filter(TrenchExcavation.subcontractor_id == subcontractor_id)
|
||||||
|
|
||||||
if ra_bill:
|
if ra_bill:
|
||||||
query = query.filter(TrenchExcavation.RA_Bill_No == ra_bill)
|
query = query.filter(TrenchExcavation.RA_Bill_No == ra_bill)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from flask import Blueprint, render_template, request, send_file, flash
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import io
|
import io
|
||||||
|
|
||||||
from app.models.subcontractor_model import Subcontractor
|
from app.models.subcontractor_model import Subcontractor
|
||||||
from app.models.trench_excavation_model import TrenchExcavation
|
from app.models.trench_excavation_model import TrenchExcavation
|
||||||
from app.models.manhole_excavation_model import ManholeExcavation
|
from app.models.manhole_excavation_model import ManholeExcavation
|
||||||
@@ -15,17 +15,13 @@ from app.models.mh_dc_client_model import ManholeDomesticChamberClient
|
|||||||
from app.models.laying_client_model import LayingClient
|
from app.models.laying_client_model import LayingClient
|
||||||
|
|
||||||
from app.utils.helpers import login_required
|
from app.utils.helpers import login_required
|
||||||
import re
|
from app.utils.regex_utils import RegularExpression
|
||||||
|
|
||||||
|
|
||||||
generate_report_bp = Blueprint("generate_report", __name__, url_prefix="/report")
|
generate_report_bp = Blueprint("generate_report", __name__, url_prefix="/report")
|
||||||
|
|
||||||
|
|
||||||
# sum field of pipe laying (pipe_150_mm)
|
|
||||||
PIPE_MM_PATTERN = re.compile(r"^pipe_\d+_mm$")
|
|
||||||
# sum fields of MH dc (d_0_to_0_75)
|
|
||||||
D_RANGE_PATTERN = re.compile( r"^d_\d+(?:_\d+)?_to_\d+(?:_\d+)?$")
|
|
||||||
|
|
||||||
|
|
||||||
# NORMALIZER
|
# NORMALIZER
|
||||||
def normalize_key(value):
|
def normalize_key(value):
|
||||||
@@ -80,6 +76,9 @@ def build_comparison(client_rows, contractor_rows, key_field):
|
|||||||
used_index = defaultdict(int) # 🔥 THIS FIXES YOUR ISSUE
|
used_index = defaultdict(int) # 🔥 THIS FIXES YOUR ISSUE
|
||||||
|
|
||||||
for c in client_rows:
|
for c in client_rows:
|
||||||
|
print("@@@@@@@@@@@@@@@@@@@@@@@")
|
||||||
|
print("c::::",c)
|
||||||
|
print("@@@@@@@@@@@@@@@@@@@@@@@")
|
||||||
client_location = normalize_key(c.get("Location"))
|
client_location = normalize_key(c.get("Location"))
|
||||||
client_key = normalize_key(c.get(key_field))
|
client_key = normalize_key(c.get(key_field))
|
||||||
|
|
||||||
@@ -104,16 +103,16 @@ def build_comparison(client_rows, contractor_rows, key_field):
|
|||||||
float(v or 0)
|
float(v or 0)
|
||||||
for k, v in c.items()
|
for k, v in c.items()
|
||||||
if k.endswith("_total")
|
if k.endswith("_total")
|
||||||
or D_RANGE_PATTERN.match(k)
|
or RegularExpression.D_RANGE_PATTERN.match(k)
|
||||||
or PIPE_MM_PATTERN.match(k)
|
or RegularExpression.PIPE_MM_PATTERN.match(k)
|
||||||
)
|
)
|
||||||
|
|
||||||
sub_total = sum(
|
sub_total = sum(
|
||||||
float(v or 0)
|
float(v or 0)
|
||||||
for k, v in s.items()
|
for k, v in s.items()
|
||||||
if k.endswith("_total")
|
if k.endswith("_total")
|
||||||
or D_RANGE_PATTERN.match(k)
|
or RegularExpression.D_RANGE_PATTERN.match(k)
|
||||||
or PIPE_MM_PATTERN.match(k)
|
or RegularExpression.PIPE_MM_PATTERN.match(k)
|
||||||
)
|
)
|
||||||
|
|
||||||
row = {
|
row = {
|
||||||
@@ -138,7 +137,18 @@ def build_comparison(client_rows, contractor_rows, key_field):
|
|||||||
output.append(row)
|
output.append(row)
|
||||||
|
|
||||||
df = pd.DataFrame(output)
|
df = pd.DataFrame(output)
|
||||||
|
print("-------------------")
|
||||||
|
print("df::",df)
|
||||||
|
print("++++++++++++++++++++++++s+++++")
|
||||||
|
for col in df.columns:
|
||||||
|
print("colll::",col)
|
||||||
|
|
||||||
|
|
||||||
df.columns = [format_header(col) for col in df.columns]
|
df.columns = [format_header(col) for col in df.columns]
|
||||||
|
print("-------------------")
|
||||||
|
print("df.columns::",df.columns)
|
||||||
|
|
||||||
|
|
||||||
return df
|
return df
|
||||||
|
|
||||||
|
|
||||||
@@ -254,106 +264,4 @@ def comparison_report():
|
|||||||
)
|
)
|
||||||
|
|
||||||
return render_template("generate_comparison_report.html",subcontractors=subcontractors)
|
return render_template("generate_comparison_report.html",subcontractors=subcontractors)
|
||||||
|
|
||||||
|
|
||||||
# def build_comparison_mh_dc(client_rows, contractor_rows, key_field):
|
|
||||||
# contractor_lookup = make_lookup(contractor_rows, key_field)
|
|
||||||
# mh_dc_fields = ManholeDomesticChamberClient.sum_mh_dc_fields()
|
|
||||||
|
|
||||||
# output = []
|
|
||||||
|
|
||||||
# for c in client_rows:
|
|
||||||
# loc = normalize_key(c.get("Location"))
|
|
||||||
# key = normalize_key(c.get(key_field))
|
|
||||||
# if not loc or not key:
|
|
||||||
# continue
|
|
||||||
|
|
||||||
# s = contractor_lookup.get((loc, key))
|
|
||||||
# if not s:
|
|
||||||
# continue
|
|
||||||
|
|
||||||
# client_total = sum(float(c.get(f, 0) or 0) for f in mh_dc_fields)
|
|
||||||
# sub_total = sum(float(s.get(f, 0) or 0) for f in mh_dc_fields)
|
|
||||||
|
|
||||||
# row = {
|
|
||||||
# "Location": loc,
|
|
||||||
# key_field.replace("_", " "): key
|
|
||||||
# }
|
|
||||||
|
|
||||||
# # CLIENT – ALL FIELDS
|
|
||||||
# for k, v in c.items():
|
|
||||||
# if k in ["id", "created_at"]:
|
|
||||||
# continue
|
|
||||||
# row[f"Client-{k}"] = v
|
|
||||||
|
|
||||||
# row["Client-Total"] = round(client_total, 2)
|
|
||||||
# row[" "] = ""
|
|
||||||
|
|
||||||
# # SUBCONTRACTOR – ALL FIELDS
|
|
||||||
# for k, v in s.items():
|
|
||||||
# if k in ["id", "created_at", "subcontractor_id"]:
|
|
||||||
# continue
|
|
||||||
# row[f"Subcontractor-{k}"] = v
|
|
||||||
|
|
||||||
# row["Subcontractor-Total"] = round(sub_total, 2)
|
|
||||||
# row["Diff"] = round(client_total - sub_total, 2)
|
|
||||||
|
|
||||||
# output.append(row)
|
|
||||||
|
|
||||||
# df = pd.DataFrame(output)
|
|
||||||
# df.columns = [format_header(col) for col in df.columns]
|
|
||||||
# return df
|
|
||||||
|
|
||||||
|
|
||||||
# def build_comparison_laying(client_rows, contractor_rows, key_field):
|
|
||||||
# contractor_lookup = make_lookup(contractor_rows, key_field)
|
|
||||||
# laying_fields = Laying.sum_laying_fields()
|
|
||||||
|
|
||||||
# output = []
|
|
||||||
|
|
||||||
# for c in client_rows:
|
|
||||||
# loc = normalize_key(c.get("Location"))
|
|
||||||
# key = normalize_key(c.get(key_field))
|
|
||||||
# if not loc or not key:
|
|
||||||
# continue
|
|
||||||
|
|
||||||
# s = contractor_lookup.get((loc, key))
|
|
||||||
# if not s:
|
|
||||||
# continue
|
|
||||||
|
|
||||||
# client_total = sum(float(c.get(f, 0) or 0) for f in laying_fields)
|
|
||||||
# sub_total = sum(float(s.get(f, 0) or 0) for f in laying_fields)
|
|
||||||
|
|
||||||
# print("--------------",key,"----------")
|
|
||||||
# print("sum -client_total ",client_total)
|
|
||||||
# print("sum -sub_total ",sub_total)
|
|
||||||
# print("Diff ---- ",client_total - sub_total)
|
|
||||||
# print("------------------------")
|
|
||||||
# row = {
|
|
||||||
# "Location": loc,
|
|
||||||
# key_field.replace("_", " "): key
|
|
||||||
# }
|
|
||||||
|
|
||||||
# # CLIENT – ALL FIELDS
|
|
||||||
# for k, v in c.items():
|
|
||||||
# if k in ["id", "created_at"]:
|
|
||||||
# continue
|
|
||||||
# row[f"Client-{k}"] = v
|
|
||||||
|
|
||||||
# row["Client-Total"] = round(client_total, 2)
|
|
||||||
# row[" "] = ""
|
|
||||||
|
|
||||||
# # SUBCONTRACTOR – ALL FIELDS
|
|
||||||
# for k, v in s.items():
|
|
||||||
# if k in ["id", "created_at", "subcontractor_id"]:
|
|
||||||
# continue
|
|
||||||
# row[f"Subcontractor-{k}"] = v
|
|
||||||
|
|
||||||
# row["Subcontractor-Total"] = round(sub_total, 2)
|
|
||||||
# row["Diff"] = round(client_total - sub_total, 2)
|
|
||||||
|
|
||||||
# output.append(row)
|
|
||||||
|
|
||||||
# df = pd.DataFrame(output)
|
|
||||||
# df.columns = [format_header(col) for col in df.columns]
|
|
||||||
# return df
|
|
||||||
@@ -121,7 +121,7 @@ def update_subcontractor(id):
|
|||||||
subcontractor.mobile_no = request.form.get("mobile_no")
|
subcontractor.mobile_no = request.form.get("mobile_no")
|
||||||
subcontractor.email_id = request.form.get("email_id")
|
subcontractor.email_id = request.form.get("email_id")
|
||||||
subcontractor.gst_no = request.form.get("gst_no")
|
subcontractor.gst_no = request.form.get("gst_no")
|
||||||
subcontractor.gst_no = request.form.get("pan_no")
|
subcontractor.pan_no = request.form.get("pan_no")
|
||||||
subcontractor.status = request.form.get("status")
|
subcontractor.status = request.form.get("status")
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|||||||
@@ -1,20 +1,25 @@
|
|||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
from logging.handlers import RotatingFileHandler
|
from logging.handlers import RotatingFileHandler
|
||||||
from flask import request, session
|
from flask import request, session, has_request_context
|
||||||
|
|
||||||
|
|
||||||
class RequestFormatter(logging.Formatter):
|
class RequestContextFilter(logging.Filter):
|
||||||
"""
|
|
||||||
Custom formatter to safely inject request data
|
|
||||||
"""
|
|
||||||
|
|
||||||
def format(self, record):
|
def filter(self, record):
|
||||||
record.user = getattr(record, "user", "Anonymous")
|
|
||||||
record.ip = getattr(record, "ip", "N/A")
|
if has_request_context():
|
||||||
record.method = getattr(record, "method", "N/A")
|
record.user = session.get("user_email", "Anonymous")
|
||||||
record.url = getattr(record, "url", "N/A")
|
record.ip = request.remote_addr
|
||||||
return super().format(record)
|
record.method = request.method
|
||||||
|
record.url = request.url
|
||||||
|
else:
|
||||||
|
record.user = "System"
|
||||||
|
record.ip = "N/A"
|
||||||
|
record.method = "N/A"
|
||||||
|
record.url = "N/A"
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class LoggerService:
|
class LoggerService:
|
||||||
@@ -22,18 +27,17 @@ class LoggerService:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def init_app(app):
|
def init_app(app):
|
||||||
|
|
||||||
# Create logs folder if not exists
|
|
||||||
if not os.path.exists("logs"):
|
if not os.path.exists("logs"):
|
||||||
os.makedirs("logs")
|
os.makedirs("logs")
|
||||||
|
|
||||||
formatter = RequestFormatter(
|
formatter = logging.Formatter(
|
||||||
"%(asctime)s | %(levelname)s | "
|
"%(asctime)s | %(levelname)s | "
|
||||||
"User:%(user)s | IP:%(ip)s | "
|
"User:%(user)s | IP:%(ip)s | "
|
||||||
"Method:%(method)s | URL:%(url)s | "
|
"Method:%(method)s | URL:%(url)s | "
|
||||||
"%(message)s"
|
"%(message)s"
|
||||||
)
|
)
|
||||||
|
|
||||||
# 🔹 INFO LOG
|
# INFO LOG
|
||||||
info_handler = RotatingFileHandler(
|
info_handler = RotatingFileHandler(
|
||||||
"logs/app.log",
|
"logs/app.log",
|
||||||
maxBytes=5 * 1024 * 1024,
|
maxBytes=5 * 1024 * 1024,
|
||||||
@@ -42,7 +46,7 @@ class LoggerService:
|
|||||||
info_handler.setLevel(logging.INFO)
|
info_handler.setLevel(logging.INFO)
|
||||||
info_handler.setFormatter(formatter)
|
info_handler.setFormatter(formatter)
|
||||||
|
|
||||||
# 🔹 ERROR LOG
|
# ERROR LOG
|
||||||
error_handler = RotatingFileHandler(
|
error_handler = RotatingFileHandler(
|
||||||
"logs/error.log",
|
"logs/error.log",
|
||||||
maxBytes=5 * 1024 * 1024,
|
maxBytes=5 * 1024 * 1024,
|
||||||
@@ -51,32 +55,25 @@ class LoggerService:
|
|||||||
error_handler.setLevel(logging.ERROR)
|
error_handler.setLevel(logging.ERROR)
|
||||||
error_handler.setFormatter(formatter)
|
error_handler.setFormatter(formatter)
|
||||||
|
|
||||||
# 🔹 CONSOLE LOG
|
# CONSOLE
|
||||||
console_handler = logging.StreamHandler()
|
console_handler = logging.StreamHandler()
|
||||||
console_handler.setLevel(logging.DEBUG)
|
console_handler.setLevel(logging.DEBUG)
|
||||||
console_handler.setFormatter(formatter)
|
console_handler.setFormatter(formatter)
|
||||||
|
|
||||||
|
# 🔹 ADD FILTER (important)
|
||||||
|
context_filter = RequestContextFilter()
|
||||||
|
|
||||||
|
info_handler.addFilter(context_filter)
|
||||||
|
error_handler.addFilter(context_filter)
|
||||||
|
console_handler.addFilter(context_filter)
|
||||||
|
|
||||||
app.logger.setLevel(logging.DEBUG)
|
app.logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
app.logger.addHandler(info_handler)
|
app.logger.addHandler(info_handler)
|
||||||
app.logger.addHandler(error_handler)
|
app.logger.addHandler(error_handler)
|
||||||
app.logger.addHandler(console_handler)
|
app.logger.addHandler(console_handler)
|
||||||
|
|
||||||
# Auto request logging
|
# Log every request automatically
|
||||||
@app.before_request
|
@app.before_request
|
||||||
def log_request():
|
def log_request():
|
||||||
app.logger.info(
|
app.logger.info("Request Started")
|
||||||
"Request Started",
|
|
||||||
extra=LoggerService.get_request_data()
|
|
||||||
)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_request_data():
|
|
||||||
try:
|
|
||||||
return {
|
|
||||||
"user": session.get("user_email", "Anonymous"),
|
|
||||||
"ip": request.remote_addr,
|
|
||||||
"method": request.method,
|
|
||||||
"url": request.url
|
|
||||||
}
|
|
||||||
except:
|
|
||||||
return {}
|
|
||||||
10
app/utils/regex_utils.py
Normal file
10
app/utils/regex_utils.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
class RegularExpression:
|
||||||
|
|
||||||
|
# sum field of pipe laying (pipe_150_mm)
|
||||||
|
PIPE_MM_PATTERN = re.compile(r"^pipe_\d+_mm$")
|
||||||
|
|
||||||
|
# sum fields of MH dc (d_0_to_0_75)
|
||||||
|
D_RANGE_PATTERN = re.compile( r"^d_\d+(?:_\d+)?_to_\d+(?:_\d+)?$")
|
||||||
|
|
||||||
Reference in New Issue
Block a user