Skip to content
Snippets Groups Projects
Commit f4b19c3d authored by Jean-Baptiste Pasquier's avatar Jean-Baptiste Pasquier
Browse files

Merge branch '187' into 'master'

bugfix: Prevent automatic source creation be performed if DB was not migrated...

See merge request startinblox/djangoldp-packages/djangoldp!111
parents ff8c754c 263ef444
No related branches found
Tags v0.0.32
1 merge request!111bugfix: Prevent automatic source creation be performed if DB was not migrated...
Pipeline #1132 passed
from django.apps import AppConfig
from django.db import OperationalError
from django.db import OperationalError, connection
class DjangoldpConfig(AppConfig):
name = 'djangoldp'
......@@ -11,7 +10,17 @@ class DjangoldpConfig(AppConfig):
def create_local_source(self):
from djangoldp.models import LDPSource, Model
model_classes = {cls.__name__: cls for cls in Model.__subclasses__()}
model_classes = {}
db_tables = []
for cls in Model.__subclasses__():
model_classes[cls.__name__] = cls
db_tables.append(LDPSource.get_meta(cls, "db_table"))
# Check that all model's table already exists
existing_tables = connection.introspection.table_names()
if not all(db_table in existing_tables for db_table in db_tables):
return
for class_name in model_classes:
model_class = model_classes[class_name]
......@@ -19,7 +28,7 @@ class DjangoldpConfig(AppConfig):
continue
path = model_class.get_container_path().strip("/")
try:
existing_source = LDPSource.objects.get(federation=path)
LDPSource.objects.get(federation=path)
except LDPSource.DoesNotExist:
LDPSource.objects.create(federation=path, urlid=Model.absolute_url(model_class))
except OperationalError:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment