Esempio n. 1
0
def test_set_setting_conversion(db_session, root):
    from kotti.sqla import NestedMutationList
    from kotti_settings.util import get_setting
    from kotti_settings.util import set_setting

    set_setting('kotti_settings-test_conversion', set(['a', 'b', 'c']))
    setting = get_setting('test_conversion')
    assert type(setting) == NestedMutationList

    # We sort this because we can't rely on the order in a set.
    setting = list(setting)
    setting.sort()
    assert setting == ['a', 'b', 'c']
Esempio n. 2
0
def test_views(db_session, dummy_request):

    root = get_root()
    root['test-document'] = Document()
    root['test-image'] = Image()

    # Setup
    kotti_configure(get_settings())
    set_setting('kotti_disqus-disqus_available_types',
                ['kotti.resources.Document'])

    # Is shown on Document with the default URL if we do not set it
    set_setting('kotti_disqus-disqus_shortname', 'test_shortname')
    set_setting('kotti_disqus-disqus_base_url', '')
    assert disqus_comments_view(root['test-document'], dummy_request) == \
        {
            'disqus_url': 'http://example.com/test-document/',
            'disqus_shortname': 'test_shortname'
        }

    # If we set the URL, it overrides the default one
    set_setting('kotti_disqus-disqus_base_url', 'http://testing.com/')
    assert disqus_comments_view(root['test-document'], dummy_request) == \
        {
            'disqus_url': 'http://testing.com/test-document/',
            'disqus_shortname': 'test_shortname'
        }

    # Is not shown if we aren't on a Document object, raises PredicateMismatch
    with pytest.raises(PredicateMismatch):
        disqus_comments_view(root['test-image'], dummy_request)
Esempio n. 3
0
 def save_success(self, appstruct):
     from kotti_settings.util import set_setting
     formid = self.request.POST.get('__formid__', None)
     self.active = False
     if formid is not None and formid == self.form_id:
         self.active = True
         appstruct.pop('csrf_token', None)
         module = None
         if appstruct:
             key = appstruct.keys()[0]
             module = key[:key.find('-')]
         self.request.registry.notify(SettingsBeforeSave(module))
         for item in appstruct:
             if appstruct[item] is not None:
                 set_setting(item, appstruct[item])
         ses = self.request.session
         if not '_f_success' in ses or\
             not self.success_message in ses['_f_success']:
                 self.request.session.flash(self.success_message, 'success')
         self.request.registry.notify(SettingsAfterSave(module))
Esempio n. 4
0
def set_nav_setting(slot, setting, value):
    name = 'kotti_navigation-'
    name += "%s_%s" % (slot, setting)
    set_setting(name, value)