From 1980d43ecfb7f30f2904eb924319d5c6aff0e4ac Mon Sep 17 00:00:00 2001 From: Arun SAG Date: Sun, 18 Sep 2011 01:22:20 +0530 Subject: Add autolinking settings to conf/markup.py - See #607 for more details on this feature - We use regex to match a pattern and autolink it --- askbot/conf/markup.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/askbot/conf/markup.py b/askbot/conf/markup.py index 026c5536..9eeb3149 100644 --- a/askbot/conf/markup.py +++ b/askbot/conf/markup.py @@ -15,6 +15,13 @@ MARKUP = ConfigurationGroup( _('Markup formatting') ) +AUTOLINK = ConfigurationGroup( + 'AUTOLINK', + _('Auto link a pattern to an URL') + +) + + settings.register( BooleanValue( MARKUP, @@ -63,3 +70,51 @@ settings.register( default = '' ) ) + + +settings.register( + BooleanValue( + AUTOLINK, + 'ENABLE_AUTO_LINK', + description=_('Enable autolinking a specifc pattern'), + help_text=_( + 'If you enable this feature, ' + 'the application will be able to ' + 'detect patterns and auto link to URLs' + ), + + default = False + ) + ) + + +settings.register( + StringValue( + AUTOLINK, + 'Pattern', + description=_('Regex to detect the pattern'), + help_text=_( + 'Enter a valid regular expression to' + 'detect the pattern. For example to' + 'detect something like #rhbz 637402 ' + 'use a regular expression like r"#rhbz\s(\d+)"' + ), + default = '' + ) + ) + +settings.register( + StringValue( + AUTOLINK, + 'AutoLinkURL', + description=_('URL for autolinking'), + help_text=_( + 'Let us assume that to detect a pattern #rhbz 637402' + ' the regex is r"#rhbz\s(\d+)" ' + 'then the autolink URL should be https://bugzilla.redhat.com/show_bug.cgi?id=\\1' + ' Where \\1 is the saved match from the regular expression' + ), + default = '' + ) + ) + -- cgit v1.2.3-1-g7c22 From 015a46ddf251032155cec161fed8300d15c6537f Mon Sep 17 00:00:00 2001 From: Arun SAG Date: Sun, 18 Sep 2011 17:23:16 +0530 Subject: Autolinking urls based on regex now works - Fix settings name for readbility - Make utils/markup.py process autlinks --- askbot/conf/markup.py | 6 +++--- askbot/utils/markup.py | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/askbot/conf/markup.py b/askbot/conf/markup.py index 9eeb3149..f7e92bd4 100644 --- a/askbot/conf/markup.py +++ b/askbot/conf/markup.py @@ -75,7 +75,7 @@ settings.register( settings.register( BooleanValue( AUTOLINK, - 'ENABLE_AUTO_LINK', + 'ENABLE_AUTO_LINKING', description=_('Enable autolinking a specifc pattern'), help_text=_( 'If you enable this feature, ' @@ -91,7 +91,7 @@ settings.register( settings.register( StringValue( AUTOLINK, - 'Pattern', + 'PATTERN', description=_('Regex to detect the pattern'), help_text=_( 'Enter a valid regular expression to' @@ -106,7 +106,7 @@ settings.register( settings.register( StringValue( AUTOLINK, - 'AutoLinkURL', + 'AUTO_LINK_URL', description=_('URL for autolinking'), help_text=_( 'Let us assume that to detect a pattern #rhbz 637402' diff --git a/askbot/utils/markup.py b/askbot/utils/markup.py index acb8d03d..ef67b315 100644 --- a/askbot/utils/markup.py +++ b/askbot/utils/markup.py @@ -10,6 +10,7 @@ LINK_PATTERNS = [ (URL_RE, r'\1'), ] + def get_parser(): extras = ['link-patterns', 'video'] if askbot_settings.ENABLE_MATHJAX or \ @@ -22,6 +23,10 @@ def get_parser(): #pip install -e git+git://github.com/andryuha/python-markdown2.git extras.append('video') + if askbot_settings.ENABLE_AUTO_LINKING: + LINK_PATTERNS.append((re.compile(askbot_settings.PATTERN),askbot_settings.AUTO_LINK_URL)) + + return Markdown( html4tags=True, extras=extras, -- cgit v1.2.3-1-g7c22 From 28007df0bc6e944901486e337387787e2d7ddc69 Mon Sep 17 00:00:00 2001 From: Arun SAG Date: Sun, 18 Sep 2011 18:13:35 +0530 Subject: Fix examples in autolink settings --- askbot/conf/markup.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/askbot/conf/markup.py b/askbot/conf/markup.py index f7e92bd4..07f60c39 100644 --- a/askbot/conf/markup.py +++ b/askbot/conf/markup.py @@ -94,10 +94,10 @@ settings.register( 'PATTERN', description=_('Regex to detect the pattern'), help_text=_( - 'Enter a valid regular expression to' + 'Enter a valid regular expression to ' 'detect the pattern. For example to' 'detect something like #rhbz 637402 ' - 'use a regular expression like r"#rhbz\s(\d+)"' + 'use a regular expression like #rhbz\s(\d+)' ), default = '' ) @@ -110,9 +110,9 @@ settings.register( description=_('URL for autolinking'), help_text=_( 'Let us assume that to detect a pattern #rhbz 637402' - ' the regex is r"#rhbz\s(\d+)" ' - 'then the autolink URL should be https://bugzilla.redhat.com/show_bug.cgi?id=\\1' - ' Where \\1 is the saved match from the regular expression' + ' the regex is #rhbz\s(\d+) ' + 'then the autolink URL should be https://bugzilla.redhat.com/show_bug.cgi?id=\1' + ' Where \1 is the saved match (bugid) from the regular expression' ), default = '' ) -- cgit v1.2.3-1-g7c22 From 335e1cfc513dec5065f0a79a9f7180c3abeb25e7 Mon Sep 17 00:00:00 2001 From: Arun SAG Date: Tue, 20 Sep 2011 00:04:45 +0530 Subject: Add support for linking multiple key terms - Use LongStringValue of livesettings to capture multiple patterns and links - Honor all the patterns for autolinking with URLS in utils/markup.py --- askbot/conf/markup.py | 55 +++++++++++++++++++++++++++----------------------- askbot/utils/markup.py | 9 ++++++--- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/askbot/conf/markup.py b/askbot/conf/markup.py index 07f60c39..7ec0d73f 100644 --- a/askbot/conf/markup.py +++ b/askbot/conf/markup.py @@ -4,7 +4,7 @@ Settings that modify processing of user text input from askbot.conf.settings_wrapper import settings from askbot.deps.livesettings import ConfigurationGroup -from askbot.deps.livesettings import BooleanValue, StringValue +from askbot.deps.livesettings import BooleanValue, StringValue, LongStringValue from django.utils.translation import ugettext as _ import askbot from askbot import const @@ -89,32 +89,37 @@ settings.register( settings.register( - StringValue( - AUTOLINK, - 'PATTERN', - description=_('Regex to detect the pattern'), - help_text=_( - 'Enter a valid regular expression to ' - 'detect the pattern. For example to' - 'detect something like #rhbz 637402 ' - 'use a regular expression like #rhbz\s(\d+)' - ), - default = '' - ) + LongStringValue( + AUTOLINK, + 'PATTERN', + description=_('Regex to detect the pattern'), + help_text=_( + 'Enter a valid regular expression to ' + 'detect the pattern. For example to' + 'detect something like #rhbz 637402 ' + 'use a regular expression like #rhbz\s(\d+)' + 'If you want to process multiple regex enter' + ' them line by line' + ), + default = '' ) + ) settings.register( - StringValue( - AUTOLINK, - 'AUTO_LINK_URL', - description=_('URL for autolinking'), - help_text=_( - 'Let us assume that to detect a pattern #rhbz 637402' - ' the regex is #rhbz\s(\d+) ' - 'then the autolink URL should be https://bugzilla.redhat.com/show_bug.cgi?id=\1' - ' Where \1 is the saved match (bugid) from the regular expression' - ), - default = '' - ) + LongStringValue( + AUTOLINK, + 'AUTO_LINK_URL', + description=_('URL for autolinking'), + help_text=_( + 'Let us assume that to detect a pattern #rhbz 637402' + ' the regex is #rhbz\s(\d+) ' + 'then the autolink URL should be https://bugzilla.redhat.com/show_bug.cgi?id=\1' + ' Where \1 is the saved match (bugid) from the regular expression' + ' If you want to process multiple regex enter' + ' them line by line. The URL in first line will be used to link the' + ' pattern on the first line' + ), + default = '' ) + ) diff --git a/askbot/utils/markup.py b/askbot/utils/markup.py index ef67b315..8d072325 100644 --- a/askbot/utils/markup.py +++ b/askbot/utils/markup.py @@ -24,9 +24,12 @@ def get_parser(): extras.append('video') if askbot_settings.ENABLE_AUTO_LINKING: - LINK_PATTERNS.append((re.compile(askbot_settings.PATTERN),askbot_settings.AUTO_LINK_URL)) - - + pattern_list = askbot_settings.PATTERN.split('\n') + url_list = askbot_settings.AUTO_LINK_URL.split('\n') + + for i in range(0,len(pattern_list)): + LINK_PATTERNS.append((re.compile(pattern_list[i].strip()),url_list[i].strip())) + return Markdown( html4tags=True, extras=extras, -- cgit v1.2.3-1-g7c22 From 95d27650403b0491ffbbbc288f969559207de5d9 Mon Sep 17 00:00:00 2001 From: Jishnu Date: Thu, 22 Sep 2011 00:22:08 +0530 Subject: feature #79 - explaining meanings of user levels in account->moderation. --- .../templates/user_profile/user_moderate.html | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/askbot/skins/default/templates/user_profile/user_moderate.html b/askbot/skins/default/templates/user_profile/user_moderate.html index 563026a4..674f8770 100644 --- a/askbot/skins/default/templates/user_profile/user_moderate.html +++ b/askbot/skins/default/templates/user_profile/user_moderate.html @@ -15,6 +15,8 @@ {{ change_user_status_form.as_table() }}
+

