def storagesetup(request): # Display the dashboard UUID on the storage service setup page dashboard_uuid = helpers.get_setting('dashboard_uuid', None) assert dashboard_uuid is not None # Prefill the storage service URL inital_data = { 'storage_service_url': helpers.get_setting('storage_service_url', 'http://localhost:8000'), 'storage_service_user': helpers.get_setting('storage_service_user', 'test'), 'storage_service_apikey': helpers.get_setting('storage_service_apikey', None) } storage_form = StorageSettingsForm(request.POST or None, initial=inital_data) if not storage_form.is_valid(): return render(request, 'installer/storagesetup.html', locals()) storage_form.save() try: use_default_config = storage_form.cleaned_data[ 'storage_service_use_default_config'] setup_pipeline_in_ss(use_default_config) except Exception: messages.warning( request, _('Error creating pipeline: is the storage server running? Please contact an administrator.' )) return redirect('main.views.home')
def storagesetup(request): # Display the dashboard UUID on the storage service setup page dashboard_uuid = helpers.get_setting("dashboard_uuid", None) assert dashboard_uuid is not None # Prefill the storage service URL inital_data = { "storage_service_url": helpers.get_setting("storage_service_url", "http://localhost:8000"), "storage_service_user": helpers.get_setting("storage_service_user", "test"), "storage_service_apikey": helpers.get_setting("storage_service_apikey", None), } storage_form = StorageSettingsForm(request.POST or None, initial=inital_data) if not storage_form.is_valid(): return render(request, "installer/storagesetup.html", locals()) storage_form.save() try: use_default_config = storage_form.cleaned_data[ "storage_service_use_default_config"] setup_pipeline_in_ss(use_default_config) except Exception: messages.warning( request, _("Error creating pipeline: is the storage server running? Please contact an administrator." ), ) return redirect("main.views.home")
def handle(self, *args, **options): setup_pipeline(options['org_name'], options['org_id']) create_super_user(options['username'], options['email'], options['password'], options['api_key']) self.save_ss_settings(options) setup_pipeline_in_ss(use_default_config=True) helpers.set_setting('api_whitelist', options['whitelist'])
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 handle(self, *args, **options): # Not needed in Django 1.9+. self.style.SUCCESS = termcolors.make_style(opts=("bold", ), fg="green") setup_pipeline(options["org_name"], options["org_id"], options["site_url"]) create_super_user( options["username"], options["email"], options["password"], options["api_key"], ) self.save_ss_settings(options) setup_pipeline_in_ss(use_default_config=True) helpers.set_api_allowlist(options["whitelist"] or options["allowlist"]) self.stdout.write(self.style.SUCCESS("Done!\n"))
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())