Refactor brand and item models to introduce 'identifier' property for consistency; update dropdown rendering in templates to utilize new properties and improve input handling.
This commit is contained in:
parent
8631e4082c
commit
9242ce6eab
5 changed files with 52 additions and 58 deletions
|
@ -107,3 +107,7 @@ class Brand(ValidatableMixin, db.Model):
|
||||||
errors.append(f"Area entry #{index + 1} has invalid ID: {raw_id}")
|
errors.append(f"Area entry #{index + 1} has invalid ID: {raw_id}")
|
||||||
|
|
||||||
return errors
|
return errors
|
||||||
|
|
||||||
|
@property
|
||||||
|
def identifier(self) -> str:
|
||||||
|
return self.name if self.name else f"ID: {self.id}"
|
||||||
|
|
|
@ -42,6 +42,7 @@ class Inventory(db.Model, ImageAttachable):
|
||||||
item: Mapped['Item'] = relationship('Item', back_populates='inventory')
|
item: Mapped['Item'] = relationship('Item', back_populates='inventory')
|
||||||
work_logs: Mapped[List['WorkLog']] = relationship('WorkLog', back_populates='work_item')
|
work_logs: Mapped[List['WorkLog']] = relationship('WorkLog', back_populates='work_item')
|
||||||
image: Mapped[Optional['Image']] = relationship('Image', back_populates='inventory', passive_deletes=True)
|
image: Mapped[Optional['Image']] = relationship('Image', back_populates='inventory', passive_deletes=True)
|
||||||
|
type: Mapped[Optional['Item']] = relationship('Item', back_populates='inventory')
|
||||||
|
|
||||||
def __init__(self, timestamp: datetime.datetime, condition: str, type_id: Optional[int] = None,
|
def __init__(self, timestamp: datetime.datetime, condition: str, type_id: Optional[int] = None,
|
||||||
name: Optional[str] = None, serial: Optional[str] = None,
|
name: Optional[str] = None, serial: Optional[str] = None,
|
||||||
|
|
|
@ -20,10 +20,9 @@ class Item(ValidatableMixin, db.Model):
|
||||||
|
|
||||||
def __init__(self, description: Optional[str] = None, category: Optional[str] = None):
|
def __init__(self, description: Optional[str] = None, category: Optional[str] = None):
|
||||||
self.description = description
|
self.description = description
|
||||||
self.category = category
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Item(id={self.id}, description={repr(self.description)}, category={repr(self.category)})>"
|
return f"<Item(id={self.id}, description={repr(self.description)})>"
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
return {
|
return {
|
||||||
|
@ -32,6 +31,10 @@ class Item(ValidatableMixin, db.Model):
|
||||||
'category': self.category
|
'category': self.category
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def identifier(self):
|
||||||
|
return self.description if self.description else f"Item {self.id}"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def sync_from_state(cls, submitted_items: list[dict]) -> dict[str, int]:
|
def sync_from_state(cls, submitted_items: list[dict]) -> dict[str, int]:
|
||||||
submitted_clean = []
|
submitted_clean = []
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<button class="btn btn-outline-dark dropdown-toggle w-100" type="button" data-bs-toggle="dropdown"
|
<button class="btn btn-outline-dark dropdown-toggle w-100" type="button" data-bs-toggle="dropdown"
|
||||||
data-inv-value="{{ current_item.id if current_item else '' }}" id="{{ id }}Button"{% if not enabled %} disabled{% endif %}
|
data-inv-value="{{ current_item.id if current_item else '' }}" id="{{ id }}Button"{% if not enabled %} disabled{% endif %}
|
||||||
style="border-color: rgb(222, 226, 230);{% if not enabled %}background-color: rgb(233, 236, 239); color: rgb(0, 0, 0);{% endif %}">
|
style="border-color: rgb(222, 226, 230);{% if not enabled %} background-color: rgb(233, 236, 239); color: rgb(0, 0, 0);{% endif %}">
|
||||||
{{ current_item.identifier if current_item else '-' }}
|
{{ current_item.identifier if current_item else '-' }}
|
||||||
</button>
|
</button>
|
||||||
<input type="hidden" name="{{ id }}" id="{{ id }}" value="{{ current_item.id if current_item else '' }}">
|
<input type="hidden" name="{{ id }}" id="{{ id }}" value="{{ current_item.id if current_item else '' }}">
|
||||||
|
|
|
@ -10,14 +10,14 @@
|
||||||
const payload = {
|
const payload = {
|
||||||
timestamp: document.querySelector("input[name='timestamp']").value,
|
timestamp: document.querySelector("input[name='timestamp']").value,
|
||||||
condition: document.querySelector("select[name='condition']").value,
|
condition: document.querySelector("select[name='condition']").value,
|
||||||
type_id: parseInt(document.querySelector("select[name='type']").value),
|
type_id: parseInt(document.querySelector("input[name='type']").value),
|
||||||
name: document.querySelector("input[name='name']").value || null,
|
name: document.querySelector("input[name='name']").value || null,
|
||||||
serial: document.querySelector("input[name='serial']").value || null,
|
serial: document.querySelector("input[name='serial']").value || null,
|
||||||
model: document.querySelector("input[name='model']").value || null,
|
model: document.querySelector("input[name='model']").value || null,
|
||||||
notes: document.querySelector("textarea[name='editornotes']").value || null,
|
notes: document.querySelector("textarea[name='editornotes']").value || null,
|
||||||
owner_id: parseInt(document.querySelector("select#userList").value) || null,
|
owner_id: parseInt(document.querySelector("input[name='owner']").value) || null,
|
||||||
brand_id: parseInt(document.querySelector("select[name='brand']").value) || null,
|
brand_id: parseInt(document.querySelector("input[name='brand']").value) || null,
|
||||||
location_id: parseInt(document.querySelector("select#room").value) || null,
|
location_id: parseInt(document.querySelector("input[name='room']").value) || null,
|
||||||
barcode: document.querySelector("input[name='barcode']").value || null,
|
barcode: document.querySelector("input[name='barcode']").value || null,
|
||||||
shared: document.querySelector("input[name='shared']").checked
|
shared: document.querySelector("input[name='shared']").checked
|
||||||
};
|
};
|
||||||
|
@ -167,16 +167,13 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
<label for="brand" class="form-label">Brand</label>
|
{{ dropdowns.render_dropdown(
|
||||||
<select class="form-select" id="brand" name="brand" {% if item.condition in ["Removed", "Disposed" ]
|
id='brand',
|
||||||
%} disabled{% endif %}>
|
list=brands,
|
||||||
<option>-</option>
|
label='Brand',
|
||||||
{% for brand in brands %}
|
current_item=item.brand,
|
||||||
<option value="{{ brand.id }}" {% if brand.id==item.brand_id %} selected{% endif %}>{{
|
enabled=item.condition not in ["Removed", "Disposed"]
|
||||||
brand.name }}
|
) }}
|
||||||
</option>
|
|
||||||
{% endfor %}
|
|
||||||
</select>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
<label for="model" class="form-label">Model</label>
|
<label for="model" class="form-label">Model</label>
|
||||||
|
@ -185,45 +182,34 @@
|
||||||
%} disabled{% endif %}>
|
%} disabled{% endif %}>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
<label for="type" class="form-label">Category</label>
|
{{ dropdowns.render_dropdown(
|
||||||
<select name="type" id="type" class="form-select" {% if item.condition in ["Removed", "Disposed" ]
|
id='type',
|
||||||
%} disabled{% endif %}>
|
list=types,
|
||||||
<option>-</option>
|
label='Category',
|
||||||
{% for t in types %}
|
current_item=item.type,
|
||||||
<option value="{{ t.id }}" {% if t.id==item.type_id %} selected{% endif %}>{{ t.description }}
|
enabled=item.condition not in ["Removed", "Disposed"]
|
||||||
</option>
|
) }}
|
||||||
{% endfor %}
|
|
||||||
</select>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
<label for="owner" class="form-label">
|
{{ dropdowns.render_dropdown(
|
||||||
Contact
|
id='owner',
|
||||||
{% if item.owner %}
|
list=users,
|
||||||
{{ links.entry_link('user', item.owner_id) }}
|
label='Contact',
|
||||||
{% endif %}
|
current_item=item.owner,
|
||||||
</label>
|
entry_link='user',
|
||||||
<select class="form-select" id="userList" {% if item.condition in ["Removed", "Disposed" ] %}
|
enabled=item.condition not in ["Removed", "Disposed"]
|
||||||
disabled{% endif %}>
|
) }}
|
||||||
<option>-</option>
|
|
||||||
{% for user in users %}
|
|
||||||
<option value="{{ user.id }}" {% if user.id==item.owner_id %} selected{% endif %}>{{
|
|
||||||
user.identifier
|
|
||||||
}}</option>
|
|
||||||
{% endfor %}
|
|
||||||
</select>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
<label for="location" class="form-label">Location</label>
|
{{ dropdowns.render_dropdown(
|
||||||
<select class="form-select" id="room" {% if item.condition in ["Removed", "Disposed" ] %} disabled{%
|
id='room',
|
||||||
endif %}>
|
list=rooms,
|
||||||
<option>-</option>
|
label='Location',
|
||||||
{% for room in rooms %}
|
current_item=item.location,
|
||||||
<option value="{{ room.id }}" {% if room.id==item.location_id %} selected{% endif %}>{{
|
enabled=item.condition not in ["Removed", "Disposed"]
|
||||||
room.identifier }}</option>
|
) }}
|
||||||
{% endfor %}
|
|
||||||
</select>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-2">
|
<div class="col-2">
|
||||||
<label for="condition" class="form-label">Condition</label>
|
<label for="condition" class="form-label">Condition</label>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue