def edit_setting(request, rule_id, template_name='browser/edit_setting.html', extra_context={}): mapping = get_object_or_404(models.DoccodePluginMapping, id=rule_id) instance = representator.serialize_model_for_PluginSelectorForm(mapping) plugins = Plugin.objects.all() kwargs = representator.create_form_fields(plugins) form = forms.PluginSelectorForm(initial = instance) form.setFields(kwargs) if request.method == 'POST': form.setData(request.POST) if form.validation_ok(): representator.save_PluginSelectorForm(request.POST, plugins, rule_id) return HttpResponseRedirect('.') extra_context['rule'] = mapping extra_context['form'] = form return direct_to_template(request, template_name, extra_context=extra_context)
def setting(request, template_name='browser/setting.html', extra_context=None): """Setting for adding and editing rule.""" extra_context = extra_context or {} mappings = models.DoccodePluginMapping.objects.all() plug = Plugin.objects.all() kwargs = representator.create_form_fields(plug) form = forms.PluginSelectorForm() form.setFields(kwargs) if request.method == 'POST': form.setData(request.POST) if form.validation_ok(): representator.save_PluginSelectorForm(request.POST, plug) return HttpResponseRedirect('.') extra_context['form'] = form extra_context['rule_list'] = mappings return render(request, template_name, extra_context)
def edit_setting(request, rule_id, template_name='browser/edit_setting.html', extra_context=None): extra_context = extra_context or {} mapping = get_object_or_404(models.DoccodePluginMapping, id=rule_id) instance = representator.serialize_model_for_PluginSelectorForm(mapping) plug = Plugin.objects.all() kwargs = representator.create_form_fields(plug) form = forms.PluginSelectorForm(initial=instance) form.setFields(kwargs) if request.method == 'POST': form.setData(request.POST) if form.validation_ok(): representator.save_PluginSelectorForm(request.POST, plug, rule_id) return HttpResponseRedirect('.') extra_context.update({ 'rule': mapping, 'form': form, }) return render(request, template_name, extra_context)