regular exp updated on model

This commit is contained in:
2026-03-17 18:02:28 +05:30
parent 96a3a79731
commit 5ddfb1f440
11 changed files with 25 additions and 135 deletions

View File

@@ -53,28 +53,13 @@ class ManholeDomesticChamber(db.Model):
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
# def sum_mh_dc_fields():
# return [
# "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_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_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_9_16_to_9_65"]
# ===============================
# AUTO TOTAL USING REGEX
# ===============================
def calculate_mh_dc_total(mapper, connection, target):
total = 0
for column in target.__table__.columns:
if RegularExpression.D_RANGE_PATTERN.match(column.name):
total += getattr(target, column.name) or 0
target.Total = total
event.listen(ManholeDomesticChamber, "before_insert", calculate_mh_dc_total)
event.listen(ManholeDomesticChamber, "before_update", calculate_mh_dc_total)