forked from openwisp/openwisp-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrated Device model changes from django-netjsonconfig openwisp#7
Closes openwisp#7
- Loading branch information
1 parent
82b768e
commit 714fd5f
Showing
14 changed files
with
345 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
openwisp_controller/config/migrations/0004_add_device_model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.5 on 2017-05-11 18:29 | ||
from __future__ import unicode_literals | ||
|
||
import django.core.validators | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
import django_netjsonconfig.utils | ||
import model_utils.fields | ||
import re | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('openwisp_users', '0001_initial'), | ||
('config', '0003_template_tags'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Device', | ||
fields=[ | ||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
('name', models.CharField(max_length=64, unique=True)), | ||
('mac_address', models.CharField(help_text='primary mac address', max_length=17, unique=True, validators=[django.core.validators.RegexValidator(re.compile('^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})', 32), code='invalid', message='Must be a valid mac address.')])), | ||
('key', models.CharField(db_index=True, default=django_netjsonconfig.utils.get_random_key, help_text='unique device key', max_length=64, unique=True, validators=[django.core.validators.RegexValidator(re.compile('^[^\\s/\\.]+$', 32), code='invalid', message='Key must not contain spaces, dots or slashes.')])), | ||
('model', models.CharField(blank=True, help_text='device model and manufacturer', max_length=64)), | ||
('os', models.CharField(blank=True, help_text='operating system identifier', max_length=128, verbose_name='operating system')), | ||
('notes', models.TextField(blank=True)), | ||
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), | ||
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), | ||
('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='openwisp_users.Organization', verbose_name='organization')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name='config', | ||
name='device', | ||
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='config.Device'), | ||
), | ||
] |
38 changes: 38 additions & 0 deletions
38
openwisp_controller/config/migrations/0005_populate_device.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def forward(apps, schema_editor): | ||
""" | ||
Creates a Device record for each existing Config | ||
TODO: delete this migration in future releases | ||
""" | ||
if not schema_editor.connection.alias == 'default': | ||
return | ||
Device = apps.get_model('config', 'Device') | ||
Config = apps.get_model('config', 'Config') | ||
|
||
for config in Config.objects.all(): | ||
device = Device(id=config.id, | ||
organization=config.organization, | ||
name=config.name, | ||
mac_address=config.mac_address, | ||
key=config.key, | ||
created=config.created, | ||
modified=config.modified) | ||
device.full_clean() | ||
device.save() | ||
config.device = device | ||
config.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('config', '0004_add_device_model'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(forward, reverse_code=migrations.RunPython.noop), | ||
] |
21 changes: 21 additions & 0 deletions
21
openwisp_controller/config/migrations/0006_config_device_not_null.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.5 on 2017-05-11 18:35 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('config', '0005_populate_device'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='config', | ||
name='device', | ||
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='config.Device'), | ||
), | ||
] |
27 changes: 27 additions & 0 deletions
27
openwisp_controller/config/migrations/0007_simplify_config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.5 on 2017-05-11 18:41 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('config', '0006_config_device_not_null'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='config', | ||
name='name', | ||
), | ||
migrations.RemoveField( | ||
model_name='config', | ||
name='key', | ||
), | ||
migrations.RemoveField( | ||
model_name='config', | ||
name='mac_address', | ||
), | ||
] |
Oops, something went wrong.