Пример #1
0
def save_pages_widget_settings_ajax(request):
    c = {}

    widget_pages_pages_spec = request.POST['widget_pages_pages_spec']
    config.set('widget_pages_pages_spec', widget_pages_pages_spec)
    # force reload page links cache
    h.get_pages_widget_links(True)
    return c
Пример #2
0
def save_settings_ajax(request):
    """
    Save settings
    """
    _ = request.translate
    c = {}
    errors = {}

    epp = request.POST['elements_on_page']

    try:
        epp = int(epp)
    except (ValueError, TypeError):
        errors['elements_on_page'] = _('Invalid value, must be positive numeric value')

    preview_width = request.POST['image_preview_width']
    try:
        preview_width = int(preview_width)
    except ValueError:
        errors['image_preview_width'] = _('Invalid value, must be positive numeric value')

    if len(errors):
        c['errors'] = errors
    else:
        dbsession = DBSession()

        # save settings
        settings = ('site_title', 'site_base_url', 'site_copyright', 'elements_on_page',
              'admin_notifications_email', 'notifications_from_email',
              'image_preview_width', 'google_analytics_id', 'timezone', 'ui_lang', 
              'tw_consumer_key', 'tw_consumer_secret', 'social_twitter_share_link',
              'social_twitter_share_link_show_count', 'social_twitter_share_link_via',
              'social_gplusone', 'social_facebook_share', 'site_search_widget_code', 'ui_theme')

        for id in settings:
            try:
                v = request.POST[id]
                config.set(id, v)
            except KeyError:
                continue

        bool_settings = ('admin_notify_new_comments',
            'admin_notify_new_user', 'social_twitter_share_link',
            'social_twitter_share_link_show_count',
            'social_gplusone', 'social_facebook_share')
        for id in bool_settings:
            if id in request.POST:
                v = 'true'
            else:
                v = 'false'
            config.set(id, v, dbsession)

        # refresh data in the cache
        h.get_gplusone_button(True)
        h.get_twitter_share_link_button(True)

    return c