12175 rack starting unit to svg

This commit is contained in:
Arthur 2023-05-31 11:40:47 -07:00
parent ec15336340
commit ba9ef11522
5 changed files with 15 additions and 6 deletions

View File

@ -221,8 +221,8 @@ class RackForm(TenancyForm, NetBoxModelForm):
model = Rack
fields = [
'site', 'location', 'name', 'facility_id', 'tenant_group', 'tenant', 'status', 'role', 'serial',
'asset_tag', 'type', 'width', 'u_height', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit',
'mounting_depth', 'weight', 'max_weight', 'weight_unit', 'description', 'comments', 'tags',
'asset_tag', 'type', 'width', 'u_height', 'starting_unit', 'desc_units', 'outer_width', 'outer_depth',
'outer_unit', 'mounting_depth', 'weight', 'max_weight', 'weight_unit', 'description', 'comments', 'tags',
]

View File

@ -274,8 +274,8 @@ class Rack(PrimaryModel, WeightMixin):
Return a list of unit numbers, top to bottom.
"""
if self.desc_units:
return drange(decimal.Decimal(1.0), self.u_height + 1, 0.5)
return drange(self.u_height + decimal.Decimal(0.5), 0.5, -0.5)
return drange(decimal.Decimal(self.starting_unit), self.u_height + 1, 0.5)
return drange(self.u_height + decimal.Decimal(0.5) + self.starting_unit - 1, 0.5 + self.starting_unit - 1, -0.5)
def get_status_color(self):
return RackStatusChoices.colors.get(self.status)

View File

@ -150,9 +150,9 @@ class RackElevationSVG:
x = self.legend_width + RACK_ELEVATION_BORDER_WIDTH
y = RACK_ELEVATION_BORDER_WIDTH
if self.rack.desc_units:
y += int((position - 1) * self.unit_height)
y += int((position - self.rack.starting_unit) * self.unit_height)
else:
y += int((self.rack.u_height - position + 1) * self.unit_height) - int(height * self.unit_height)
y += int((self.rack.u_height - position + self.rack.starting_unit) * self.unit_height) - int(height * self.unit_height)
return x, y
@ -237,6 +237,7 @@ class RackElevationSVG:
start_y = ru * self.unit_height + RACK_ELEVATION_BORDER_WIDTH
position_coordinates = (self.legend_width / 2, start_y + self.unit_height / 2 + RACK_ELEVATION_BORDER_WIDTH)
unit = ru + 1 if self.rack.desc_units else self.rack.u_height - ru
unit = unit + self.rack.starting_unit - 1
self.drawing.add(
Text(str(unit), position_coordinates, class_='unit')
)
@ -278,6 +279,7 @@ class RackElevationSVG:
for ru in range(0, self.rack.u_height):
unit = ru + 1 if self.rack.desc_units else self.rack.u_height - ru
unit = unit + self.rack.starting_unit - 1
y_offset = RACK_ELEVATION_BORDER_WIDTH + ru * self.unit_height
text_coords = (
x_offset + self.unit_width / 2,

View File

@ -101,6 +101,12 @@
<th scope="row">Height</th>
<td>{{ object.u_height }}U ({% if object.desc_units %}descending{% else %}ascending{% endif %})</td>
</tr>
<tr>
<th scope="row">Starting Unit</th>
<td>
{{ object.starting_unit }}
</td>
</tr>
<tr>
<th scope="row">Outer Width</th>
<td>

View File

@ -71,6 +71,7 @@
</div>
{% render_field form.mounting_depth %}
{% render_field form.desc_units %}
{% render_field form.starting_unit %}
</div>
{% if form.custom_fields %}