diff --git a/morango/migrations/0006_instanceidmodel_system_id.py b/morango/migrations/0006_instanceidmodel_system_id.py new file mode 100644 index 00000000..d4c5f863 --- /dev/null +++ b/morango/migrations/0006_instanceidmodel_system_id.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2017-06-30 00:15 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('morango', '0005_auto_20170629_2139'), + ] + + operations = [ + migrations.AddField( + model_name='instanceidmodel', + name='system_id', + field=models.CharField(blank=True, max_length=100), + ), + ] diff --git a/morango/models.py b/morango/models.py index 937857ba..9e6458bc 100644 --- a/morango/models.py +++ b/morango/models.py @@ -59,7 +59,7 @@ class InstanceIDModel(UUIDModelMixin): as well as its counter with all the records that were serialized at the time. """ - uuid_input_fields = ("platform", "hostname", "sysversion", "macaddress", "database_id", "db_path") + uuid_input_fields = ("platform", "hostname", "sysversion", "macaddress", "database_id", "db_path", "system_id") platform = models.TextField() hostname = models.TextField() @@ -69,18 +69,26 @@ class InstanceIDModel(UUIDModelMixin): counter = models.IntegerField(default=0) current = models.BooleanField(default=True) db_path = models.CharField(max_length=1000) + system_id = models.CharField(max_length=100, blank=True) @staticmethod def get_or_create_current_instance(): """Get the instance model corresponding to the current system, or create a new one if the system is new or its properties have changed (e.g. OS from upgrade).""" + # on Android, platform.platform() barfs, so we handle that safely here + try: + plat = platform.platform() + except: + plat = "Unknown (Android?)" + kwargs = { - "platform": platform.platform(), + "platform": plat, "hostname": platform.node(), "sysversion": sys.version, "database": DatabaseIDModel.objects.get(current=True), "db_path": os.path.abspath(settings.DATABASES['default']['NAME']), + "system_id": os.environ.get("MORANGO_SYSTEM_ID", ""), } # try to get the MAC address, but exclude it if it was a fake (random) address