v1_api.register(ExperimentParameterSetResource()) v1_api.register(ExperimentResource()) v1_api.register(LocationResource()) v1_api.register(ParameterNameResource()) v1_api.register(ReplicaResource()) v1_api.register(SchemaResource()) v1_api.register(StorageBoxResource()) v1_api.register(StorageBoxOptionResource()) v1_api.register(StorageBoxAttributeResource()) v1_api.register(UserResource()) v1_api.register(GroupResource()) v1_api.register(ObjectACLResource()) v1_api.register(FacilityResource()) v1_api.register(InstrumentResource()) for app_name, app in get_tardis_apps(): try: app_api = import_module('%s.api' % app) for res_name in dir(app_api): if not res_name.endswith('AppResource'): continue resource = getattr(app_api, res_name) if not issubclass(resource, Resource): continue resource_name = resource._meta.resource_name if not resource_name.startswith(app_name): resource._meta.resource_name = '%s_%s' % ( format_app_name_for_url(app_name), resource_name) v1_api.register(resource()) except ImportError as e: logger.debug('App API URLs import error: %s' % str(e))
v1_api.register(ExperimentResource()) v1_api.register(ExperimentAuthorResource()) v1_api.register(LocationResource()) v1_api.register(ParameterNameResource()) v1_api.register(ReplicaResource()) v1_api.register(SchemaResource()) v1_api.register(StorageBoxResource()) v1_api.register(StorageBoxOptionResource()) v1_api.register(StorageBoxAttributeResource()) v1_api.register(UserResource()) v1_api.register(GroupResource()) v1_api.register(ObjectACLResource()) v1_api.register(FacilityResource()) v1_api.register(InstrumentResource()) for app_name, app in get_tardis_apps(): try: app_api = import_module('%s.api' % app) for res_name in dir(app_api): if not res_name.endswith('AppResource'): continue resource = getattr(app_api, res_name) if not issubclass(resource, Resource): continue resource_name = resource._meta.resource_name if not resource_name.startswith(app_name): resource._meta.resource_name = '%s_%s' % ( format_app_name_for_url(app_name), resource_name) v1_api.register(resource()) except ImportError as e: logger.debug('App API URLs import error: %s' % str(e))
def get_context_data(self, request, experiment, **kwargs): """ Prepares the values to be passed to the default experiment view, respecting authorization rules. Returns a dict of values (the context). :param request: a HTTP request object :type request: :class:`django.http.HttpRequest` :param experiment: the experiment model instance :type experiment: tardis.tardis_portal.models.experiment.Experiment :return: A dictionary of values for the view/template. :rtype: dict """ c = super(ExperimentView, self).get_context_data(**kwargs) c['experiment'] = experiment c['has_write_permissions'] = \ authz.has_write_permissions(request, experiment.id) c['has_download_permissions'] = \ authz.has_experiment_download_access(request, experiment.id) if request.user.is_authenticated(): c['is_owner'] = authz.has_experiment_ownership(request, experiment.id) c['has_read_or_owner_ACL'] = authz.has_read_or_owner_ACL(request, experiment.id) # Enables UI elements for the publication form c['pub_form_enabled'] = 'tardis.apps.publication_forms' in \ settings.INSTALLED_APPS # Enables UI elements for the push_to app c['push_to_enabled'] = PushToConfig.name in settings.INSTALLED_APPS if c['push_to_enabled']: push_to_args = { 'experiment_id': experiment.pk } c['push_to_url'] = reverse(initiate_push_experiment, kwargs=push_to_args) c['subtitle'] = experiment.title c['nav'] = [{'name': 'Data', 'link': '/experiment/view/'}, {'name': experiment.title, 'link': experiment.get_absolute_url()}] if 'status' in request.POST: c['status'] = request.POST['status'] if 'error' in request.POST: c['error'] = request.POST['error'] if 'query' in request.GET: c['search_query'] = SearchQueryString(request.GET['query']) if 'search' in request.GET: c['search'] = request.GET['search'] if 'load' in request.GET: c['load'] = request.GET['load'] _add_protocols_and_organizations(request, experiment, c) default_apps = [ {'name': 'Description', 'viewfn': 'tardis.tardis_portal.views.experiment_description'}, {'name': 'Metadata', 'viewfn': 'tardis.tardis_portal.views.retrieve_experiment_metadata'}, {'name': 'Sharing', 'viewfn': 'tardis.tardis_portal.views.share'}, {'name': 'Transfer Datasets', 'viewfn': 'tardis.tardis_portal.views.experiment_dataset_transfer'}, ] appnames = [] appurls = [] for app in getattr(settings, 'EXPERIMENT_APPS', default_apps): try: appnames.append(app['name']) if 'viewfn' in app: appurls.append(reverse(app['viewfn'], args=[experiment.id])) elif 'url' in app: appurls.append(app['url']) except: logger.debug('error when loading default exp apps') from tardis.app_config import get_tardis_apps for app_name, app in get_tardis_apps(): try: appnames.append( sys.modules['%s.settings' % app].NAME) appurls.append( reverse('%s.views.index' % app, args=[experiment.id])) except: logger.debug("No tab for %s" % app) c['apps'] = zip(appurls, appnames) return c
def get_context_data(self, request, experiment, **kwargs): """ Prepares the values to be passed to the default experiment view, respecting authorization rules. Returns a dict of values (the context). :param request: a HTTP request object :type request: :class:`django.http.HttpRequest` :param experiment: the experiment model instance :type experiment: tardis.tardis_portal.models.experiment.Experiment :return: A dictionary of values for the view/template. :rtype: dict """ c = super(ExperimentView, self).get_context_data(**kwargs) c['experiment'] = experiment c['has_write_permissions'] = \ authz.has_write_permissions(request, experiment.id) c['has_download_permissions'] = \ authz.has_experiment_download_access(request, experiment.id) if request.user.is_authenticated(): c['is_owner'] = authz.has_experiment_ownership( request, experiment.id) c['has_read_or_owner_ACL'] = authz.has_read_or_owner_ACL( request, experiment.id) # Enables UI elements for the publication form c['pub_form_enabled'] = 'tardis.apps.publication_forms' in \ settings.INSTALLED_APPS # Enables UI elements for the push_to app c['push_to_enabled'] = PushToConfig.name in settings.INSTALLED_APPS if c['push_to_enabled']: push_to_args = {'experiment_id': experiment.pk} c['push_to_url'] = reverse(initiate_push_experiment, kwargs=push_to_args) c['subtitle'] = experiment.title c['nav'] = [{ 'name': 'Data', 'link': '/experiment/view/' }, { 'name': experiment.title, 'link': experiment.get_absolute_url() }] if 'status' in request.POST: c['status'] = request.POST['status'] if 'error' in request.POST: c['error'] = request.POST['error'] if 'query' in request.GET: c['search_query'] = SearchQueryString(request.GET['query']) if 'search' in request.GET: c['search'] = request.GET['search'] if 'load' in request.GET: c['load'] = request.GET['load'] _add_protocols_and_organizations(request, experiment, c) default_apps = [ { 'name': 'Description', 'viewfn': 'tardis.tardis_portal.views.experiment_description' }, { 'name': 'Metadata', 'viewfn': 'tardis.tardis_portal.views.retrieve_experiment_metadata' }, { 'name': 'Sharing', 'viewfn': 'tardis.tardis_portal.views.share' }, { 'name': 'Transfer Datasets', 'viewfn': 'tardis.tardis_portal.views.experiment_dataset_transfer' }, ] appnames = [] appurls = [] for app in getattr(settings, 'EXPERIMENT_APPS', default_apps): try: appnames.append(app['name']) if 'viewfn' in app: appurls.append(reverse(app['viewfn'], args=[experiment.id])) elif 'url' in app: appurls.append(app['url']) except: logger.debug('error when loading default exp apps') from tardis.app_config import get_tardis_apps for app_name, app in get_tardis_apps(): try: appnames.append(sys.modules['%s.settings' % app].NAME) appurls.append( reverse('%s.views.index' % app, args=[experiment.id])) except: logger.debug("No tab for %s" % app) c['apps'] = zip(appurls, appnames) return c