Populate HLDS data version field

This commit is contained in:
Midgard 2020-02-25 17:51:53 +01:00
parent a62e2bd9f7
commit 646858aac3
Signed by: midgard
GPG key ID: 511C112F1331BBB4
2 changed files with 9 additions and 3 deletions

View file

@ -2,15 +2,20 @@
from os import path from os import path
from typing import List from typing import List
import subprocess
from .parser import parse_all_directory from .parser import parse_all_directory
from .models import Location 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 # TODO Use proper way to get resources, see https://stackoverflow.com/a/10935674
DATA_DIR = path.join(path.dirname(__file__), "..", "..", "data") DATA_DIR = path.join(path.dirname(__file__), "..", "..", "data")
# pylint: disable=invalid-name
location_definitions: List[Location] = parse_all_directory(DATA_DIR) location_definitions: List[Location] = parse_all_directory(DATA_DIR)
location_definitions.sort(key=lambda l: l.name) 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

View file

@ -11,7 +11,7 @@ from flask_login import current_user, login_required
from forms import AnonOrderItemForm, OrderForm, OrderItemForm from forms import AnonOrderItemForm, OrderForm, OrderItemForm
from models import Order, OrderItem, User, db 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 notification import post_order_to_webhook
from utils import ignore_none from utils import ignore_none
@ -157,6 +157,7 @@ def order_item_create(order_id: int) -> typing.Any:
item = OrderItem() item = OrderItem()
form.populate_obj(item) form.populate_obj(item)
item.hlds_data_version = location_definition_version
item.order_id = order_id item.order_id = order_id
if not current_user.is_anonymous(): if not current_user.is_anonymous():
item.user_id = current_user.id item.user_id = current_user.id