From 646858aac33713e7105ddb437dc0971147727531 Mon Sep 17 00:00:00 2001 From: Midgard Date: Tue, 25 Feb 2020 17:51:53 +0100 Subject: [PATCH] Populate HLDS data version field --- app/hlds/definitions.py | 9 +++++++-- app/views/order.py | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/hlds/definitions.py b/app/hlds/definitions.py index 4267ff4..56d1182 100644 --- a/app/hlds/definitions.py +++ b/app/hlds/definitions.py @@ -2,15 +2,20 @@ from os import path from typing import List +import subprocess from .parser import parse_all_directory from .models import Location -__all__ = ["location_definitions"] +__all__ = ["location_definitions", "location_definition_version"] + +# pylint: disable=invalid-name # TODO Use proper way to get resources, see https://stackoverflow.com/a/10935674 DATA_DIR = path.join(path.dirname(__file__), "..", "..", "data") -# pylint: disable=invalid-name location_definitions: List[Location] = parse_all_directory(DATA_DIR) location_definitions.sort(key=lambda l: l.name) + +proc = subprocess.run(["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE, check=True) +location_definition_version = proc.stdout diff --git a/app/views/order.py b/app/views/order.py index aa67663..88e7fd3 100644 --- a/app/views/order.py +++ b/app/views/order.py @@ -11,7 +11,7 @@ from flask_login import current_user, login_required from forms import AnonOrderItemForm, OrderForm, OrderItemForm from models import Order, OrderItem, User, db -from hlds.definitions import location_definitions +from hlds.definitions import location_definitions, location_definition_version from notification import post_order_to_webhook from utils import ignore_none @@ -157,6 +157,7 @@ def order_item_create(order_id: int) -> typing.Any: item = OrderItem() form.populate_obj(item) + item.hlds_data_version = location_definition_version item.order_id = order_id if not current_user.is_anonymous(): item.user_id = current_user.id