mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 13:32:15 +00:00
Compare commits
11 Commits
subhire
...
asset_fixe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b3dca04a2 | ||
|
|
3731c5bba0 | ||
|
|
61a46fa1c2 | ||
| dea628e7a2 | |||
|
|
171d5d633e | ||
|
|
294c839bc3 | ||
|
|
73e8bc3326 | ||
|
|
5a081a97c4 | ||
|
|
1f0dc9f1ae | ||
|
|
8ad0bdf5f3 | ||
|
faa86dbe8d
|
@@ -1,60 +0,0 @@
|
|||||||
# Generated by Django 2.0.13 on 2019-12-05 20:42
|
|
||||||
|
|
||||||
import re
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.migrations.operations.special
|
|
||||||
|
|
||||||
def forwards(apps, schema_editor):
|
|
||||||
AssetModel = apps.get_model('assets', 'Asset')
|
|
||||||
|
|
||||||
for row in AssetModel.objects.all():
|
|
||||||
|
|
||||||
row.asset_id = row.asset_id.upper()
|
|
||||||
asset_search = re.search("^([A-Z0-9]*?[A-Z]?)([0-9]+)$", row.asset_id)
|
|
||||||
if asset_search is None: # If the asset_id doesn't have a number at the end
|
|
||||||
row.asset_id += "1"
|
|
||||||
|
|
||||||
asset_search = re.search("^([A-Z0-9]*?[A-Z]?)([0-9]+)$", row.asset_id)
|
|
||||||
row.asset_id_prefix = asset_search.group(1)
|
|
||||||
row.asset_id_number = int(asset_search.group(2))
|
|
||||||
|
|
||||||
row.save(update_fields=['asset_id', 'asset_id_prefix', 'asset_id_number'])
|
|
||||||
|
|
||||||
# Functions from the following migrations need manual copying.
|
|
||||||
# Move them and any dependencies into this file, then update the
|
|
||||||
# RunPython operations to refer to the local versions:
|
|
||||||
# assets.migrations.0008_auto_20191205_1937
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
replaces = [('assets', '0008_auto_20191205_1937'), ('assets', '0009_auto_20191205_2041')]
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('assets', '0007_auto_20190108_0202_squashed_0014_auto_20191017_2052'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='asset',
|
|
||||||
name='asset_id_number',
|
|
||||||
field=models.IntegerField(default=1),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='asset',
|
|
||||||
name='asset_id_prefix',
|
|
||||||
field=models.CharField(default='', max_length=8),
|
|
||||||
),
|
|
||||||
migrations.RunPython(
|
|
||||||
code=forwards,
|
|
||||||
reverse_code=django.db.migrations.operations.special.RunPython.noop,
|
|
||||||
),
|
|
||||||
migrations.AlterModelOptions(
|
|
||||||
name='asset',
|
|
||||||
options={'ordering': ['asset_id_prefix', 'asset_id_number'], 'permissions': (('asset_finance', 'Can see financial data for assets'), ('view_asset', 'Can view an asset'))},
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='asset',
|
|
||||||
name='asset_id',
|
|
||||||
field=models.CharField(max_length=15, unique=True),
|
|
||||||
)
|
|
||||||
]
|
|
||||||
51
assets/migrations/0008_auto_20191206_2124.py
Normal file
51
assets/migrations/0008_auto_20191206_2124.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
# Generated by Django 2.0.13 on 2019-12-06 21:24
|
||||||
|
|
||||||
|
from django.db import migrations, models, transaction
|
||||||
|
import re
|
||||||
|
|
||||||
|
def forwards(apps, schema_editor):
|
||||||
|
AssetModel = apps.get_model('assets', 'Asset')
|
||||||
|
with transaction.atomic():
|
||||||
|
for row in AssetModel.objects.all():
|
||||||
|
|
||||||
|
row.asset_id = row.asset_id.upper()
|
||||||
|
asset_search = re.search("^([A-Z0-9]*?[A-Z]?)([0-9]+)$", row.asset_id)
|
||||||
|
if asset_search is None: # If the asset_id doesn't have a number at the end
|
||||||
|
row.asset_id += "1"
|
||||||
|
|
||||||
|
asset_search = re.search("^([A-Z0-9]*?[A-Z]?)([0-9]+)$", row.asset_id)
|
||||||
|
row.asset_id_prefix = asset_search.group(1)
|
||||||
|
row.asset_id_number = int(asset_search.group(2))
|
||||||
|
|
||||||
|
row.save(update_fields=['asset_id', 'asset_id_prefix', 'asset_id_number'])
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('assets', '0007_auto_20190108_0202_squashed_0014_auto_20191017_2052'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='asset',
|
||||||
|
options={'ordering': ['asset_id_prefix', 'asset_id_number'], 'permissions': (('asset_finance', 'Can see financial data for assets'), ('view_asset', 'Can view an asset'))},
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='asset',
|
||||||
|
name='asset_id_number',
|
||||||
|
field=models.IntegerField(default=1),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='asset',
|
||||||
|
name='asset_id_prefix',
|
||||||
|
field=models.CharField(default='', max_length=8),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='asset',
|
||||||
|
name='asset_id',
|
||||||
|
field=models.CharField(max_length=15, unique=True),
|
||||||
|
),
|
||||||
|
migrations.RunPython(
|
||||||
|
code=forwards,
|
||||||
|
reverse_code=migrations.operations.special.RunPython.noop,
|
||||||
|
),
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user