app/soc/views/person/profile.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sun, 12 Oct 2008 00:12:53 +0000
changeset 299 a1cc853a56e5
parent 298 c76a366c7ab4
child 316 9efdc7bc3565
permissions -rw-r--r--
Refactor nearly all the soc.logic code to use the Base class Instead of having a lot of duplicate code, this patch aims to reduce this duplication by introducing a Base abstraction. Patch by: Sverre Rabbelier Reviewed by: to-be-reviewed
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
274
56e1c1721299 Move helpers/forms_helpers.py to helper/forms.py.
Todd Larsen <tlarsen@google.com>
parents: 66
diff changeset
    37
from soc.views import helper
56e1c1721299 Move helpers/forms_helpers.py to helper/forms.py.
Todd Larsen <tlarsen@google.com>
parents: 66
diff changeset
    38
import soc.views.helper.forms
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    39
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    40
274
56e1c1721299 Move helpers/forms_helpers.py to helper/forms.py.
Todd Larsen <tlarsen@google.com>
parents: 66
diff changeset
    41
class EditForm(helper.forms.DbModelForm):
39
fa3545f99c02 Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents: 32
diff changeset
    42
  """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
    43
  """
fa3545f99c02 Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents: 32
diff changeset
    44
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    45
  class Meta:
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    46
    """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
    47
    """
fa3545f99c02 Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents: 32
diff changeset
    48
    #: 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
    49
    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
    50
39
fa3545f99c02 Major revamp of Person model, splitting up poorly-validated properties into
Todd Larsen <tlarsen@google.com>
parents: 32
diff changeset
    51
    #: 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
    52
    exclude = ['user']
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    53
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    54
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
    55
def edit(request, program=None, link_name=None,
66
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    56
         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
    57
  """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
    58
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    59
  Args:
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    60
    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
    61
    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
    62
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    63
  Returns:
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    64
    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
    65
    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
    66
  """
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    67
  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
    68
  if not user:
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    69
    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
    70
66
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    71
  # TODO(tlarsen)
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    72
  # if program:
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    73
  #   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
    74
  
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    75
  # TODO(tlarsen)
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 274
diff changeset
    76
  # if link_name:
66
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    77
  #   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
    78
  #      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
    79
  # else:
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    80
  #   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
    81
  #      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
    82
8c86470746fc Finished migrating the "proto" app (which only contained a Person profile edit
Todd Larsen <tlarsen@google.com>
parents: 54
diff changeset
    83
  form = EditForm()
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    84
  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
    85
    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
    86
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    87
    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
    88
      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
    89
31
8b43c541afa7 First iteration of a "prototype" Melange app, along with an initial Person
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    90
  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
    91
      template, dictionary={'template': template, 'form': form, 'user': user,
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 274
diff changeset
    92
                            'program': program, 'link_name': link_name})