def register(self, configuration): if configuration.__class__ == ConfigOption and not (configuration.app, configuration.name) in self._registry: try: existing_config = ConfigOption.objects.get(app = configuration.app, name = configuration.name) except ObjectDoesNotExist: configuration.save() existing_config = configuration try: defined_config = DefinedConfigOption.objects.get(option__name = configuration.name, option__app = configuration.app) except ObjectDoesNotExist: defined_config = DefinedConfigOption(option = existing_config, value = configuration.default) defined_config.save() self._registry[(configuration.app, configuration.name)] = existing_config
def configure_option(request, option_id): from django_wizard.forms import build_config_form option = ConfigOption.objects.get(id = option_id) try: defined_option = DefinedConfigOption.objects.get(option = option) except ObjectDoesNotExist: defined_option = DefinedConfigOption(option = option, value = option.default) defined_option.save() ConfigForm = build_config_form(option, defined_option) if request.POST: form = ConfigForm(request.POST) if form.is_valid(): defined_option.value = json.dumps(form.cleaned_data['value']) defined_option.save() return http.HttpResponseRedirect(reverse('django-wizard-main')) else: form = ConfigForm() return shortcuts.render_to_response('django_wizard/option.html', {'option':option, 'defined_option':defined_option, 'form':form}, context_instance = RequestContext(request))