app/soc/views/user/profile.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Wed, 20 Aug 2008 21:59:00 +0000
changeset 98 b2b823466a8b
parent 85 426b4ca2a72a
child 99 8c38b546a3cf
permissions -rw-r--r--
User Profile view (without controller yet). Patch by: Pawel Solyga Review by: Todd Larsen Review issue: 386 Review URL: http://codereviews.googleopensourceprograms.com/386
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
83
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     2
#
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     4
#
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     8
#
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    10
#
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    16
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    17
"""Views relevant to the User role.
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    18
"""
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    19
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    20
__authors__ = [
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    21
  '"Pawel Solyga" <pawel.solyga@gmail.com>',
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    22
  ]
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    23
98
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    24
import re
83
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    25
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    26
from google.appengine.api import users
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    27
from django import http
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    28
from django import shortcuts
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    29
from django import newforms as forms
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    30
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    31
from soc.views.helpers import forms_helpers
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    32
from soc.views.helpers import response_helpers
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    33
98
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    34
import soc.models.user
83
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    35
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    36
class UserForm(forms_helpers.DbModelForm):
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    37
  """Django form displayed when creating or editing a User.
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    38
  """
98
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    39
  LINKNAME_PATTERN = r'''(?x)
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    40
      ^
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    41
      [0-9a-z]  # start with ASCII digit or lowercase
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    42
      (
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    43
      [0-9a-z]  # additional ASCII digit or lowercase
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    44
      |         # -OR-
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    45
      _[0-9a-z] # underscore and ASCII digit or lowercase
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    46
      )*        # zero or more of OR group
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    47
      $'''
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    48
  LINKNAME_REGEX = re.compile(LINKNAME_PATTERN)
83
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    49
98
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    50
  
83
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    51
  class Meta:
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    52
    """Inner Meta class that defines some behavior for the form.
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    53
    """
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    54
    #: db.Model subclass for which the form will gather information
98
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    55
    model = soc.models.user.User
83
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    56
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    57
    #: list of model fields which will *not* be gathered by the form
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    58
    exclude = ['id']
98
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    59
  
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    60
  def clean_link_name(self):
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    61
    linkname = self.cleaned_data.get('link_name')
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    62
    linkname_user = soc.models.user.User.getUserForLinkname(linkname)
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    63
    user = users.get_current_user()
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    64
    # if linkname exist in datastore and doesn't belong to current user
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    65
    if linkname_user and (linkname_user.id != user):
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    66
      raise forms.ValidationError("This link name is already in use.")
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    67
    elif not self.LINKNAME_REGEX.match(linkname):
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    68
      raise forms.ValidationError("This link name is in wrong format.")
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    69
    return linkname
83
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    70
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    71
85
426b4ca2a72a Move soc.views.user.profile.profile() to soc.views.user.profile.edit().
Todd Larsen <tlarsen@google.com>
parents: 83
diff changeset
    72
def edit(request, linkname=None, template='soc/user/profile/edit.html'):
83
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    73
  """View for a User to modify the properties of a UserModel.
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    74
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    75
  Args:
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    76
    request: the standard django request object.
98
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    77
    linkname: the User's site-unique "linkname" extracted from the URL
83
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    78
    template: the template path to use for rendering the template.
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    79
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    80
  Returns:
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    81
    A subclass of django.http.HttpResponse which either contains the form to
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    82
    be filled out, or a redirect to the correct view in the interface.
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    83
  """
98
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    84
  #TODO(solydzajs): create controller for User and cleanup code in this handler
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    85
  
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    86
  #: If user not signed in redirect to sign-in page
83
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    87
  user = users.get_current_user()
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    88
  if not user:
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    89
    return http.HttpResponseRedirect(users.create_login_url(request.path))
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    90
98
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    91
  soc_user = soc.models.user.User.getUser(user)
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    92
  
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    93
  #: Show custom 404 page when linkname in url doesn't match current user
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    94
  if linkname:
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    95
    linkname_user = soc.models.user.User.getUserForLinkname(linkname)
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    96
    if (linkname_user and linkname_user.id != user) or not linkname_user:
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    97
      return http.HttpResponseNotFound('No user exists with that link name "%s"' %
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    98
                                linkname)
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
    99
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   100
  #: GET method
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   101
  if (request.method != 'POST') and soc_user:
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   102
    form = UserForm(initial={'nick_name': soc_user.nick_name,
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   103
                             'link_name': soc_user.link_name})
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   104
    return response_helpers.respond(request,
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   105
        template, {'template': template, 
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   106
                   'form': form, 
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   107
                   'soc_nick_name': soc_user.nick_name})
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   108
  
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   109
  #: POST method
83
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   110
  form = UserForm()
98
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   111
  if request.method == 'POST':
83
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   112
    form = UserForm(request.POST)
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   113
98
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   114
    if form.is_valid():
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   115
      linkname = form.cleaned_data.get('link_name')
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   116
      nickname = form.cleaned_data.get("nick_name")
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   117
      if not soc_user:
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   118
        soc_user = soc.models.user.User(id = user,link_name = linkname,
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   119
                                        nick_name = nickname)
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   120
      else:
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   121
        soc_user.nick_name = nickname
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   122
        soc_user.link_name = linkname
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   123
      soc_user.put()
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   124
      return response_helpers.respond(request,
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   125
              template, {'template': template, 
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   126
                        'form': form, 
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   127
                        'soc_nick_name': nickname,
b2b823466a8b User Profile view (without controller yet).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 85
diff changeset
   128
                        'submit_message': 'Profile saved.'})
83
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   129
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   130
  return response_helpers.respond(request,
3f4f7c540b75 Created response helper respond() function that is used to generate base templates and it's child templates (handles sign in/out links, user name etc).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   131
      template, {'template': template, 'form': form})