app/soc/views/person/profile.py
author Todd Larsen <tlarsen@google.com>
Wed, 01 Oct 2008 02:11:56 +0000
changeset 229 a46c238be8db
parent 66 8c86470746fc
child 274 56e1c1721299
permissions -rw-r--r--
Show link to /site/user/list on /site/user/lookup when User is not found. http://code.google.com/p/soc/issues/detail?id=61 Patch by: Chen Lunpeng Review by: Todd Larsen (with modifications)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
#
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
#
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
#
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
66
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    17
"""Views of Person entity contents, a "profile".
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    18
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    19
edit: read-write form for modifying Person fields 
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    20
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    21
TODO:
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    22
public: read-only view of "public-only" Person fields
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
"""
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    25
__authors__ = [
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    26
  '"Augie Fackler" <durin42@gmail.com>',
66
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    27
  '"Todd Larsen" <tlarsen@google.com>',
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    28
  ]
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    29
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    30
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    31
from google.appengine.api import users
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    32
from django import http
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    33
from django import shortcuts
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    34
from django import newforms as forms
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    35
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    36
from soc.models import person
39
fa3545f99c02 Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents: 32
diff changeset
    37
from soc.views.helpers import forms_helpers
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    38
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    39
66
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    40
class EditForm(forms_helpers.DbModelForm):
39
fa3545f99c02 Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents: 32
diff changeset
    41
  """Django form displayed when creating or editing a Person.
fa3545f99c02 Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents: 32
diff changeset
    42
  """
fa3545f99c02 Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents: 32
diff changeset
    43
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    44
  class Meta:
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    45
    """Inner Meta class that defines some behavior for the form.
39
fa3545f99c02 Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents: 32
diff changeset
    46
    """
fa3545f99c02 Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents: 32
diff changeset
    47
    #: db.Model subclass for which the form will gather information
fa3545f99c02 Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents: 32
diff changeset
    48
    model = person.Person
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    49
39
fa3545f99c02 Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents: 32
diff changeset
    50
    #: list of model fields which will *not* be gathered by the form
fa3545f99c02 Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents: 32
diff changeset
    51
    exclude = ['user']
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    52
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    53
66
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    54
def edit(request, program=None, linkname=None,
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    55
         template='soc/person/profile/edit.html'):
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    56
  """View for a Person to modify the properties of a Person Model.
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    57
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    58
  Args:
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    59
    request: the standard django request object.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    60
    template: the template path to use for rendering the template.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    61
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    62
  Returns:
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    63
    A subclass of django.http.HttpResponse which either contains the form to
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    64
    be filled out, or a redirect to the correct view in the interface.
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    65
  """
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    66
  user = users.get_current_user()
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    67
  if not user:
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    68
    return http.HttpResponseRedirect(users.create_login_url(request.path))
39
fa3545f99c02 Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents: 32
diff changeset
    69
66
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    70
  # TODO(tlarsen)
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    71
  # if program:
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    72
  #   query for the human-readable program name and pass that to the form
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    73
  
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    74
  # TODO(tlarsen)
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    75
  # if linkname:
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    76
  #   query for a site-wide user profile for a friendly display name
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    77
  #      to use in the greeting
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    78
  # else:
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    79
  #   use user to query for a site-wide user profile for a friendly
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    80
  #      display name to use in the greeting
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    81
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    82
  form = EditForm()
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    83
  if request.method=='POST':
66
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    84
    form = EditForm(request.POST)
39
fa3545f99c02 Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents: 32
diff changeset
    85
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    86
    if not form.errors:
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    87
      return http.HttpResponse('This would update the model')
39
fa3545f99c02 Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents: 32
diff changeset
    88
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    89
  return shortcuts.render_to_response(
66
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    90
      template, dictionary={'template': template, 'form': form, 'user': user,
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    91
                            'program': program, 'linkname': linkname})