applications: move get_object_types function in models.py (#71251)
This commit is contained in:
parent
cc5e852abc
commit
7116603575
|
@ -37,6 +37,27 @@ from .utils import Requests
|
|||
requests = Requests()
|
||||
|
||||
|
||||
def get_object_types():
|
||||
object_types = []
|
||||
for service_id, services in getattr(settings, 'KNOWN_SERVICES', {}).items():
|
||||
if service_id not in Application.SUPPORTED_MODULES:
|
||||
continue
|
||||
service_objects = {x.get_base_url_path(): x for x in get_installed_services(types=[service_id])}
|
||||
for service in services.values():
|
||||
if service['url'] not in service_objects:
|
||||
continue
|
||||
if service_objects[service['url']].secondary:
|
||||
continue
|
||||
url = urllib.parse.urljoin(service['url'], 'api/export-import/')
|
||||
response = requests.get(url)
|
||||
if not response.ok:
|
||||
continue
|
||||
for object_type in response.json()['data']:
|
||||
object_type['service'] = service
|
||||
object_types.append(object_type)
|
||||
return object_types
|
||||
|
||||
|
||||
class ApplicationError(Exception):
|
||||
def __init__(self, msg):
|
||||
self.msg = msg
|
||||
|
|
|
@ -18,9 +18,7 @@ import dataclasses
|
|||
import io
|
||||
import json
|
||||
import tarfile
|
||||
import urllib.parse
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.files.base import ContentFile
|
||||
from django.db.models import Prefetch
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
|
@ -31,10 +29,8 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from django.views.generic import DetailView, FormView, ListView, TemplateView
|
||||
from django.views.generic.edit import CreateView, DeleteView, UpdateView
|
||||
|
||||
from hobo.environment.utils import get_installed_services
|
||||
|
||||
from .forms import GenerateForm, InstallForm, MetadataForm
|
||||
from .models import Application, AsyncJob, Element, Relation, Version
|
||||
from .models import Application, AsyncJob, Element, Relation, Version, get_object_types
|
||||
from .utils import Requests
|
||||
|
||||
requests = Requests()
|
||||
|
@ -63,27 +59,6 @@ class InitView(CreateView):
|
|||
init = InitView.as_view()
|
||||
|
||||
|
||||
def get_object_types():
|
||||
object_types = []
|
||||
for service_id, services in getattr(settings, 'KNOWN_SERVICES', {}).items():
|
||||
if service_id not in Application.SUPPORTED_MODULES:
|
||||
continue
|
||||
service_objects = {x.get_base_url_path(): x for x in get_installed_services(types=[service_id])}
|
||||
for service in services.values():
|
||||
if service['url'] not in service_objects:
|
||||
continue
|
||||
if service_objects[service['url']].secondary:
|
||||
continue
|
||||
url = urllib.parse.urljoin(service['url'], 'api/export-import/')
|
||||
response = requests.get(url)
|
||||
if not response.ok:
|
||||
continue
|
||||
for object_type in response.json()['data']:
|
||||
object_type['service'] = service
|
||||
object_types.append(object_type)
|
||||
return object_types
|
||||
|
||||
|
||||
class ManifestView(TemplateView):
|
||||
template_name = 'hobo/applications/manifest.html'
|
||||
|
||||
|
|
Loading…
Reference in New Issue