made /user/123 the path for user profiles. adjusted redirects and tests.

This commit is contained in:
Fred Wenzel 2010-02-02 18:03:47 +01:00
Родитель 7e81a75fe0
Коммит 440f81343e
5 изменённых файлов: 35 добавлений и 8 удалений

Просмотреть файл

@ -75,3 +75,8 @@ class TestRedirects(test.TestCase):
response = self.client.get('/', follow=True,
HTTP_ACCEPT_LANGUAGE='en-us;q=0.5, de')
self.assertRedirects(response, '/de/firefox/', status_code=301)
def test_users(self):
response = self.client.get('/users/info/1', follow=True)
self.assertRedirects(response, '/en-US/firefox/user/1/',
status_code=301)

Просмотреть файл

@ -3,8 +3,9 @@ import hashlib
import random
import string
from django.db import models
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User as DjangoUser
from django.db import models
import amo.models
from translations.fields import TranslatedField
@ -61,8 +62,7 @@ class UserProfile(amo.models.ModelBase):
return '%s: %s' % (self.id, self.display_name)
def get_absolute_url(self):
# XXX: use reverse
return '/users/%s' % self.id
return reverse('users.profile', args=[self.id])
@property
def display_name(self):

Просмотреть файл

@ -1,7 +1,16 @@
from django.conf.urls.defaults import patterns, url
from django.conf.urls.defaults import patterns, url, include
from . import views
urlpatterns = patterns('',
url('^logout$', views.logout_view, name='users.logout'),
# These will all start with /user/<user_id>/
detail_patterns = patterns('',
url('^$', views.profile, name='users.profile'),
)
urlpatterns = patterns('',
# URLs for a single user.
('^user/(?P<user_id>\d+)/', include(detail_patterns)),
url('^user/logout/$', views.logout_view, name='users.logout'),
)

Просмотреть файл

@ -1,9 +1,19 @@
from django.contrib.auth import logout
from django.http import HttpResponseRedirect
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import get_object_or_404
import jingo
from .models import UserProfile
from .signals import logged_out
def profile(request, user_id):
"""user profile display page"""
user = get_object_or_404(UserProfile, id=user_id)
return HttpResponse()
def logout_view(request):
# XXX - we should redirect to /en-US/firefox by default
redir = request.REQUEST.get('to', '/')

Просмотреть файл

@ -19,7 +19,7 @@ urlpatterns = patterns('',
('', include('browse.urls')),
# Users
('^users/', include('users.urls')),
('', include('users.urls')),
# AMO admin (not django admin).
('^admin/', include('admin.urls')),
@ -34,6 +34,9 @@ urlpatterns = patterns('',
('^reviews/display/(\d+)',
lambda r, id: redirect('reviews.list', id, permanent=True)),
('^users/info/(\d+)',
lambda r, id: redirect('users.profile', id, permanent=True)),
('^browse/type:3$',
lambda r: redirect('browse.language_tools', permanent=True)),