mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
PowerFeed.supply to slug (#3569)
This commit is contained in:
parent
62494f295e
commit
bb8b012397
@ -699,8 +699,8 @@ class PowerFeedSerializer(TaggitSerializer, CustomFieldModelSerializer):
|
|||||||
default=POWERFEED_STATUS_ACTIVE
|
default=POWERFEED_STATUS_ACTIVE
|
||||||
)
|
)
|
||||||
supply = ChoiceField(
|
supply = ChoiceField(
|
||||||
choices=POWERFEED_SUPPLY_CHOICES,
|
choices=PowerFeedSupplyChoices,
|
||||||
default=POWERFEED_SUPPLY_AC
|
default=PowerFeedSupplyChoices.SUPPLY_AC
|
||||||
)
|
)
|
||||||
phase = ChoiceField(
|
phase = ChoiceField(
|
||||||
choices=POWERFEED_PHASE_CHOICES,
|
choices=POWERFEED_PHASE_CHOICES,
|
||||||
|
@ -892,3 +892,19 @@ class PowerFeedTypeChoices(ChoiceSet):
|
|||||||
TYPE_PRIMARY: 1,
|
TYPE_PRIMARY: 1,
|
||||||
TYPE_REDUNDANT: 2,
|
TYPE_REDUNDANT: 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class PowerFeedSupplyChoices(ChoiceSet):
|
||||||
|
|
||||||
|
SUPPLY_AC = 'ac'
|
||||||
|
SUPPLY_DC = 'dc'
|
||||||
|
|
||||||
|
CHOICES = (
|
||||||
|
(SUPPLY_AC, 'Primary'),
|
||||||
|
(SUPPLY_DC, 'Redundant'),
|
||||||
|
)
|
||||||
|
|
||||||
|
LEGACY_MAP = {
|
||||||
|
SUPPLY_AC: 1,
|
||||||
|
SUPPLY_DC: 2,
|
||||||
|
}
|
||||||
|
@ -68,12 +68,6 @@ COMPATIBLE_TERMINATION_TYPES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Power feeds
|
# Power feeds
|
||||||
POWERFEED_SUPPLY_AC = 1
|
|
||||||
POWERFEED_SUPPLY_DC = 2
|
|
||||||
POWERFEED_SUPPLY_CHOICES = (
|
|
||||||
(POWERFEED_SUPPLY_AC, 'AC'),
|
|
||||||
(POWERFEED_SUPPLY_DC, 'DC'),
|
|
||||||
)
|
|
||||||
POWERFEED_PHASE_SINGLE = 1
|
POWERFEED_PHASE_SINGLE = 1
|
||||||
POWERFEED_PHASE_3PHASE = 3
|
POWERFEED_PHASE_3PHASE = 3
|
||||||
POWERFEED_PHASE_CHOICES = (
|
POWERFEED_PHASE_CHOICES = (
|
||||||
|
@ -3865,7 +3865,7 @@ class PowerFeedCSVForm(forms.ModelForm):
|
|||||||
help_text='Primary or redundant'
|
help_text='Primary or redundant'
|
||||||
)
|
)
|
||||||
supply = CSVChoiceField(
|
supply = CSVChoiceField(
|
||||||
choices=POWERFEED_SUPPLY_CHOICES,
|
choices=PowerFeedSupplyChoices,
|
||||||
required=False,
|
required=False,
|
||||||
help_text='AC/DC'
|
help_text='AC/DC'
|
||||||
)
|
)
|
||||||
@ -3942,7 +3942,7 @@ class PowerFeedBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEd
|
|||||||
widget=StaticSelect2()
|
widget=StaticSelect2()
|
||||||
)
|
)
|
||||||
supply = forms.ChoiceField(
|
supply = forms.ChoiceField(
|
||||||
choices=add_blank_choice(POWERFEED_SUPPLY_CHOICES),
|
choices=add_blank_choice(PowerFeedSupplyChoices),
|
||||||
required=False,
|
required=False,
|
||||||
initial='',
|
initial='',
|
||||||
widget=StaticSelect2()
|
widget=StaticSelect2()
|
||||||
@ -4019,7 +4019,7 @@ class PowerFeedFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
|||||||
widget=StaticSelect2()
|
widget=StaticSelect2()
|
||||||
)
|
)
|
||||||
supply = forms.ChoiceField(
|
supply = forms.ChoiceField(
|
||||||
choices=add_blank_choice(POWERFEED_SUPPLY_CHOICES),
|
choices=add_blank_choice(PowerFeedSupplyChoices),
|
||||||
required=False,
|
required=False,
|
||||||
widget=StaticSelect2()
|
widget=StaticSelect2()
|
||||||
)
|
)
|
||||||
|
@ -6,6 +6,11 @@ POWERFEED_TYPE_CHOICES = (
|
|||||||
(2, 'redundant'),
|
(2, 'redundant'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
POWERFEED_SUPPLY_CHOICES = (
|
||||||
|
(1, 'ac'),
|
||||||
|
(2, 'dc'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def powerfeed_type_to_slug(apps, schema_editor):
|
def powerfeed_type_to_slug(apps, schema_editor):
|
||||||
PowerFeed = apps.get_model('dcim', 'PowerFeed')
|
PowerFeed = apps.get_model('dcim', 'PowerFeed')
|
||||||
@ -13,6 +18,12 @@ def powerfeed_type_to_slug(apps, schema_editor):
|
|||||||
PowerFeed.objects.filter(type=id).update(type=slug)
|
PowerFeed.objects.filter(type=id).update(type=slug)
|
||||||
|
|
||||||
|
|
||||||
|
def powerfeed_supply_to_slug(apps, schema_editor):
|
||||||
|
PowerFeed = apps.get_model('dcim', 'PowerFeed')
|
||||||
|
for id, slug in POWERFEED_SUPPLY_CHOICES:
|
||||||
|
PowerFeed.objects.filter(supply=id).update(supply=slug)
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
atomic = False
|
atomic = False
|
||||||
|
|
||||||
@ -22,7 +33,7 @@ class Migration(migrations.Migration):
|
|||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
|
||||||
# Cable.type
|
# PowerFeed.type
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='powerfeed',
|
model_name='powerfeed',
|
||||||
name='type',
|
name='type',
|
||||||
@ -32,4 +43,14 @@ class Migration(migrations.Migration):
|
|||||||
code=powerfeed_type_to_slug
|
code=powerfeed_type_to_slug
|
||||||
),
|
),
|
||||||
|
|
||||||
|
# PowerFeed.supply
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='powerfeed',
|
||||||
|
name='supply',
|
||||||
|
field=models.CharField(blank=True, max_length=50),
|
||||||
|
),
|
||||||
|
migrations.RunPython(
|
||||||
|
code=powerfeed_supply_to_slug
|
||||||
|
),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
@ -3112,12 +3112,14 @@ class PowerFeed(ChangeLoggedModel, CableTermination, CustomFieldModel):
|
|||||||
default=POWERFEED_STATUS_ACTIVE
|
default=POWERFEED_STATUS_ACTIVE
|
||||||
)
|
)
|
||||||
type = models.CharField(
|
type = models.CharField(
|
||||||
|
max_length=50,
|
||||||
choices=PowerFeedTypeChoices,
|
choices=PowerFeedTypeChoices,
|
||||||
default=PowerFeedTypeChoices.TYPE_PRIMARY
|
default=PowerFeedTypeChoices.TYPE_PRIMARY
|
||||||
)
|
)
|
||||||
supply = models.PositiveSmallIntegerField(
|
supply = models.CharField(
|
||||||
choices=POWERFEED_SUPPLY_CHOICES,
|
max_length=50,
|
||||||
default=POWERFEED_SUPPLY_AC
|
choices=PowerFeedSupplyChoices,
|
||||||
|
default=PowerFeedSupplyChoices.SUPPLY_AC
|
||||||
)
|
)
|
||||||
phase = models.PositiveSmallIntegerField(
|
phase = models.PositiveSmallIntegerField(
|
||||||
choices=POWERFEED_PHASE_CHOICES,
|
choices=POWERFEED_PHASE_CHOICES,
|
||||||
|
Loading…
Reference in New Issue
Block a user