]> git.openstreetmap.org Git - osqa.git/commitdiff
Adds options to control the behaviour of urls.
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Fri, 9 Jul 2010 11:27:33 +0000 (11:27 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Fri, 9 Jul 2010 11:27:33 +0000 (11:27 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@511 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/models/__init__.py
forum/settings/__init__.py
forum/settings/urls.py [new file with mode: 0644]
forum/skins/default/templates/osqaadmin/djstyle_base.html
forum/urls.py
forum/utils/djangofix.py [new file with mode: 0644]
forum/views/admin.py
forum/views/readers.py

index 7a15132362bc0bc70c0d83809d28a37818bc1278..2449289fb619d03dedba976f999e60d896c0af44 100644 (file)
@@ -1,3 +1,4 @@
+import forum.utils.djangofix
 from question import Question ,QuestionRevision, QuestionSubscription
 from answer import Answer, AnswerRevision
 from tag import Tag, MarkedTag
index b7b4aac4ebf9aa9d19a8144e0d3ea03e21e87f32..6d5b03f6f1f324d2214ab9581abbb6b135d8fdcd 100644 (file)
@@ -36,6 +36,7 @@ from view import *
 from moderation import *
 from users import *
 from static import *
+from urls import *
 
 BADGES_SET = SettingSet('badges', _('Badges config'), _("Configure badges on your OSQA site."), 500)
 
diff --git a/forum/settings/urls.py b/forum/settings/urls.py
new file mode 100644 (file)
index 0000000..e532c55
--- /dev/null
@@ -0,0 +1,15 @@
+from base import Setting, SettingSet
+from django.utils.translation import ugettext as _
+
+URLS_SET = SettingSet('urls', _('URL settings'), _("Some settings to tweak behaviour of site urls (experimental)."))
+
+ALLOW_UNICODE_IN_SLUGS = Setting('ALLOW_UNICODE_IN_SLUGS', False, URLS_SET, dict(
+label = _("Allow unicode in slugs"),
+help_text = _("Allow unicode/non-latin characters in urls."),
+required=False))
+
+FORCE_SINGLE_URL = Setting('FORCE_SINGLE_URL', True, URLS_SET, dict(
+label = _("Force single url"),
+help_text = _("Redirect the request in case there is a mismatch between the slug in the url and the actual slug"),
+required=False))
+
index 02443a7458ac7b38668ec3e24ffac2cb4c4a1196..d976268a1308c5a6385fc9b79bf9434b7d38b68f 100644 (file)
@@ -68,6 +68,7 @@
                         <li><a href="{% url admin_set allsets.users.name %}">{{ allsets.users.title }}</a></li>
                         <li><a href="{% url admin_set allsets.email.name %}">{{ allsets.email.title }}</a></li>
                         <li><a href="{% url admin_set allsets.paths.name %}">{{ allsets.paths.title }}</a></li>
+                        <li><a href="{% url admin_set allsets.urls.name %}">{{ allsets.urls.title }}</a></li>
                         <li><a href="{% url admin_set allsets.extkeys.name %}">{{ allsets.extkeys.title }}</a></li>
                     </ul>
                 </div>
index 4598ddc34e7e1d49dd1c18484c4c8f4440d4c1cb..faea61a466ede699cfea1e42e657cfa2d577841b 100644 (file)
@@ -94,8 +94,8 @@ urlpatterns += patterns('',
                         url(r'^%s(?P<id>\d+)/(?P<slug>[\w-]*)$' % _('question/'),
                             'django.views.generic.simple.redirect_to', {'url': '/questions/%(id)s/%(slug)s'}),
                         url(r'^%s(?P<id>\d+)/?$' % _('questions/'), app.readers.question, name='question'),
-                        url(r'^%s(?P<id>\d+)/(?P<slug>[\w-]*)$' % _('questions/'), app.readers.question, name='question'),
-                        url(r'^%s(?P<id>\d+)/(?P<slug>[\w-]*)/(?P<answer>\d+)$' % _('questions/'), app.readers.question),
+                        url(r'^%s(?P<id>\d+)/(?P<slug>.*)$' % _('questions/'), app.readers.question, name='question'),
+                        url(r'^%s(?P<id>\d+)/(?P<slug>.*)/(?P<answer>\d+)$' % _('questions/'), app.readers.question),
 
 
                         url(r'^%s$' % _('tags/'), app.readers.tags, name='tags'),
diff --git a/forum/utils/djangofix.py b/forum/utils/djangofix.py
new file mode 100644 (file)
index 0000000..d74e48d
--- /dev/null
@@ -0,0 +1,21 @@
+import re
+import urllib
+from forum.modules import decorate
+
+from django.template.defaultfilters import slugify
+from django.utils.safestring import mark_safe
+from django.utils.http import urlquote_plus
+
+slug_re = re.compile(r'\w+', re.UNICODE)
+
+@decorate(slugify)
+def imp_slugify(origin, value):
+    if settings.ALLOW_UNICODE_IN_SLUGS:
+        try:
+            bits = slug_re.findall(value.lower())
+            return mark_safe("-".join(bits))
+        except:
+            pass
+    return origin(value)
+
+from forum import settings
\ No newline at end of file
index ad4f9b933c01137372d92360ae8022931691e34a..29fd454fcbfb2bda7d5f732dfb6f8ce5a6ed9dd8 100644 (file)
@@ -37,7 +37,7 @@ def admin_page(fn):
             context['othersets'] = sorted(
                     [s for s in Setting.sets.values() if not s.name in
                     ('basic', 'users', 'email', 'paths', 'extkeys', 'repgain', 'minrep', 'voting', 'badges', 'about', 'faq', 'sidebar',
-                    'form', 'moderation', 'css', 'headandfoot', 'head', 'view')]
+                    'form', 'moderation', 'css', 'headandfoot', 'head', 'view', 'urls')]
                     , lambda s1, s2: s1.weight - s2.weight)
 
             unsaved = request.session.get('previewing_settings', {})
index 0d282b8c5000d25a0cd779addce27a3f69027352..4a839b0be81ef3f073cbb5a4518cbc8a0608a2c3 100644 (file)
@@ -305,7 +305,7 @@ def question(request, id, slug=None, answer=None):
 
         return answer_redirect(request, answer)
 
-    if (not slug) or (slug != urlquote(slugify(question.title))):
+    if settings.FORCE_SINGLE_URL and ((not slug) or (slug != slugify(question.title))):
         return HttpResponsePermanentRedirect(question.get_absolute_url())
 
     if request.POST: