Ejemplo n.º 1
0
 def form_valid(self, form):
     settings = Setting.settings
     changes = {}
     for data in form.cleaned_data:
         setting = settings[data['name']]
         if not isinstance(data['value'], parser.NotSupported) and setting.editable:
             if setting.value != data['value']:
                 if setting.default == data['value']:
                     changes[setting.name] = parser.Remove()
                 else:
                     changes[setting.name] = parser.serialize(data['value'])
     if changes:
         # Display confirmation
         if not self.request.POST.get('confirmation'):
             settings_file = parser.get_settings_file()
             new_content = parser.apply(changes)
             cmd = "cat <<EOF | diff %s -\n%s\nEOF" % (settings_file, new_content)
             diff = sys.run(cmd, valid_codes=(1, 0)).stdout
             context = self.get_context_data(form=form)
             context['diff'] = diff
             return self.render_to_response(context)
         n = len(changes)
         # Save changes
         parser.save(changes)
         sys.touch_wsgi()
         context = {
             'message': ngettext(
                 _("One change successfully applied, orchestra is being restarted."),
                 _("%s changes successfully applied, orchestra is being restarted.") % n,
                 n),
         }
         return render_to_response(self.reload_template_name, context)
     else:
         messages.success(self.request, _("No changes have been detected."))
     return super(SettingView, self).form_valid(form)
Ejemplo n.º 2
0
 def save_model(self, request, obj, form, change):
     super(ResourceAdmin, self).save_model(request, obj, form, change)
     # best-effort
     model = obj.content_type.model_class()
     modeladmin = type(get_modeladmin(model))
     resources = obj.content_type.resource_set.filter(is_active=True)
     inlines = []
     for inline in modeladmin.inlines:
         if inline.model is ResourceData:
             inline = resource_inline_factory(resources)
         inlines.append(inline)
     modeladmin.inlines = inlines
     # reload Not always work
     sys.touch_wsgi()
Ejemplo n.º 3
0
 def save_model(self, request, obj, form, change):
     super(ResourceAdmin, self).save_model(request, obj, form, change)
     # best-effort
     model = obj.content_type.model_class()
     modeladmin = type(get_modeladmin(model))
     resources = obj.content_type.resource_set.filter(is_active=True)
     inlines = []
     for inline in modeladmin.inlines:
         if inline.model is ResourceData:
             inline = resource_inline_factory(resources)
         inlines.append(inline)
     modeladmin.inlines = inlines
     # reload Not always work
     sys.touch_wsgi()
Ejemplo n.º 4
0
 def form_valid(self, form):
     settings = Setting.settings
     changes = {}
     for data in form.cleaned_data:
         setting = settings[data['name']]
         if not isinstance(data['value'], parser.NotSupported) and setting.editable:
             if setting.value != data['value']:
                 # Ignore differences between lists and tuples
                 if (type(setting.value) != type(data['value']) and
                     isinstance(data['value'], list) and
                     tuple(data['value']) == setting.value):
                         continue
                 if setting.default == data['value']:
                     changes[setting.name] = parser.Remove()
                 else:
                     changes[setting.name] = data['value']
     if changes:
         # Display confirmation
         if not self.request.POST.get('confirmation'):
             settings_file = parser.get_settings_file()
             new_content = parser.apply(changes)
             cmd = "cat <<EOF | diff %s -\n%s\nEOF" % (settings_file, new_content)
             diff = sys.run(cmd, valid_codes=(1, 0)).stdout
             context = self.get_context_data(form=form)
             context['diff'] = diff
             if not diff:
                 messages.warning(self.request, _("Changes detected but no diff %s.") % changes)
             return self.render_to_response(context)
         n = len(changes)
         # Save changes
         parser.save(changes)
         sys.touch_wsgi()
         context = {
             'message': ngettext(
                 _("One change successfully applied, orchestra is being restarted."),
                 _("%s changes successfully applied, orchestra is being restarted.") % n,
                 n),
         }
         return render_to_response(self.reload_template_name, context)
     else:
         messages.success(self.request, _("No changes have been detected."))
     return super(SettingView, self).form_valid(form)