+import forum.utils.djangofix
from question import Question ,QuestionRevision, QuestionSubscription
from answer import Answer, AnswerRevision
from tag import Tag, MarkedTag
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)
--- /dev/null
+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))
+
<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>
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'),
--- /dev/null
+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
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', {})
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: