PowerFeed.supply to slug (#3569)

This commit is contained in:
Jeremy Stretch 2019-11-25 21:08:34 -05:00
parent 62494f295e
commit bb8b012397
6 changed files with 48 additions and 15 deletions

View File

@ -699,8 +699,8 @@ class PowerFeedSerializer(TaggitSerializer, CustomFieldModelSerializer):
default=POWERFEED_STATUS_ACTIVE
)
supply = ChoiceField(
choices=POWERFEED_SUPPLY_CHOICES,
default=POWERFEED_SUPPLY_AC
choices=PowerFeedSupplyChoices,
default=PowerFeedSupplyChoices.SUPPLY_AC
)
phase = ChoiceField(
choices=POWERFEED_PHASE_CHOICES,

View File

@ -892,3 +892,19 @@ class PowerFeedTypeChoices(ChoiceSet):
TYPE_PRIMARY: 1,
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,
}

View File

@ -68,12 +68,6 @@ COMPATIBLE_TERMINATION_TYPES = {
}
# 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_3PHASE = 3
POWERFEED_PHASE_CHOICES = (

View File

@ -3865,7 +3865,7 @@ class PowerFeedCSVForm(forms.ModelForm):
help_text='Primary or redundant'
)
supply = CSVChoiceField(
choices=POWERFEED_SUPPLY_CHOICES,
choices=PowerFeedSupplyChoices,
required=False,
help_text='AC/DC'
)
@ -3942,7 +3942,7 @@ class PowerFeedBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEd
widget=StaticSelect2()
)
supply = forms.ChoiceField(
choices=add_blank_choice(POWERFEED_SUPPLY_CHOICES),
choices=add_blank_choice(PowerFeedSupplyChoices),
required=False,
initial='',
widget=StaticSelect2()
@ -4019,7 +4019,7 @@ class PowerFeedFilterForm(BootstrapMixin, CustomFieldFilterForm):
widget=StaticSelect2()
)
supply = forms.ChoiceField(
choices=add_blank_choice(POWERFEED_SUPPLY_CHOICES),
choices=add_blank_choice(PowerFeedSupplyChoices),
required=False,
widget=StaticSelect2()
)

View File

@ -6,6 +6,11 @@ POWERFEED_TYPE_CHOICES = (
(2, 'redundant'),
)
POWERFEED_SUPPLY_CHOICES = (
(1, 'ac'),
(2, 'dc'),
)
def powerfeed_type_to_slug(apps, schema_editor):
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)
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):
atomic = False
@ -22,7 +33,7 @@ class Migration(migrations.Migration):
operations = [
# Cable.type
# PowerFeed.type
migrations.AlterField(
model_name='powerfeed',
name='type',
@ -32,4 +43,14 @@ class Migration(migrations.Migration):
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
),
]

View File

@ -3112,12 +3112,14 @@ class PowerFeed(ChangeLoggedModel, CableTermination, CustomFieldModel):
default=POWERFEED_STATUS_ACTIVE
)
type = models.CharField(
max_length=50,
choices=PowerFeedTypeChoices,
default=PowerFeedTypeChoices.TYPE_PRIMARY
)
supply = models.PositiveSmallIntegerField(
choices=POWERFEED_SUPPLY_CHOICES,
default=POWERFEED_SUPPLY_AC
supply = models.CharField(
max_length=50,
choices=PowerFeedSupplyChoices,
default=PowerFeedSupplyChoices.SUPPLY_AC
)
phase = models.PositiveSmallIntegerField(
choices=POWERFEED_PHASE_CHOICES,