+

{% endif %} @@ -64,3 +66,29 @@ {% endif %} {% endblock %} +{% block endjs %} + +{% endblock %} -- cgit v1.2.3-1-g7c22 From 48c58a0ee87b5ea4b6f628640903216304808efa Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Fri, 23 Sep 2011 08:05:11 -0300 Subject: incremented revision --- askbot/__init__.py | 2 +- askbot/doc/source/changelog.rst | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/askbot/__init__.py b/askbot/__init__.py index 8133c74f..5ced4ca1 100644 --- a/askbot/__init__.py +++ b/askbot/__init__.py @@ -9,7 +9,7 @@ import smtplib import sys import logging -VERSION = (0, 7, 22) +VERSION = (0, 7, 23) #necessary for interoperability of django and coffin try: diff --git a/askbot/doc/source/changelog.rst b/askbot/doc/source/changelog.rst index c40f08c1..7bbd734c 100644 --- a/askbot/doc/source/changelog.rst +++ b/askbot/doc/source/changelog.rst @@ -1,7 +1,7 @@ Changes in Askbot ================= -Development version +0.7.23 (Current Version) ------------------- * Greeting for anonymuos users can be changed from live settings (Hrishi) * Greeting for anonymous users is shown only once (Rag Sagar) @@ -11,8 +11,8 @@ Development version * Allowed logging in with password and email in the place of login name (Evgeny) * Added config settings allowing adjust license information (Evgeny) -0.7.22 (Current Version) ------------------------- +0.7.22 +------ * Media resource revision is now incremented automatically any time when media is updated (Adolfo Fitoria, Evgeny Fadeev) * First user automatically becomes site administrator (Adolfo Fitoria) -- cgit v1.2.3-1-g7c22 From e10f078f4ce8862871593eb5e0b357cca409b2f1 Mon Sep 17 00:00:00 2001 From: Arun SAG Date: Sat, 24 Sep 2011 19:47:05 +0530 Subject: Add validation callback - Validate the regular expressions using update_callback --- askbot/conf/markup.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/askbot/conf/markup.py b/askbot/conf/markup.py index 7ec0d73f..09f65ce4 100644 --- a/askbot/conf/markup.py +++ b/askbot/conf/markup.py @@ -9,6 +9,7 @@ from django.utils.translation import ugettext as _ import askbot from askbot import const import os +import re MARKUP = ConfigurationGroup( 'MARKUP', @@ -21,6 +22,24 @@ AUTOLINK = ConfigurationGroup( ) +def regex_settings_validation(*args): + """ + Validate the regular expressions + + """ + try: + + new_value = args[1] + regex_list = new_value.split('\n') + + for i in range(0,len(regex_list)): + re.compile(regex_list[i].strip()) + return args[1] + + except Exception, e: + # The regex is invalid, so we overwrite it with empty string + return "" + settings.register( BooleanValue( @@ -101,6 +120,7 @@ settings.register( 'If you want to process multiple regex enter' ' them line by line' ), + update_callback=regex_settings_validation, default = '' ) ) -- cgit v1.2.3-1-g7c22 From 87b56b761ac999e33e9c243f7f5b8aff4fba2cb1 Mon Sep 17 00:00:00 2001 From: Arun SAG Date: Sat, 24 Sep 2011 19:51:52 +0530 Subject: Ignore key terms if there are no sufficient links --- askbot/utils/markup.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/askbot/utils/markup.py b/askbot/utils/markup.py index 8d072325..0c1a7f0f 100644 --- a/askbot/utils/markup.py +++ b/askbot/utils/markup.py @@ -27,8 +27,10 @@ def get_parser(): pattern_list = askbot_settings.PATTERN.split('\n') url_list = askbot_settings.AUTO_LINK_URL.split('\n') - for i in range(0,len(pattern_list)): - LINK_PATTERNS.append((re.compile(pattern_list[i].strip()),url_list[i].strip())) + # Check whether we have matching links for all key terms, Other wise we ignore the key terms + if len(pattern_list) == len(url_list): + for i in range(0,len(pattern_list)): + LINK_PATTERNS.append((re.compile(pattern_list[i].strip()),url_list[i].strip())) return Markdown( html4tags=True, -- cgit v1.2.3-1-g7c22 From 85ceec244562920040823b748af1a18409f6c69e Mon Sep 17 00:00:00 2001 From: Arun SAG Date: Sat, 24 Sep 2011 20:14:01 +0530 Subject: Fix help text in settings UI of auto link key terms --- askbot/conf/markup.py | 27 ++++++++++++++------------- askbot/utils/markup.py | 4 +++- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/askbot/conf/markup.py b/askbot/conf/markup.py index 09f65ce4..077c2d9f 100644 --- a/askbot/conf/markup.py +++ b/askbot/conf/markup.py @@ -113,12 +113,12 @@ settings.register( 'PATTERN', description=_('Regex to detect the pattern'), help_text=_( - 'Enter a valid regular expression to ' - 'detect the pattern. For example to' - 'detect something like #rhbz 637402 ' - 'use a regular expression like #rhbz\s(\d+)' - 'If you want to process multiple regex enter' - ' them line by line' + ' Enter valid regular expressions to' + ' detect patterns. If you want to auto' + ' link more than one key terms enter them' + ' line by line. For example to' + ' detect a bug pattern like #rhbz 637402' + ' you will have use the following regex #rhbz\s(\d+)' ), update_callback=regex_settings_validation, default = '' @@ -131,13 +131,14 @@ settings.register( 'AUTO_LINK_URL', description=_('URL for autolinking'), help_text=_( - 'Let us assume that to detect a pattern #rhbz 637402' - ' the regex is #rhbz\s(\d+) ' - 'then the autolink URL should be https://bugzilla.redhat.com/show_bug.cgi?id=\1' - ' Where \1 is the saved match (bugid) from the regular expression' - ' If you want to process multiple regex enter' - ' them line by line. The URL in first line will be used to link the' - ' pattern on the first line' + ' The regex to detect pattern #rhbz 637402' + ' is #rhbz\s(\d+), If you want to auto link it to the actual bug' + ' then the autolink URL should be entered here. Example URL can be' + ' https://bugzilla.redhat.com/show_bug.cgi?id=\\1' + ' where \\1 is the saved match (bugid) from the regular expression.' + ' Multiple URLs should be entered in separate lines.' + ' The URL entered in first line' + ' will be used to auto link the first pattern or key term' ), default = '' ) diff --git a/askbot/utils/markup.py b/askbot/utils/markup.py index 0c1a7f0f..e458e381 100644 --- a/askbot/utils/markup.py +++ b/askbot/utils/markup.py @@ -27,7 +27,9 @@ def get_parser(): pattern_list = askbot_settings.PATTERN.split('\n') url_list = askbot_settings.AUTO_LINK_URL.split('\n') - # Check whether we have matching links for all key terms, Other wise we ignore the key terms + # Check whether we have matching links for all key terms, Other wise we ignore the key terms + # May be we should do this test in update_callback? + print len(pattern_list), len(url_list) if len(pattern_list) == len(url_list): for i in range(0,len(pattern_list)): LINK_PATTERNS.append((re.compile(pattern_list[i].strip()),url_list[i].strip())) -- cgit v1.2.3-1-g7c22 From 10ff7a37e1403f96f73918b6b30a51da1f56a654 Mon Sep 17 00:00:00 2001 From: Arun SAG Date: Sat, 24 Sep 2011 20:30:46 +0530 Subject: Log when number of patterns mismatch number of URLs --- askbot/utils/markup.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/askbot/utils/markup.py b/askbot/utils/markup.py index e458e381..3b16a5b2 100644 --- a/askbot/utils/markup.py +++ b/askbot/utils/markup.py @@ -1,4 +1,5 @@ import re +import logging from askbot import const from askbot.conf import settings as askbot_settings from markdown2 import Markdown @@ -29,10 +30,13 @@ def get_parser(): # Check whether we have matching links for all key terms, Other wise we ignore the key terms # May be we should do this test in update_callback? - print len(pattern_list), len(url_list) if len(pattern_list) == len(url_list): for i in range(0,len(pattern_list)): LINK_PATTERNS.append((re.compile(pattern_list[i].strip()),url_list[i].strip())) + else: + settings_url = askbot_settings.APP_URL+'/settings/AUTOLINK/' + logging.debug("Number of keyterms didn't match the number of links, fix this by visiting" + settings_url) + return Markdown( html4tags=True, -- cgit v1.2.3-1-g7c22 From 2c1abd03c2f66b033df2d3e04ff76d85f2081093 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Mon, 26 Sep 2011 12:35:22 -0300 Subject: merged annotation of user types by Jishnu --- askbot/doc/source/changelog.rst | 6 +++++- askbot/doc/source/contributors.rst | 1 + askbot/skins/default/templates/user_profile/user_moderate.html | 10 +++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/askbot/doc/source/changelog.rst b/askbot/doc/source/changelog.rst index 7bbd734c..87933311 100644 --- a/askbot/doc/source/changelog.rst +++ b/askbot/doc/source/changelog.rst @@ -1,7 +1,11 @@ Changes in Askbot ================= -0.7.23 (Current Version) +0.7.24 (development version - not released) +------------------------------------------- +* Added annotations for the meanings of user levels on the "moderation" page. (Jishnu) + +0.7.23 (Current) ------------------- * Greeting for anonymuos users can be changed from live settings (Hrishi) * Greeting for anonymous users is shown only once (Rag Sagar) diff --git a/askbot/doc/source/contributors.rst b/askbot/doc/source/contributors.rst index 35c02be1..fb8d9690 100644 --- a/askbot/doc/source/contributors.rst +++ b/askbot/doc/source/contributors.rst @@ -15,6 +15,7 @@ Programming and documentation * Andy Knotts * Benoit Lavine (with Windriver Software, Inc.) * Jeff Madynski +* `Jishnu `_ * `Hrishi `_ * Andrei Mamoutkine * Ramiro Morales (with Machinalis) diff --git a/askbot/skins/default/templates/user_profile/user_moderate.html b/askbot/skins/default/templates/user_profile/user_moderate.html index 674f8770..b2f350df 100644 --- a/askbot/skins/default/templates/user_profile/user_moderate.html +++ b/askbot/skins/default/templates/user_profile/user_moderate.html @@ -72,19 +72,19 @@ $("#id_user_status").change(function () { var optionValue = $(this).attr('value'); if (optionValue == "d") { - $('#id_user_status_info').html("{% trans %}Administrator is the top-level user privilege set. This amounts to the same as an Operational user's privileges, plus the ability to manage users and alter system settings.{% endtrans %}"); + $('#id_user_status_info').html("{% trans %}Administrators have privileges of normal users, but in addition they can assign/revoke any status to any user, and are exempt from the reputation limits.{% endtrans %}"); $('#id_user_status_info').show('slow'); } else if (optionValue == "m"){ - $('#id_user_status_info').html("{% trans %}Moderator differ from admins in that they cannot set anyone's status to 'moderator' or remove it.{% endtrans %}"); + $('#id_user_status_info').html("{% trans %}Moderators have the same privileges as administrators, but cannot add or remove user status of 'moderator' or 'administrator'.{% endtrans %}"); $('#id_user_status_info').show('slow'); } else if (optionValue == "a"){ - $('#id_user_status_info').html("{% trans %}Approved status is for a regular user.{% endtrans %}"); + $('#id_user_status_info').html("{% trans %}'Approved' status means the same as regular user.{% endtrans %}"); $('#id_user_status_info').show('slow'); } else if (optionValue == "s"){ - $('#id_user_status_info').html("{% trans %}Suspended users can only edit or delete his/her own posts.{% endtrans %}"); + $('#id_user_status_info').html("{% trans %}Suspended users can only edit or delete their own posts.{% endtrans %}"); $('#id_user_status_info').show('slow'); } else if (optionValue == "b"){ - $('#id_user_status_info').html("{% trans %}Blocked user can login and send feedback. nothing else.{% endtrans %}"); + $('#id_user_status_info').html("{% trans %}Blocked users can only login and send feedback to the site administrators.{% endtrans %}"); $('#id_user_status_info').show('slow'); } else { $('#id_user_status_info').hide('slow'); -- cgit v1.2.3-1-g7c22 From 56b83e94717bd46b8d1fb9c638bbad044ea28f88 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Mon, 26 Sep 2011 18:29:40 -0300 Subject: pylinted markup.py files in askbot/conf and askbot/utils --- askbot/conf/markup.py | 87 +++++++++++++++++++---------------------- askbot/doc/source/changelog.rst | 4 ++ askbot/utils/markup.py | 71 ++++++++++++++++++++++++--------- 3 files changed, 96 insertions(+), 66 deletions(-) diff --git a/askbot/conf/markup.py b/askbot/conf/markup.py index 077c2d9f..e4202f05 100644 --- a/askbot/conf/markup.py +++ b/askbot/conf/markup.py @@ -6,9 +6,7 @@ from askbot.conf.settings_wrapper import settings from askbot.deps.livesettings import ConfigurationGroup from askbot.deps.livesettings import BooleanValue, StringValue, LongStringValue from django.utils.translation import ugettext as _ -import askbot from askbot import const -import os import re MARKUP = ConfigurationGroup( @@ -16,27 +14,20 @@ MARKUP = ConfigurationGroup( _('Markup formatting') ) -AUTOLINK = ConfigurationGroup( - 'AUTOLINK', - _('Auto link a pattern to an URL') - -) - def regex_settings_validation(*args): """ Validate the regular expressions - """ try: new_value = args[1] regex_list = new_value.split('\n') - for i in range(0,len(regex_list)): + for i in range(0, len(regex_list)): re.compile(regex_list[i].strip()) return args[1] - except Exception, e: + except Exception: # The regex is invalid, so we overwrite it with empty string return "" @@ -92,34 +83,36 @@ settings.register( settings.register( - BooleanValue( - AUTOLINK, - 'ENABLE_AUTO_LINKING', - description=_('Enable autolinking a specifc pattern'), - help_text=_( - 'If you enable this feature, ' - 'the application will be able to ' - 'detect patterns and auto link to URLs' - ), - - default = False - ) - ) + BooleanValue( + MARKUP, + 'ENABLE_AUTO_LINKING', + description=_('Enable autolinking with specific patterns'), + help_text=_( + 'If you enable this feature, ' + 'the application will be able to ' + 'detect patterns and auto link to URLs' + ), + default = False + ) +) settings.register( LongStringValue( - AUTOLINK, - 'PATTERN', - description=_('Regex to detect the pattern'), + MARKUP, + 'AUTO_LINK_PATTERNS', + description=_('Regexes to detect the link patterns'), help_text=_( - ' Enter valid regular expressions to' - ' detect patterns. If you want to auto' - ' link more than one key terms enter them' - ' line by line. For example to' - ' detect a bug pattern like #rhbz 637402' - ' you will have use the following regex #rhbz\s(\d+)' - ), + 'Enter valid regular expressions for the patters,' + ' one per line.' + ' For example to' + ' detect a bug pattern like #bug123,' + ' use the following regex: #bug(\d+). The numbers' + ' captured by the pattern in the parentheses will' + ' be transferred to the link url template.' + ' Please look up more information about regular' + ' expressions elsewhere.' + ), update_callback=regex_settings_validation, default = '' ) @@ -127,20 +120,20 @@ settings.register( settings.register( LongStringValue( - AUTOLINK, - 'AUTO_LINK_URL', - description=_('URL for autolinking'), + MARKUP, + 'AUTO_LINK_URLS', + description=_('URLs for autolinking'), help_text=_( - ' The regex to detect pattern #rhbz 637402' - ' is #rhbz\s(\d+), If you want to auto link it to the actual bug' - ' then the autolink URL should be entered here. Example URL can be' + 'Here, please enter url templates for the patterns' + ' entered in the previous setting, also one entry per line.' + ' Make sure that number of lines in this setting' + ' and the previous one are the same' + ' For example template' ' https://bugzilla.redhat.com/show_bug.cgi?id=\\1' - ' where \\1 is the saved match (bugid) from the regular expression.' - ' Multiple URLs should be entered in separate lines.' - ' The URL entered in first line' - ' will be used to auto link the first pattern or key term' - ), + ' together with the pattern shown above' + ' and the entry in the post #123' + ' will produce link to the bug 123 in the redhat bug tracker.' + ), default = '' - ) ) - +) diff --git a/askbot/doc/source/changelog.rst b/askbot/doc/source/changelog.rst index 7bbd734c..04062dc2 100644 --- a/askbot/doc/source/changelog.rst +++ b/askbot/doc/source/changelog.rst @@ -1,6 +1,10 @@ Changes in Askbot ================= +Development version (not released yet) +-------------------------------------- +* Auto-link patterns - e.g. to bug databases - are configurable from settings. (Arun SAG) + 0.7.23 (Current Version) ------------------- * Greeting for anonymuos users can be changed from live settings (Hrishi) diff --git a/askbot/utils/markup.py b/askbot/utils/markup.py index 3b16a5b2..60bde9a0 100644 --- a/askbot/utils/markup.py +++ b/askbot/utils/markup.py @@ -1,9 +1,13 @@ +"""methods that make parsing of post inputs possible, +handling of markdown and additional syntax rules - +such as optional link patterns, video embedding and +Twitter-style @mentions""" + import re import logging from askbot import const from askbot.conf import settings as askbot_settings from markdown2 import Markdown - #url taken from http://regexlib.com/REDetails.aspx?regexp_id=501 by Brian Bothwell URL_RE = re.compile("((?@%s' % (url, username) def extract_first_matching_mentioned_author(text, anticipated_authors): + """matches beginning of ``text`` string with the names + of ``anticipated_authors`` - list of user objects. + Returns upon first match the first matched user object + and the remainder of the ``text`` that is left unmatched""" if len(text) == 0: return None, '' - for a in anticipated_authors: - if text.lower().startswith(a.username.lower()): - ulen = len(a.username) + for author in anticipated_authors: + if text.lower().startswith(author.username.lower()): + ulen = len(author.username) if len(text) == ulen: text = '' elif text[ulen] in const.TWITTER_STYLE_MENTION_TERMINATION_CHARS: @@ -66,17 +87,24 @@ def extract_first_matching_mentioned_author(text, anticipated_authors): #near miss, here we could insert a warning that perhaps #a termination character is needed continue - return a, text + return author, text return None, text def extract_mentioned_name_seeds(text): + """Returns list of strings that + follow the '@' symbols in the text. + The strings will be 10 characters long, + or shorter, if the subsequent character + is one of the list accepted to be termination + characters. + """ extra_name_seeds = set() while '@' in text: pos = text.index('@') text = text[pos+1:]#chop off prefix name_seed = '' - for c in text: - if c in const.TWITTER_STYLE_MENTION_TERMINATION_CHARS: + for char in text: + if char in const.TWITTER_STYLE_MENTION_TERMINATION_CHARS: extra_name_seeds.add(name_seed) name_seed = '' break @@ -84,12 +112,12 @@ def extract_mentioned_name_seeds(text): extra_name_seeds.add(name_seed) name_seed = '' break - if c == '@': + if char == '@': if len(name_seed) > 0: extra_name_seeds.add(name_seed) name_seed = '' break - name_seed += c + name_seed += char if len(name_seed) > 0: #in case we run off the end of text extra_name_seeds.add(name_seed) @@ -97,6 +125,11 @@ def extract_mentioned_name_seeds(text): return extra_name_seeds def mentionize_text(text, anticipated_authors): + """Returns a tuple of two items: + * modified text where @mentions are + replaced with urls to the corresponding user profiles + * list of users whose names matched the @mentions + """ output = '' mentioned_authors = list() while '@' in text: -- cgit v1.2.3-1-g7c22