Clean up User Model and User profile edit view now that soc.logic.site.id_user
module exists. Change usage of "user" to be "id" the variable refers to a
Google Account and not a User entity.
Patch by: Todd Larsen
Review by: to-be-reviewed
--- a/app/soc/models/user.py Thu Aug 28 22:23:11 2008 +0000
+++ b/app/soc/models/user.py Thu Aug 28 22:27:40 2008 +0000
@@ -22,11 +22,17 @@
'"Pawel Solyga" <pawel.solyga@gmail.com>',
]
+
+import logging
+
from google.appengine.ext import db
from django.utils.translation import ugettext_lazy
+from soc.models import base
+from soc.views.helpers import forms_helpers
-class User(db.Model):
+
+class User(base.ModelWithFieldAttributes):
"""A user and associated login credentials, the fundamental identity entity.
User is a separate Model class from Person because the same login
@@ -63,36 +69,3 @@
link_name.help_text = ugettext_lazy(
'Field used in URLs to identify user. '
'Lower ASCII characters only.')
-
- @staticmethod
- def doesUserExist(id=None):
- """Returns if user already exists in the Datastore.
-
- Args:
- user: a Google Account object,
- """
- #: let's do a gql query and check if user exists in datastore
- data = self.getUserForId(id)
- if data:
- return True
- else:
- return False
-
- @staticmethod
- def getUserForId(id=None):
- """Returns User entity from datastore, or None if not found.
-
- Args:
- user: a Google Account object,
- """
- return User.gql('WHERE id = :1', id).get()
-
- @staticmethod
- def getUserForLinkname(link_name=None):
- """Returns User entity for linkname or None if not found.
-
- Args:
- link_name: linkname used in URLs to identify user,
- """
- return User.gql('WHERE link_name = :1', link_name).get()
-
\ No newline at end of file
--- a/app/soc/templates/soc/base.html Thu Aug 28 22:23:11 2008 +0000
+++ b/app/soc/templates/soc/base.html Thu Aug 28 22:27:40 2008 +0000
@@ -30,7 +30,7 @@
{% if id %}
<b>{{ id.email }} ({{ id.nickname }})</b> |
{% endif %}
- {% if is_dev %}
+ {% if is_debug %}
<a class="novisit" target="_blank" href="/_ah/admin">Admin</a> |
{% endif %}
<a class="novisit" href="http://code.google.com/p/soc/issues/list">Report bugs</a> |
--- a/app/soc/templates/soc/user/profile/edit.html Thu Aug 28 22:23:11 2008 +0000
+++ b/app/soc/templates/soc/user/profile/edit.html Thu Aug 28 22:27:40 2008 +0000
@@ -24,9 +24,6 @@
{% block body %}
<p>
<p>
-{% if submit_message %}<h3>{{ submit_message }}</h3>{% endif %}
-</p>
-<p>
{% block instructions %}
Please use this form to set basic site-wide settings for your participation in Google Open Source Programs.
{% endblock %}
@@ -35,11 +32,22 @@
<table>
{% field_as_table_row form.nick_name %}
{% field_as_table_row form.link_name %}
+ <tr>
+ <td colspan="4"> </td>
+ </tr>
+ <tr>
+ <td>
+ <input style="font-weight: bold" type="submit" value="Save Changes"/></span>
+ </td>
+ <td>
+ <input type="button" onclick="location.href='/'" value="Cancel"/>
+ </td>
+ <td> </td>
+ <td>
+ {% if submit_message %}<b><i>{{ submit_message }}</i></b>{% endif %}
+ </td>
+ </tr>
</table>
- <div class="buttons">
- <input style="font-weight: bold" type="submit" value="Save Changes"/></span>
- <input type="button" onclick="location.href='/'" value="Cancel"/>
- </div>
</form>
</p>
-{% endblock %}
\ No newline at end of file
+{% endblock %}
--- a/app/soc/views/user/profile.py Thu Aug 28 22:23:11 2008 +0000
+++ b/app/soc/views/user/profile.py Thu Aug 28 22:27:40 2008 +0000
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-"""Views relevant to the User role.
+"""Views for editing and examining User profiles.
"""
__authors__ = [
@@ -28,11 +28,13 @@
from django import shortcuts
from django import newforms as forms
+from soc.logic.site import id_user
from soc.views.helpers import forms_helpers
from soc.views.helpers import response_helpers
import soc.models.user
+
class UserForm(forms_helpers.DbModelForm):
"""Django form displayed when creating or editing a User.
"""
@@ -46,7 +48,6 @@
)* # zero or more of OR group
$'''
LINKNAME_REGEX = re.compile(LINKNAME_PATTERN)
-
class Meta:
"""Inner Meta class that defines some behavior for the form.
@@ -59,10 +60,10 @@
def clean_link_name(self):
linkname = self.cleaned_data.get('link_name')
- linkname_user = soc.models.user.User.getUserForLinkname(linkname)
- current_id = users.get_current_user()
+ linkname_user = id_user.getUserFromLinkName(linkname)
+ id = users.get_current_user()
# if linkname exist in datastore and doesn't belong to current user
- if linkname_user and (linkname_user.id != current_id):
+ if linkname_user and (linkname_user.id != id):
raise forms.ValidationError("This link name is already in use.")
elif not self.LINKNAME_REGEX.match(linkname):
raise forms.ValidationError("This link name is in wrong format.")
@@ -99,15 +100,15 @@
elif not current_id and linkname:
return public(request, linkname)
- user = soc.models.user.User.getUserForId(current_id)
+ user = id_user.getUserFromId(current_id)
#: Show custom 404 page when linkname doesn't exist in datastore
#: or show public view for linkname user
if linkname:
- linkname_user = soc.models.user.User.getUserForLinkname(linkname)
+ linkname_user = id_user.getUserFromLinkName(linkname)
if not linkname_user:
return http.HttpResponseNotFound('No user exists with that link name "%s"' %
- linkname)
+ linkname)
elif linkname_user and (linkname_user.id != current_id):
return public(request, linkname)
@@ -117,8 +118,7 @@
'link_name': user.link_name})
return response_helpers.respond(request,
template, {'template': template,
- 'form': form,
- 'user': user})
+ 'form': form})
#: POST method
form = UserForm()
@@ -129,16 +129,15 @@
linkname = form.cleaned_data.get('link_name')
nickname = form.cleaned_data.get("nick_name")
if not user:
- user = soc.models.user.User(id = user,link_name = linkname,
- nick_name = nickname)
+ user = soc.models.user.User(id=id,link_name=linkname,
+ nick_name=nickname)
else:
user.nick_name = nickname
user.link_name = linkname
user.put()
return response_helpers.respond(request,
template, {'template': template,
- 'form': form,
- 'user': user,
+ 'form': form,
'submit_message': 'Profile saved.'})
return response_helpers.respond(request,
@@ -160,14 +159,14 @@
#: If linkname is empty or not a valid linkname on the site, display
#: "user does not exist", otherwise render public view for linkname user
if linkname:
- linkname_user = soc.models.user.User.getUserForLinkname(linkname)
+ linkname_user = id_user.getUserFromLinkName(linkname)
if not linkname_user:
return http.HttpResponseNotFound('No user exists with that link name "%s"' %
- linkname)
+ linkname)
else:
return response_helpers.respond(request,
template, {'template': template,
'user': linkname_user})
return http.HttpResponseNotFound('No user exists with that link name "%s"' %
- linkname)
+ linkname)