app/soc/views/user/profile.py
changeset 83 3f4f7c540b75
child 85 426b4ca2a72a
equal deleted inserted replaced
82:1456e633bf8a 83:3f4f7c540b75
       
     1 #!/usr/bin/python2.5
       
     2 #
       
     3 # Copyright 2008 the Melange authors.
       
     4 #
       
     5 # Licensed under the Apache License, Version 2.0 (the "License");
       
     6 # you may not use this file except in compliance with the License.
       
     7 # You may obtain a copy of the License at
       
     8 #
       
     9 #   http://www.apache.org/licenses/LICENSE-2.0
       
    10 #
       
    11 # Unless required by applicable law or agreed to in writing, software
       
    12 # distributed under the License is distributed on an "AS IS" BASIS,
       
    13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    14 # See the License for the specific language governing permissions and
       
    15 # limitations under the License.
       
    16 
       
    17 """Views relevant to the User role.
       
    18 """
       
    19 
       
    20 __authors__ = [
       
    21   '"Pawel Solyga" <pawel.solyga@gmail.com>',
       
    22   ]
       
    23 
       
    24 
       
    25 from google.appengine.api import users
       
    26 from django import http
       
    27 from django import shortcuts
       
    28 from django import newforms as forms
       
    29 
       
    30 from soc.models import user
       
    31 from soc.views.helpers import forms_helpers
       
    32 from soc.views.helpers import response_helpers
       
    33 
       
    34 
       
    35 class UserForm(forms_helpers.DbModelForm):
       
    36   """Django form displayed when creating or editing a User.
       
    37   """
       
    38 
       
    39   class Meta:
       
    40     """Inner Meta class that defines some behavior for the form.
       
    41     """
       
    42     #: db.Model subclass for which the form will gather information
       
    43     model = user.User
       
    44 
       
    45     #: list of model fields which will *not* be gathered by the form
       
    46     exclude = ['id']
       
    47 
       
    48 
       
    49 def profile(request, linkname=None, template='soc/user/profile.html'):
       
    50   """View for a User to modify the properties of a UserModel.
       
    51 
       
    52   Args:
       
    53     request: the standard django request object.
       
    54     template: the template path to use for rendering the template.
       
    55 
       
    56   Returns:
       
    57     A subclass of django.http.HttpResponse which either contains the form to
       
    58     be filled out, or a redirect to the correct view in the interface.
       
    59   """
       
    60   user = users.get_current_user()
       
    61   if not user:
       
    62     return http.HttpResponseRedirect(users.create_login_url(request.path))
       
    63 
       
    64   form = UserForm()
       
    65   if request.method=='POST':
       
    66     form = UserForm(request.POST)
       
    67 
       
    68     if not form.errors:
       
    69       return http.HttpResponse('This would update the model')
       
    70 
       
    71   return response_helpers.respond(request,
       
    72       template, {'template': template, 'form': form})