app/soc/views/models/user.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Mon, 10 Nov 2008 14:40:16 +0000
changeset 462 1f164cd0529b
parent 460 3a508b1ebaac
child 470 7ba510d3fad3
permissions -rw-r--r--
Adds a check to logic/valididate.py that checks the partial path format using a regexp. This regexp has been added to logic/path_link_name.py, therefore changing PATH_LINKNAME_REGEX to use the PARTIAL_PATH in building this regexp. Plus views/models/docs.py now uses the validation functions in the clean_ methods. Patch by: Lennard de Rijk Review by: Pawel Solyga
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
"""Views for Host profiles.
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
  ]
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
from google.appengine.api import users
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
from django import forms
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
from django.utils.translation import ugettext_lazy
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from soc.logic import dicts
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
from soc.logic import validate
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
from soc.logic.models import user as user_logic
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
from soc.views import helper
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
from soc.views.models import base
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
import soc.models.user
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
import soc.logic.models.user
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
import soc.views.helper
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
class CreateForm(helper.forms.BaseForm):
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
  """Django form displayed when creating a User.
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
  """
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
  id = forms.EmailField(
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
      label=soc.models.user.User.id.verbose_name,
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
      help_text=soc.models.user.User.id.help_text)
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
  link_name = forms.CharField(
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
      label=soc.models.user.User.link_name.verbose_name,
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
      help_text=soc.models.user.User.link_name.help_text)
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
  nick_name = forms.CharField(
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
      label=soc.models.user.User.nick_name.verbose_name)
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
  is_developer = forms.BooleanField(required=False,
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
      label=soc.models.user.User.is_developer.verbose_name,
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
      help_text=soc.models.user.User.is_developer.help_text)
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
  class Meta:
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    60
    model = None
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    62
  def clean_link_name(self):
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
    link_name = self.cleaned_data.get('link_name')
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
    if not validate.isLinkNameFormatValid(link_name):
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
      raise forms.ValidationError("This link name is in wrong format.")
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    67
    properties = {'link_name': link_name}
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
    user = soc.logic.models.user.logic.getForFields(properties, unique=True)
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    70
    if user and user.link_name != link_name:
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    71
      raise forms.ValidationError("This link name is already in use.")
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    72
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
    return link_name
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    74
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    75
  def clean_id(self):
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    76
    form_id = users.User(email=self.cleaned_data.get('id'))
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    77
    key_name = self.data.get('key_name')
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    78
    if key_name:
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    79
      user = user_logic.logic.getFromKeyName(key_name)
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
      old_email = user.id.email()
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    81
    else:
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    82
      old_email = None
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    83
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    84
    new_email = form_id.email()
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    85
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    86
    if new_email != old_email and user_logic.logic.getFromFields(email=new_email):
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
      raise forms.ValidationError("This account is already in use.")
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    88
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    89
    return form_id
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    90
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    91
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    92
class EditForm(CreateForm):
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    93
  """Django form displayed when editing a User.
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    94
  """
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    95
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    96
  key_name = forms.CharField(widget=forms.HiddenInput)
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    97
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    98
class View(base.View):
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    99
  """View methods for the User model
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   100
  """
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   101
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   102
  def __init__(self, original_params=None, original_rights=None):
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   103
    """Defines the fields and methods required for the base View class
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   104
    to provide the user with list, public, create, edit and delete views.
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   105
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   106
    Params:
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   107
      original_params: a dict with params for this View
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   108
      original_rights: a dict with right definitions for this View
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   109
    """
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   110
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   111
    self._logic = soc.logic.models.user.logic
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   112
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   113
    params = {}
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   114
    rights = {}
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   115
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   116
    params['name'] = "User"
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   117
    params['name_short'] = "User"
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   118
    params['name_plural'] = "Users"
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   119
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   120
    params['edit_form'] = EditForm
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   121
    params['create_form'] = CreateForm
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   122
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   123
    # TODO(tlarsen) Add support for Django style template lookup
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   124
    params['edit_template'] = 'soc/models/edit.html'
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   125
    params['public_template'] = 'soc/user/public.html'
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   126
    params['list_template'] = 'soc/models/list.html'
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   127
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   128
    params['lists_template'] = {
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   129
      'list_main': 'soc/list/list_main.html',
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   130
      'list_pagination': 'soc/list/list_pagination.html',
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   131
      'list_row': 'soc/user/list/user_row.html',
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   132
      'list_heading': 'soc/user/list/user_heading.html',
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   133
    }
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   134
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   135
    params['delete_redirect'] = '/user/list'
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   136
    params['create_redirect'] = '/user/create'
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   137
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   138
    params['save_message'] = [ugettext_lazy('Profile saved.')]
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   139
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   140
    params['edit_params'] = {
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   141
        self.DEF_SUBMIT_MSG_PARAM_NAME: self.DEF_SUBMIT_MSG_PROFILE_SAVED,
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   142
        }
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   143
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   144
    rights['list'] = [helper.access.checkIsDeveloper]
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   145
    rights['delete'] = [helper.access.checkIsDeveloper]
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   146
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   147
    params = dicts.merge(original_params, params)
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   148
    rights = dicts.merge(original_rights, rights)
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   149
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   150
    base.View.__init__(self, rights=rights, params=params)
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   151
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   152
  def self(self, request, page=None, params=None, **kwargs):
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   153
    """
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   154
    """
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   155
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   156
    params = dicts.merge(params, {'edit_template': 'soc/user/edit_self.html'})
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   157
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   158
    id = users.get_current_user()
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   159
    email = id.email()
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   160
    properties = {'id': id}
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   161
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   162
    entity = self._logic.getForFields(properties, unique=True)
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   163
    keys = self._logic.getKeyFieldNames()
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   164
    values = self._logic.getKeyValues(entity)
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   165
    key_fields = dicts.zip(keys, values)
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   166
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   167
    return self.edit(request, page, params=params, **key_fields)
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   168
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   169
  def _editPost(self, request, entity, fields):
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   170
    """See base.View._editPost().
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   171
    """
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   172
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   173
    fields['email'] = fields['id'].email()
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   174
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   175
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   176
view = View()
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   177
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   178
create = view.create
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   179
delete = view.delete
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   180
edit = view.edit
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   181
list = view.list
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   182
public = view.public
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   183
self = view.self