Commit f4b19c3d authored by Jean-Baptiste Pasquier's avatar Jean-Baptiste Pasquier

Merge branch '187' into 'master'

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

See merge request !111
parents ff8c754c 263ef444
Pipeline #6616 passed with stage
in 1 minute and 22 seconds
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):
for class_name in model_classes:
model_class = model_classes[class_name]
......@@ -19,7 +28,7 @@ class DjangoldpConfig(AppConfig):
path = model_class.get_container_path().strip("/")
existing_source = LDPSource.objects.get(federation=path)
except LDPSource.DoesNotExist:
LDPSource.objects.create(federation=path, urlid=Model.absolute_url(model_class))
except OperationalError:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment