diff --git a/vislib/models.py b/vislib/models.py index f545328..efba69f 100644 --- a/vislib/models.py +++ b/vislib/models.py @@ -3,67 +3,67 @@ from django.contrib.auth.models import User from django.utils import timezone def default_datetime(): - now = timezone.now() - return now + now = timezone.now() + return now class SourceDataBase(models.Model): - host = models.CharField(max_length=32) - port = models.IntegerField() - username = models.CharField(max_length=32) - password = models.CharField(max_length=256) - database = models.CharField(max_length=32) - base_alias = models.CharField(max_length=32) - creator = models.ForeignKey(User, on_delete=models.CASCADE) - source_id = models.CharField(max_length=64, primary_key=True) - is_private = models.BooleanField(default=True) - status = models.IntegerField(default=1) - created_at = models.DateTimeField(db_index=True, default=default_datetime) - updated_at = models.DateTimeField(db_index=True, null=False) + host = models.CharField(max_length=32) + port = models.IntegerField() + username = models.CharField(max_length=32) + password = models.CharField(max_length=256) + database = models.CharField(max_length=32) + base_alias = models.CharField(max_length=32) + creator = models.ForeignKey(User, on_delete=models.CASCADE) + source_id = models.CharField(max_length=64, primary_key=True) + is_private = models.BooleanField(default=True) + status = models.IntegerField(default=1) + created_at = models.DateTimeField(db_index=True, default=default_datetime) + updated_at = models.DateTimeField(db_index=True, null=False) class SourceDataTable(models.Model): - database = models.ForeignKey(SourceDataBase, on_delete=models.CASCADE) - table = models.CharField(max_length=32) - table_alias = models.CharField(max_length=32) - status = models.IntegerField(default=1) - creator = models.ForeignKey(User, on_delete=models.CASCADE) - id = models.CharField(max_length=64, primary_key=True) - created_at = models.DateTimeField(db_index=True, default=default_datetime) - updated_at = models.DateTimeField(db_index=True, null=False) + database = models.ForeignKey(SourceDataBase, on_delete=models.CASCADE) + table = models.CharField(max_length=32) + table_alias = models.CharField(max_length=32) + status = models.IntegerField(default=1) + creator = models.ForeignKey(User, on_delete=models.CASCADE) + id = models.CharField(max_length=64, primary_key=True) + created_at = models.DateTimeField(db_index=True, default=default_datetime) + updated_at = models.DateTimeField(db_index=True, null=False) # Create your models here. class Chart(models.Model): - chart_id = models.CharField(max_length=64, primary_key=True) - chart_name = models.CharField(max_length=128) - source_id = models.ForeignKey(SourceDataBase, on_delete=models.CASCADE) - desc = models.CharField(max_length=512, null=True) - content = models.TextField() - is_private = models.BooleanField() - status = models.IntegerField() - creator = models.ForeignKey(User, on_delete=models.CASCADE) - created_at = models.DateTimeField(db_index=True, default=default_datetime) - updated_at = models.DateTimeField(db_index=True, null=False) + chart_id = models.CharField(max_length=64, primary_key=True) + chart_name = models.CharField(max_length=128) + source_id = models.ForeignKey(SourceDataBase, on_delete=models.CASCADE) + desc = models.CharField(max_length=512, null=True) + content = models.TextField() + is_private = models.BooleanField() + status = models.IntegerField() + creator = models.ForeignKey(User, on_delete=models.CASCADE) + created_at = models.DateTimeField(db_index=True, default=default_datetime) + updated_at = models.DateTimeField(db_index=True, null=False) class Dashboard(models.Model): - dashboard_id = models.CharField(max_length=64, primary_key=True) - name = models.CharField(max_length=128) - desc = models.CharField(max_length=512, null=True) - content = models.TextField() - is_private = models.BooleanField() - status = models.IntegerField() - creator = models.ForeignKey(User, on_delete=models.CASCADE) - created_at = models.DateTimeField(db_index=True, default=default_datetime) - updated_at = models.DateTimeField(db_index=True, null=False) + dashboard_id = models.CharField(max_length=64, primary_key=True) + name = models.CharField(max_length=128) + desc = models.CharField(max_length=512, null=True) + content = models.TextField() + is_private = models.BooleanField() + status = models.IntegerField() + creator = models.ForeignKey(User, on_delete=models.CASCADE) + created_at = models.DateTimeField(db_index=True, default=default_datetime) + updated_at = models.DateTimeField(db_index=True, null=False) class ChartBoardMap(models.Model): - chart = models.ForeignKey(Chart, on_delete=models.CASCADE) - dashboard = models.ForeignKey(Dashboard, on_delete=models.CASCADE) - id = models.CharField(max_length=64, primary_key=True) - created_at = models.DateTimeField(db_index=True, default=default_datetime) - updated_at = models.DateTimeField(db_index=True, null=False) + chart = models.ForeignKey(Chart, on_delete=models.CASCADE) + dashboard = models.ForeignKey(Dashboard, on_delete=models.CASCADE) + id = models.CharField(max_length=64, primary_key=True) + created_at = models.DateTimeField(db_index=True, default=default_datetime) + updated_at = models.DateTimeField(db_index=True, null=False) class BoardOrder(models.Model): - creator = models.ForeignKey(User, on_delete=models.CASCADE) - order = models.TextField() - id = models.CharField(max_length=64, primary_key=True) - created_at = models.DateTimeField(db_index=True, default=default_datetime) - updated_at = models.DateTimeField(db_index=True, null=False) + creator = models.ForeignKey(User, on_delete=models.CASCADE) + order = models.TextField() + id = models.CharField(max_length=64, primary_key=True) + created_at = models.DateTimeField(db_index=True, default=default_datetime) + updated_at = models.DateTimeField(db_index=True, null=False) diff --git a/vislib/views/source.py b/vislib/views/source.py index e855313..c047514 100644 --- a/vislib/views/source.py +++ b/vislib/views/source.py @@ -93,14 +93,15 @@ def sourceDetail(request, sourceId): def sourceTables(request, sourceId): json_data = [] try: - tables = SourceDataTable.objects.get(database=sourceId) - tables = serializers.serialize('json', [tables]) + tables = SourceDataTable.objects.filter(database=sourceId) + + tables = serializers.serialize('json', tables) tables = json.loads(tables) for table in tables: json_data.append(table['fields']) - except: - print('no linked tables before') + except Exception as e: + print('no linked tables before', e) source = SourceDataBase.objects.get(source_id=sourceId) source = serializers.serialize('json', [source]) @@ -161,17 +162,15 @@ def sourceTableSave(request): @csrf_exempt def sourceLinkedTables(request, sourceId): try: - tables = SourceDataTable.objects.get(database=sourceId) - print(tables) - tables = serializers.serialize('json', [tables]) - print(tables) + tables = SourceDataTable.objects.filter(database=sourceId) + tables = serializers.serialize('json', tables) tables = json.loads(tables) - print(tables) json_data = [] for table in tables: json_data.append(table['fields']) - except: + except Exception as e: json_data = [] + printz(e) return JsonResponse({'code': 20000, 'message': 'success', 'data': json_data })