102 # create default template context for use with any templates |
102 # create default template context for use with any templates |
103 context = helper.responses.getUniversalContext(request) |
103 context = helper.responses.getUniversalContext(request) |
104 |
104 |
105 if (not id) and (not link_name): |
105 if (not id) and (not link_name): |
106 # not logged in, and no link name, so request that the user sign in |
106 # not logged in, and no link name, so request that the user sign in |
107 return simple.requestLogin(request, template, context, page=page, |
107 return simple.requestLogin(request, page, template, context, |
108 # TODO(tlarsen): /user/profile could be a link to a help page instead |
108 # TODO(tlarsen): /user/profile could be a link to a help page instead |
109 login_message_fmt='To create a new' |
109 login_message_fmt='To create a new' |
110 ' <a href="/user/profile">User Profile</a>' |
110 ' <a href="/user/profile">User Profile</a>' |
111 ' or modify an existing one, you must first' |
111 ' or modify an existing one, you must first' |
112 ' <a href="%(sign_in)s">sign in</a>.') |
112 ' <a href="%(sign_in)s">sign in</a>.') |
113 |
113 |
114 if (not id) and link_name: |
114 if (not id) and link_name: |
115 # not logged in, so show read-only public profile for link_name user |
115 # not logged in, so show read-only public profile for link_name user |
116 return simple.public(request, template, link_name, context, page) |
116 return simple.public(request, page=page, template=template, |
|
117 link_name=link_name, context=context) |
117 |
118 |
118 link_name_user = None |
119 link_name_user = None |
119 |
120 |
120 # try to fetch User entity corresponding to link_name if one exists |
121 # try to fetch User entity corresponding to link_name if one exists |
121 try: |
122 try: |
122 if link_name: |
123 if link_name: |
123 link_name_user = id_user.getUserFromLinkNameOr404(link_name) |
124 link_name_user = id_user.getUserFromLinkNameOr404(link_name) |
124 except out_of_band.ErrorResponse, error: |
125 except out_of_band.ErrorResponse, error: |
125 # show custom 404 page when link name doesn't exist in Datastore |
126 # show custom 404 page when link name doesn't exist in Datastore |
126 return simple.errorResponse(request, error, template, context, page) |
127 return simple.errorResponse(request, page, error, template, context) |
127 |
128 |
128 # link_name_user will be None here if link name was already None... |
129 # link_name_user will be None here if link name was already None... |
129 if link_name_user and (link_name_user.id != id): |
130 if link_name_user and (link_name_user.id != id): |
130 # link_name_user exists but is not the currently logged in Google Account, |
131 # link_name_user exists but is not the currently logged in Google Account, |
131 # so show public view for that (other) User entity |
132 # so show public view for that (other) User entity |
132 return simple.public(request, template, link_name, context, page) |
133 return simple.public(request, page=page, template=template, |
|
134 link_name=link_name, context=context) |
133 |
135 |
134 if request.method == 'POST': |
136 if request.method == 'POST': |
135 form = UserForm(request.POST) |
137 form = UserForm(request.POST) |
136 |
138 |
137 if form.is_valid(): |
139 if form.is_valid(): |