From d4d19211375de71a1c411ae01a16d451ce5917b9 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Sun, 15 Jun 2014 04:50:44 -0300 Subject: added validation to custom logo destination url --- askbot/conf/skin_general_settings.py | 22 ++++++++++++++++++++-- askbot/doc/source/changelog.rst | 1 + askbot/doc/source/contributors.rst | 1 + askbot/templates/widgets/logo.html | 6 ++++-- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/askbot/conf/skin_general_settings.py b/askbot/conf/skin_general_settings.py index 2a4c76fa..beaf04be 100644 --- a/askbot/conf/skin_general_settings.py +++ b/askbot/conf/skin_general_settings.py @@ -6,6 +6,8 @@ from askbot.deps.livesettings import ConfigurationGroup from askbot.deps.livesettings import values from django.utils.translation import ugettext_lazy as _ from django.conf import settings as django_settings +from django.core.validators import URLValidator +from django.core.exceptions import ValidationError from askbot.skins import utils as skin_utils from askbot import const from askbot.conf.super_groups import CONTENT_AND_UI @@ -16,12 +18,28 @@ GENERAL_SKIN_SETTINGS = ConfigurationGroup( super_group = CONTENT_AND_UI ) +def logo_destination_callback(old_url, new_url): + url = new_url.strip() + if url == '': + return '' + + if url.startswith('/'): + return url + + validate = URLValidator() + try: + validate(url) + return url + except ValidationError: + raise ValueError(_('Please enter a valid url')) + settings.register( values.StringValue( GENERAL_SKIN_SETTINGS, 'LOGO_DESTINATION_URL', - default = '/', - description = _('Destination URL for the site logo'), + default = '', + description = _('Custom destination URL for the logo'), + update_callback=logo_destination_callback ) ) diff --git a/askbot/doc/source/changelog.rst b/askbot/doc/source/changelog.rst index e554e324..67928fbc 100644 --- a/askbot/doc/source/changelog.rst +++ b/askbot/doc/source/changelog.rst @@ -3,6 +3,7 @@ Changes in Askbot Development master branch (only on github) ------------------------------------------ +* Allow custom destination url under the logo * Option to allow asking without registration (Egil Moeller) * Implemented Mozilla Persona authentication * Allowed custom providers of gravatar service (michas2) diff --git a/askbot/doc/source/contributors.rst b/askbot/doc/source/contributors.rst index 2ebcaebb..d1e2dd3a 100644 --- a/askbot/doc/source/contributors.rst +++ b/askbot/doc/source/contributors.rst @@ -58,6 +58,7 @@ Programming, bug fixes and documentation * `Francis Devereux `_ * `Andrew Chen `_ * `Egil Moeller `_ +* `Jerry Zhenlei Cai `_ Translations ------------ diff --git a/askbot/templates/widgets/logo.html b/askbot/templates/widgets/logo.html index afa0a95b..c0349d1f 100644 --- a/askbot/templates/widgets/logo.html +++ b/askbot/templates/widgets/logo.html @@ -1,5 +1,7 @@ - -- cgit v1.2.3-1-g7c22