diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-09-11 19:35:00 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-09-11 19:35:00 -0400 |
commit | cb09dd64924628e0646342538d2512439b7c3eba (patch) | |
tree | f4e72953c72114a906c3c2d2618824e4bd955e55 | |
parent | ce5f99a29f1f7c4d6ed704fb4974e70ba4defe58 (diff) | |
download | askbot-cb09dd64924628e0646342538d2512439b7c3eba.tar.gz askbot-cb09dd64924628e0646342538d2512439b7c3eba.tar.bz2 askbot-cb09dd64924628e0646342538d2512439b7c3eba.zip |
finished merge with Omat's change and added setting to enable/disable slugs
-rw-r--r-- | askbot/conf/site_settings.py | 59 | ||||
-rw-r--r-- | askbot/tests/page_load_tests.py | 6 | ||||
-rw-r--r-- | askbot/utils/slug.py | 45 | ||||
-rw-r--r-- | askbot/views/readers.py | 22 | ||||
-rw-r--r-- | setup.py | 5 |
5 files changed, 94 insertions, 43 deletions
diff --git a/askbot/conf/site_settings.py b/askbot/conf/site_settings.py index 5b0213e4..e2991fad 100644 --- a/askbot/conf/site_settings.py +++ b/askbot/conf/site_settings.py @@ -3,18 +3,18 @@ Q&A website settings - title, desctiption, basic urls keywords """ from askbot.conf.settings_wrapper import settings -from askbot.deps.livesettings import ConfigurationGroup, StringValue +from askbot.deps import livesettings from django.utils.translation import ugettext as _ from django.utils.html import escape from askbot import const -QA_SITE_SETTINGS = ConfigurationGroup( +QA_SITE_SETTINGS = livesettings.ConfigurationGroup( 'QA_SITE_SETTINGS', _('Q&A forum website parameters and urls') ) settings.register( - StringValue( + livesettings.StringValue( QA_SITE_SETTINGS, 'APP_TITLE', default=u'ASKBOT: Open Source Q&A Forum', @@ -23,7 +23,7 @@ settings.register( ) settings.register( - StringValue( + livesettings.StringValue( QA_SITE_SETTINGS, 'APP_KEYWORDS', default=u'ASKBOT,CNPROG,forum,community', @@ -32,25 +32,27 @@ settings.register( ) settings.register( - StringValue( + livesettings.StringValue( QA_SITE_SETTINGS, 'APP_COPYRIGHT', - default='Copyright ASKBOT, 2010. Some rights reserved under creative commons license.', + default='Copyright ASKBOT, 2010. Some rights reserved ' + \ + 'under creative commons license.', description=_('Copyright message to show in the footer') ) ) settings.register( - StringValue( + livesettings.StringValue( QA_SITE_SETTINGS, 'APP_DESCRIPTION', - default='Open source question and answer forum written in Python and Django', + default='Open source question and answer forum written in ' +\ + 'Python and Django', description=_('Site description for the search engines') ) ) settings.register( - StringValue( + livesettings.StringValue( QA_SITE_SETTINGS, 'APP_SHORT_NAME', default=_('Askbot'), @@ -60,21 +62,27 @@ settings.register( ) settings.register( - StringValue( + livesettings.StringValue( QA_SITE_SETTINGS, 'APP_URL', default='http://askbot.org', - description=_('Base URL for your Q&A forum, must start with http or https'), + description=_( + 'Base URL for your Q&A forum, must start with ' + 'http or https' + ), ) ) settings.register( - StringValue( + livesettings.StringValue( QA_SITE_SETTINGS, 'GREETING_URL', - default='/' + _('faq/'),#cannot reverse url here, unfortunately, must be absolute also + default='/' + _('faq/'),#cannot reverse url here, must be absolute also hidden=True, - description=_('Link shown in the greeting message shown to the anonymous user'), + description=_( + 'Link shown in the greeting message ' + 'shown to the anonymous user' + ), help_text=_('If you change this url from the default - ' 'then you will also probably want to adjust translation of ' 'the following string: ') + '"' @@ -85,10 +93,29 @@ settings.register( ) settings.register( - StringValue( + livesettings.StringValue( QA_SITE_SETTINGS, 'FEEDBACK_SITE_URL', description=_('Feedback site URL'), - help_text=_('If left empty, a simple internal feedback form will be used instead') + help_text=_( + 'If left empty, a simple internal feedback form ' + 'will be used instead' + ) + ) +) + +settings.register( + livesettings.BooleanValue( + QA_SITE_SETTINGS, + 'USE_ASCII_ONLY_SLUGS', + description=_( + 'Use slugs made only of ASCII characters ' + 'in the page urls' + ), + help_text=_('Slugs are human-readable parts of the url ' + 'consisting of the page keywords, that are ' + 'typically composed from the page title.' + ), + default = True ) ) diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py index 21b897c1..87537e58 100644 --- a/askbot/tests/page_load_tests.py +++ b/askbot/tests/page_load_tests.py @@ -130,14 +130,20 @@ class PageLoadTests(PageLoadTestCase): self.try_url( 'question', kwargs={'id':1}, + follow=True, + template='question.html' ) self.try_url( 'question', kwargs={'id':2}, + follow=True, + template='question.html' ) self.try_url( 'question', kwargs={'id':3}, + follow=True, + template='question.html' ) self.try_url( 'question_revisions', diff --git a/askbot/utils/slug.py b/askbot/utils/slug.py index e89c667e..d4f2a263 100644 --- a/askbot/utils/slug.py +++ b/askbot/utils/slug.py @@ -1,18 +1,33 @@ +"""defines the method for building slugs +slugification may be disabled with a live setting "USE_ASCII_ONLY_SLUGS" + +the setting was added just in case - if people actually +want to see unicode characters in the slug. If this is the choice +slug will be simply equal to the input text +""" from unidecode import unidecode -from django.template.defaultfilters import slugify as slgfy +from django.template import defaultfilters +from askbot.conf import settings as askbot_settings -def slugify(s, max_length=50): - if s == '': - return s - slug = slgfy(unidecode(s)) - while len(slug) > max_length: - # try to shorten word by word until len(slug) <= max_length - temp = slug[:slug.rfind('-')] - if len(temp) > 0: - slug = temp - else: - # we have nothing left, do not apply the last crop, apply the cut-off directly - slug = slug[:max_length] - break - return slug +def slugify(input_text, max_length=50): + """custom slugify function that + removes diacritic modifiers from the characters + """ + if askbot_settings.USE_ASCII_ONLY_SLUGS == True: + if input_text == '': + return input_text + slug = defaultfilters.slugify(unidecode(input_text)) + while len(slug) > max_length: + # try to shorten word by word until len(slug) <= max_length + temp = slug[:slug.rfind('-')] + if len(temp) > 0: + slug = temp + else: + #we have nothing left, do not apply the last crop, + #apply the cut-off directly + slug = slug[:max_length] + break + return slug + else: + return input_text diff --git a/askbot/views/readers.py b/askbot/views/readers.py index 49a42ad8..31eeee67 100644 --- a/askbot/views/readers.py +++ b/askbot/views/readers.py @@ -267,18 +267,16 @@ def question(request, id):#refactor - long subroutine. display question body, an question = get_object_or_404(Question, id=id) try: - pattern = r'/%s%s%d/([\w-]+)' % (settings.ASKBOT_URL,_('question/'), question.id) - path_re = re.compile(pattern) - logging.debug(pattern) - logging.debug(request.path) - m = path_re.match(request.path) - if m: - slug = m.group(1) - logging.debug('have slug %s' % slug) - assert(slug == slugify(question.title)) - else: - logging.debug('no match!') - except: + path_prefix = r'/%s%s%d/' % (settings.ASKBOT_URL,_('question/'), question.id) + if not request.path.startswith(path_prefix): + logging.critical('bad request path %s' % request_path) + raise Http404 + slug = request.path.replace(path_prefix, '', 1) + logging.debug('have slug %s' % slug) + logging.debug('requestion path is %s' % request.path) + assert(slug == slugify(question.title)) + except AssertionError: + logging.debug('no slug match!') return HttpResponseRedirect(question.get_absolute_url()) if question.deleted: @@ -7,6 +7,7 @@ import sys #you might want to install django-debug-toolbar as well install_requires = [ + 'django==1.1.2', 'South>=0.7.1', 'recaptcha-client', 'markdown2', @@ -19,6 +20,10 @@ install_requires = [ import askbot +WIN_PLATFORMS = ('win32', 'cygwin',) +if sys.platform not in WIN_PLATFORMS: + install_requires.append('mysql-python') + setup( name = "askbot", version = askbot.get_version(), |