Exemple #1
0
 def test_with_custom_panels(self):
     handler = get_setting_edit_handler(PanelSettings)
     self.assertEqual(handler.__name__, "_ObjectList")
     self.assertEqual(len(handler.children), 1)
     first = handler.children[0]
     self.assertEqual(first.__name__, "_FieldPanel")
     self.assertEqual(first.field_name, "title")
Exemple #2
0
 def test_with_custom_panels(self):
     handler = get_setting_edit_handler(PanelSettings)
     self.assertIsInstance(handler, ObjectList)
     self.assertEqual(len(handler.children), 1)
     first = handler.children[0]
     self.assertIsInstance(first, FieldPanel)
     self.assertEqual(first.field_name, 'title')
 def test_with_custom_panels(self):
     handler = get_setting_edit_handler(PanelSettings)
     self.assertEqual(handler.__name__, '_ObjectList')
     self.assertEqual(len(handler.children), 1)
     first = handler.children[0]
     self.assertEqual(first.__name__, '_FieldPanel')
     self.assertEqual(first.field_name, 'title')
Exemple #4
0
 def test_default_language_widget(self):
     edit_handler = get_setting_edit_handler(SiteLanguages)
     form_cls = edit_handler.get_form_class(SiteLanguages)
     form = form_cls(instance=self.site.sitelanguages)
     assert isinstance(form.fields['default_language'].widget, Select)
     sites.create_site_tree(language=self.default_language, site=self.site)
     form = form_cls(instance=self.site.sitelanguages)
     assert isinstance(form.fields['default_language'].widget,
                       ReadOnlyWidget)
Exemple #5
0
    def test_validate_other_langauges(self):
        edit_handler = get_setting_edit_handler(SiteLanguages)
        form_cls = edit_handler.get_form_class()
        form = form_cls(instance=self.site.sitelanguages, data={
            'default_language': self.default_language.pk,
            'other_languages': [self.default_language.pk],
        })

        assert not form.is_valid()
        assert 'other_languages' in form.errors
Exemple #6
0
 def test_default_model_introspection(self):
     handler = get_setting_edit_handler(TestSetting)
     self.assertIsInstance(handler, ObjectList)
     self.assertEqual(len(handler.children), 2)
     first = handler.children[0]
     self.assertIsInstance(first, FieldPanel)
     self.assertEqual(first.field_name, 'title')
     second = handler.children[1]
     self.assertIsInstance(second, FieldPanel)
     self.assertEqual(second.field_name, 'email')
Exemple #7
0
 def test_default_model_introspection(self):
     handler = get_setting_edit_handler(TestSetting)
     self.assertEqual(handler.__name__, "_ObjectList")
     self.assertEqual(len(handler.children), 2)
     first = handler.children[0]
     self.assertEqual(first.__name__, "_FieldPanel")
     self.assertEqual(first.field_name, "title")
     second = handler.children[1]
     self.assertEqual(second.__name__, "_FieldPanel")
     self.assertEqual(second.field_name, "email")
 def test_default_language_widget(self):
     edit_handler = get_setting_edit_handler(SiteLanguages)
     form_cls = edit_handler.get_form_class()
     form = form_cls(instance=self.site.sitelanguages)
     assert isinstance(form.fields['default_language'].widget, Select)
Exemple #9
0
 def test_with_custom_edit_handler(self):
     handler = get_setting_edit_handler(TabbedSettings)
     self.assertIsInstance(handler, TabbedInterface)
     self.assertEqual(len(handler.children), 2)
Exemple #10
0
 def test_with_custom_edit_handler(self):
     handler = get_setting_edit_handler(TabbedSettings)
     self.assertEqual(handler.__name__, "_TabbedInterface")
     self.assertEqual(len(handler.children), 2)
 def test_with_custom_edit_handler(self):
     handler = get_setting_edit_handler(TabbedSettings)
     self.assertEqual(handler.__name__, '_TabbedInterface')
     self.assertEqual(len(handler.children), 2)
Exemple #12
0
def edit(request, site_pk):
    # get user
    user = request.user
    app_name = 'settings'
    model_name = 'sitesettings'
    # site = request.site or Site.objects.first()
    # if not site:
    #     messages.error(request, _("This setting could not be opened because there is no site defined."))
    #     return redirect('wagtailadmin_home')

    model = get_model_from_url_params(app_name, model_name)
    if not user_can_edit_setting_type(request.user, model):
        raise PermissionDenied
    site = get_object_or_404(Site, pk=site_pk)

    setting_type_name = model._meta.verbose_name

    instance = model.for_site(site)
    edit_handler = get_setting_edit_handler(model)
    form_class = edit_handler.get_form_class()

    if request.method == 'POST':
        form = form_class(request.POST, request.FILES, instance=instance)

        if form.is_valid():
            form.save()

            messages.success(
                request,
                _("{setting_type} updated.").format(
                    setting_type=capfirst(setting_type_name),
                    instance=instance))
            return redirect('wagtailsettings:edit', app_name, model_name,
                            site.pk)
        else:
            messages.validation_error(
                request, _("The setting could not be saved due to errors."),
                form)
            edit_handler = edit_handler.bind_to_instance(instance=instance,
                                                         form=form,
                                                         request=request)
    else:
        form = form_class(instance=instance)
        edit_handler = edit_handler.bind_to_instance(instance=instance,
                                                     form=form,
                                                     request=request)

    # Show a site switcher form if there are multiple sites
    site_switcher = None
    if Site.objects.count() > 1:
        site_switcher = SiteSwitchForm(site, model, user)

    return render(
        request, 'wagtailsettings/edit.html', {
            'opts': model._meta,
            'setting_type_name': setting_type_name,
            'instance': instance,
            'edit_handler': edit_handler,
            'form': form,
            'site': site,
            'site_switcher': site_switcher,
            'tabbed': isinstance(edit_handler, TabbedInterface),
        })