def general(request): initial_data = _intial_settings_data() initial_data['storage_service_use_default_config'] = { 'False': False}.get( initial_data.get('storage_service_use_default_config', True), True) general_form = GeneralSettingsForm(request.POST or None, prefix='general', initial=initial_data) storage_form = StorageSettingsForm(request.POST or None, prefix='storage', initial=initial_data) checksum_form = ChecksumSettingsForm(request.POST or None, prefix='checksum algorithm', initial=initial_data) forms = (general_form, storage_form, checksum_form) if all(map(lambda form: form.is_valid(), forms)): map(lambda form: form.save(), forms) messages.info(request, _('Saved.')) dashboard_uuid = helpers.get_setting('dashboard_uuid') not_created_yet = False try: pipeline = storage_service.get_pipeline(dashboard_uuid) except Exception as err: if err.response is not None and err.response.status_code == 404: # The server has returned a 404, we're going to assume that this is # the Storage Service telling us that the pipeline is unknown. not_created_yet = True else: messages.warning(request, _('Storage Service inaccessible. Please' ' contact an administrator or update' ' the Storage Sevice URL below.' '<hr />%(error)s' % {'error': err})) if not_created_yet: if storage_form.is_valid(): try: setup_pipeline_in_ss( storage_form.cleaned_data[ 'storage_service_use_default_config']) except Exception as err: messages.warning(request, _('Storage Service failed to create the' ' pipeline. This can happen if' ' the pipeline exists but it is' ' disabled. Please contact an' ' administrator.' '<hr />%(error)s' % {'error': err})) else: messages.warning(request, _('Storage Service returned a 404 error.' ' Has the pipeline been disabled or is' ' it not registered yet? Submitting' ' form will attempt to register the' ' pipeline.')) return render(request, 'administration/general.html', locals())
def setup_pipeline_in_ss(use_default_config=False): # Check if pipeline is already registered on SS dashboard_uuid = helpers.get_setting("dashboard_uuid") try: storage_service.get_pipeline(dashboard_uuid) except Exception: logger.warning("SS inaccessible or pipeline not registered.") else: # If pipeline is already registered on SS, then exit logger.warning("This pipeline is already configured on SS.") return if not use_default_config: # Storage service manually set up, just register Pipeline if # possible. Do not provide additional information about the shared # path, or API, as this is probably being set up in the storage # service manually. storage_service.create_pipeline() return # Post first user & API key user = User.objects.all()[0] api_key = ApiKey.objects.get(user=user) # Retrieve remote name try: setting = DashboardSetting.objects.get(name="site_url") except DashboardSetting.DoesNotExist: remote_name = None else: remote_name = setting.value # Create pipeline, tell it to use default setup storage_service.create_pipeline( create_default_locations=True, shared_path=django_settings.SHARED_DIRECTORY, remote_name=remote_name, api_username=user.username, api_key=api_key.key, )
def general(request): initial_data = _intial_settings_data() initial_data["storage_service_use_default_config"] = {"False": False}.get( initial_data.get("storage_service_use_default_config", True), True ) general_form = GeneralSettingsForm( request.POST or None, prefix="general", initial=initial_data ) storage_form = StorageSettingsForm( request.POST or None, prefix="storage", initial=initial_data ) checksum_form = ChecksumSettingsForm( request.POST or None, prefix="checksum algorithm", initial=initial_data ) forms = (general_form, storage_form, checksum_form) if all(map(lambda form: form.is_valid(), forms)): for item in forms: item.save() messages.info(request, _("Saved.")) dashboard_uuid = helpers.get_setting("dashboard_uuid") not_created_yet = False try: pipeline = storage_service.get_pipeline(dashboard_uuid) except Exception as err: if err.response is not None and err.response.status_code == 404: # The server has returned a 404, we're going to assume that this is # the Storage Service telling us that the pipeline is unknown. not_created_yet = True else: messages.warning( request, _( "Storage Service inaccessible. Please" " contact an administrator or update" " the Storage Sevice URL below." "<hr />%(error)s" % {"error": err} ), ) if not_created_yet: if storage_form.is_valid(): try: setup_pipeline_in_ss( storage_form.cleaned_data["storage_service_use_default_config"] ) except Exception as err: messages.warning( request, _( "Storage Service failed to create the" " pipeline. This can happen if" " the pipeline exists but it is" " disabled. Please contact an" " administrator." "<hr />%(error)s" % {"error": err} ), ) else: messages.warning( request, _( "Storage Service returned a 404 error." " Has the pipeline been disabled or is" " it not registered yet? Submitting" " form will attempt to register the" " pipeline." ), ) return render(request, "administration/general.html", locals())