]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/models/user.py
Merge pull request #46 from udacity/subfolder_fixes
[osqa.git] / forum / models / user.py
index 7f15d21dc38db441befcb9c6a5c554eaddd06cd5..131ae5491d06c013f5b317c794ace47a611cb07e 100644 (file)
@@ -5,6 +5,7 @@ from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
 from django.contrib.contenttypes.models import ContentType
 from django.contrib.auth.models import User as DjangoUser, AnonymousUser as DjangoAnonymousUser
 from django.db.models import Q, Manager
 from django.contrib.contenttypes.models import ContentType
 from django.contrib.auth.models import User as DjangoUser, AnonymousUser as DjangoAnonymousUser
 from django.db.models import Q, Manager
+from django.core.urlresolvers import get_script_prefix
 
 from django.utils.encoding import smart_unicode
 
 
 from django.utils.encoding import smart_unicode
 
@@ -117,7 +118,7 @@ class UserManager(CachedManager):
             
             if len(matching_users) == 1:
                 return matching_users[0]
             
             if len(matching_users) == 1:
                 return matching_users[0]
-            else:
+            elif len(matching_users) > 1:
                 for user in matching_users:
                     if user.username == kwargs['username']:
                         return user
                 for user in matching_users:
                     if user.username == kwargs['username']:
                         return user
@@ -165,8 +166,8 @@ class User(BaseModel, DjangoUser):
         #todo: temporary thing, for now lets just assume that the site owner will always be the first user of the application
         return self.id == 1
 
         #todo: temporary thing, for now lets just assume that the site owner will always be the first user of the application
         return self.id == 1
 
-    @property
-    def decorated_name(self):
+
+    def _decorated_name(self):
         username = smart_unicode(self.username)
 
         if len(username) > TRUNCATE_USERNAMES_LONGER_THAN and TRUNCATE_LONG_USERNAMES:
         username = smart_unicode(self.username)
 
         if len(username) > TRUNCATE_USERNAMES_LONGER_THAN and TRUNCATE_LONG_USERNAMES:
@@ -181,6 +182,10 @@ class User(BaseModel, DjangoUser):
 
         return username
 
 
         return username
 
+    @property
+    def decorated_name(self):
+        return self._decorated_name()
+
     @property
     def last_activity(self):
         try:
     @property
     def last_activity(self):
         try:
@@ -205,15 +210,6 @@ class User(BaseModel, DjangoUser):
             sub_settings = SubscriptionSettings(user=self)
             sub_settings.save()
 
             sub_settings = SubscriptionSettings(user=self)
             sub_settings.save()
 
-    def get_messages(self):
-        messages = []
-        for m in self.message_set.all():
-            messages.append(m.message)
-        return messages
-
-    def delete_messages(self):
-        self.message_set.all().delete()
-
     @models.permalink
     def get_profile_url(self):
         keyword_arguments = {
     @models.permalink
     def get_profile_url(self):
         keyword_arguments = {
@@ -226,7 +222,9 @@ class User(BaseModel, DjangoUser):
         return ('user_profile', (), keyword_arguments)
 
     def get_absolute_url(self):
         return ('user_profile', (), keyword_arguments)
 
     def get_absolute_url(self):
-        return self.get_profile_url()
+        root_relative_url = self.get_profile_url()
+        relative_url = root_relative_url[len(get_script_prefix()):]
+        return '%s/%s' % (django_settings.APP_URL, relative_url)
 
     @models.permalink
     def get_asked_url(self):
 
     @models.permalink
     def get_asked_url(self):