@models.permalink
def get_profile_url(self):
- return ('user_profile', (), {'id': self.id, 'slug': slugify(smart_unicode(self.username))})
+ keyword_arguments = {
+ 'slug': slugify(smart_unicode(self.username))
+ }
+ if settings.INCLUDE_ID_IN_USER_URLS:
+ keyword_arguments.update({
+ 'id': self.id,
+ })
+ return ('user_profile', (), keyword_arguments)
def get_absolute_url(self):
return self.get_profile_url()
@models.permalink
def get_user_subscriptions_url(self):
- return ('user_subscriptions', (), { 'id': self.id, 'slug': slugify(smart_unicode(self.username))})
+ keyword_arguments = {
+ 'slug': slugify(smart_unicode(self.username))
+ }
+ if settings.INCLUDE_ID_IN_USER_URLS:
+ keyword_arguments.update({
+ 'id': self.id,
+ })
+ return ('user_subscriptions', (), keyword_arguments)
@models.permalink
def get_answered_url(self):
URLS_SET = SettingSet('urls', _('URL settings'), _("Some settings to tweak behaviour of site urls (experimental)."))
+INCLUDE_ID_IN_USER_URLS = Setting('INCLUDE_ID_IN_USER_URLS', True, URLS_SET, dict(
+label = _("Include IDs in user URLs"),
+help_text = _("Choose this if you want to have IDs included in the user-related URLs."),
+required=False))
+
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."),
<p style="{{ p_style }}">{% trans "Thanks" %},<br />{{settings.APP_SHORT_NAME}}</p>
{% if not exclude_finetune %}
<p style="{{ p_style }}">{% trans "P.S. You can always fine-tune which notifications you receive" %}
-<a href="{{ settings.APP_URL }}{% url user_subscriptions id=recipient.id,slug=recipient.username|slugify %}" style="{{ a_style }}">{% trans "here" %}</a>.
+<a href="{{ settings.APP_URL }}{{ recipient.get_user_subscriptions_url }}" style="{{ a_style }}">{% trans "here" %}</a>.
{% endif %}
</p>
<hr style="{{ hr_style }}" />
{% if not exclude_finetune %}
{% trans "P.S. You can always fine-tune which notifications you receive here:" %}
-{{ settings.APP_URL }}{% url user_subscriptions id=recipient.id,slug=recipient.username|slugify %}
+{{ settings.APP_URL }}{{ recipient.get_user_subscriptions_url }}
{% endif %}
{{ settings.EMAIL_FOOTER_TEXT }}
\ No newline at end of file
<br/>
<div id="navBar"><div class="tabsA">
- <a href='{% url user_subscriptions id=view_user.id slug=view_user.username|slugify %}?tab=settings' id="subscriptions_settings_button" {% if not manage_open %}class="on"{% endif %}>Settings</a>
- <a href='{% url user_subscriptions id=view_user.id slug=view_user.username|slugify %}?tab=manage' id="subscriptions_management_button" {% if manage_open %}class="on"{% endif %}>Manage</a>
+ <a href='{{ view_user.get_user_subscriptions_url }}?tab=settings' id="subscriptions_settings_button" {% if not manage_open %}class="on"{% endif %}>Settings</a>
+ <a href='{{ view_user.get_user_subscriptions_url }}?tab=manage' id="subscriptions_management_button" {% if manage_open %}class="on"{% endif %}>Manage</a>
</div></div>
<br/>
except AttributeError:
admin_url = url(r'^%s(.*)' % _('nimda/'), admin.site.urls)
+# Choose the user urls pattern
+if bool(settings.INCLUDE_ID_IN_USER_URLS.value):
+ core_user_urls_prefix = r'^%s(?P<id>\d+)/(?P<slug>.*)'
+else:
+ core_user_urls_prefix = r'^%s(?P<slug>.*)'
+
core_urls = (
url(r'^$', app.readers.index, name='index'), admin_url,
url(r'^%s(?P<id>\d+)/%s$' % (_('users/'), _('award/')), app.users.award_points, name='user_award_points'),
url(r'^%s(?P<id>\d+)/%s$' % (_('users/'), _('suspend/')), app.users.suspend, name='user_suspend'),
url(r'^%s(?P<id>\d+)/%s(?P<action>[a-z]+)/(?P<status>[a-z]+)/$' % (_('users/'), _('powers/')), app.users.user_powers, name='user_powers'),
- url(r'^%s(?P<id>\d+)/(?P<slug>.*)/%s$' % (_('users/'), _('subscriptions/')), app.users.user_subscriptions, name='user_subscriptions'),
+ url((core_user_urls_prefix + '/%s$') % (_('users/'), _('subscriptions/')), app.users.user_subscriptions, name='user_subscriptions'),
url(r'^%s(?P<id>\d+)/(?P<slug>.*)/%s$' % (_('users/'), _('preferences/')), app.users.user_preferences, name='user_preferences'),
url(r'^%s(?P<id>\d+)/(?P<slug>.*)/%s$' % (_('users/'), _('favorites/')), app.users.user_favorites, name='user_favorites'),
url(r'^%s(?P<id>\d+)/(?P<slug>.*)/%s$' % (_('users/'), _('reputation/')), app.users.user_reputation, name='user_reputation'),
url(r'^%s(?P<id>\d+)/(?P<slug>.*)/%s$' % (_('users/'), _('votes/')), app.users.user_votes, name='user_votes'),
url(r'^%s(?P<id>\d+)/(?P<slug>.*)/%s$' % (_('users/'), _('recent/')), app.users.user_recent, name='user_recent'),
- url(r'^%s(?P<id>\d+)/(?P<slug>.*)$' % _('users/'), app.users.user_profile, name='user_profile'),
+ url(core_user_urls_prefix % _('users/'), app.users.user_profile, name='user_profile'),
url(r'^%s$' % _('badges/'), app.meta.badges, name='badges'),
url(r'^%s(?P<id>\d+)/(?P<slug>[\w-]+)?$' % _('badges/'), app.meta.badge, name='badge'),
# (r'^admin/doc/' % _('admin/doc'), include('django.contrib.admindocs.urls')),
\r
def user_view(template, tab_name, tab_title, tab_description, private=False, tabbed=True, render_to=None, weight=500):\r
def decorator(fn):\r
- def params(request, id, slug=None):\r
- user = get_object_or_404(User, id=id)\r
+ def params(request, id=None, slug=None):\r
+ # Get the user object by id if the id parameter has been passed\r
+ if id is not None:\r
+ user = get_object_or_404(User, id=id)\r
+ # ...or by slug if the slug has been given\r
+ elif slug is not None:\r
+ user = get_object_or_404(User, username=slug)\r
+\r
if private and not (user == request.user or request.user.is_superuser):\r
raise ReturnImediatelyException(HttpResponseUnauthorized(request))\r
\r