Commit 4849b1e3 authored by Jean-Baptiste's avatar Jean-Baptiste

refactor: don't reload for sources

parent d912786d
Pipeline #4823 passed with stage
in 1 minute and 21 seconds
......@@ -23,4 +23,4 @@ for class_name in model_classes:
if not admin.site.is_registered(model_class):
admin.site.register(model_class)
admin.site.register(LDPSource)
# admin.site.register(LDPSource)
......@@ -116,7 +116,7 @@ class Model(models.Model):
return [{'mode': {'@type': name.split('_')[0]}} for name in permissions]
class LDPSource(models.Model):
class LDPSource(Model):
container = models.URLField()
federation = models.CharField(max_length=255)
......
......@@ -4,8 +4,8 @@ from django.conf import settings
from django.conf.urls import url, include
from djangoldp.models import LDPSource, Model
from djangoldp.views import LDPSourceViewSet
from djangoldp.permissions import LDPPermissions
from djangoldp.views import LDPSourceViewSet
def __clean_path(path):
......@@ -17,7 +17,8 @@ def __clean_path(path):
urlpatterns = [
url(r'^sources/', LDPSourceViewSet.urls(model=LDPSource)),
url(r'^sources/(?P<federation>\w+)/', LDPSourceViewSet.urls(model=LDPSource, fields=['federation', 'container'],
permission_classes=[LDPPermissions], )),
]
for package in settings.DJANGOLDP_PACKAGES:
......
......@@ -278,24 +278,5 @@ class LDPSourceViewSet(LDPViewSet):
model = LDPSource
federation = None
@classonlymethod
def urls(cls, **kwargs):
try:
return include([url(name + '/', super(LDPSourceViewSet, cls).urls(federation=name, **kwargs))
for name in LDPSource.objects.order_by().values_list('federation', flat=True).distinct()])
except (OperationalError, ProgrammingError): # for the case where the table doesn't exist
return include([])
def get_queryset(self, *args, **kwargs):
return super().get_queryset(*args, **kwargs).filter(federation=self.federation)
@receiver([post_save, post_delete], sender=LDPSource)
def reload_sources_module(sender, instance, **kwargs):
urlconf = settings.ROOT_URLCONF
clear_url_caches()
if 'djangoldp.urls' in sys.modules:
reload(sys.modules['djangoldp.urls'])
if urlconf in sys.modules:
reload(sys.modules[urlconf])
return super().get_queryset(*args, **kwargs).filter(federation=self.kwargs['federation'])
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