app/soc/views/models/user.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Thu, 22 Jan 2009 22:02:40 +0000
changeset 906 275d2f457c50
parent 891 3d40190f35b6
child 934 9fcc08971efe
permissions -rw-r--r--
Fix missing dots in soc.views.helper.decoratos module docstrings. Patch by: Pawel Solyga Review by: to-be-reviewed
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
590
37735d97b541 Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents: 587
diff changeset
    17
"""Views for User profiles.
460
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>',
470
7ba510d3fad3 In soc.views.models.user module fix too long line. Delete unused email variable, add missing doc and rename self method and global variable to editSelf and edit_self so it's not confused with "self" used in classes and there is no outerscope variable name overwriting anymore.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 460
diff changeset
    22
    '"Pawel Solyga" <pawel.solyga@gmail.com>',
460
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
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 495
diff changeset
    25
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
from google.appengine.api import users
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
from django import forms
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
from soc.logic import dicts
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
from soc.logic import validate
856
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
    32
from soc.logic.models.site import logic as site_logic
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
    33
from soc.logic.models.user import logic as user_logic
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
from soc.views import helper
891
3d40190f35b6 Move getToSLink() to soc.views.helper.redirects.getToSRedirect().
Todd Larsen <tlarsen@google.com>
parents: 858
diff changeset
    35
from soc.views.helper import redirects
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
from soc.views.models import base
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
549
00a9ce3dc082 Fix some broken help_text bubbles (they are truncated or not displayed if they
Todd Larsen <tlarsen@google.com>
parents: 547
diff changeset
    38
import soc.models.linkable
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
import soc.models.user
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
import soc.logic.models.user
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
import soc.views.helper
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
class CreateForm(helper.forms.BaseForm):
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
  """Django form displayed when creating a User.
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
  """
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
479
50bab5e71a66 Make sure the user edit form has the complete mail adress in the user account field when opened. Replace confusing id field in form with email field. Editing the email adress of an existing user will still result in an error but that should be fixed soon.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 473
diff changeset
    48
  email = forms.EmailField(
481
94834a1e6c01 Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents: 479
diff changeset
    49
      label=soc.models.user.User.account.verbose_name,
94834a1e6c01 Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents: 479
diff changeset
    50
      help_text=soc.models.user.User.account.help_text)
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 507
diff changeset
    52
  link_id = forms.CharField(
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 507
diff changeset
    53
      label=soc.models.user.User.link_id.verbose_name,
549
00a9ce3dc082 Fix some broken help_text bubbles (they are truncated or not displayed if they
Todd Larsen <tlarsen@google.com>
parents: 547
diff changeset
    54
      help_text=soc.models.linkable.Linkable.link_id.help_text)
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
546
850d9a5ad894 Rename the User.public_name Property to simply 'name' (but leave the verbose
Todd Larsen <tlarsen@google.com>
parents: 543
diff changeset
    56
  name = forms.CharField(
549
00a9ce3dc082 Fix some broken help_text bubbles (they are truncated or not displayed if they
Todd Larsen <tlarsen@google.com>
parents: 547
diff changeset
    57
      label=soc.models.user.User.name.verbose_name,
00a9ce3dc082 Fix some broken help_text bubbles (they are truncated or not displayed if they
Todd Larsen <tlarsen@google.com>
parents: 547
diff changeset
    58
      help_text=soc.models.user.User.name.help_text)
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    60
  is_developer = forms.BooleanField(required=False,
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
      label=soc.models.user.User.is_developer.verbose_name,
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    62
      help_text=soc.models.user.User.is_developer.help_text)
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
813
68c0eb8656bc Display state (but dis-allow edits) of User's agrees_to_tos boolean Property.
Todd Larsen <tlarsen@google.com>
parents: 799
diff changeset
    64
  agrees_to_tos = forms.BooleanField(required=False,
68c0eb8656bc Display state (but dis-allow edits) of User's agrees_to_tos boolean Property.
Todd Larsen <tlarsen@google.com>
parents: 799
diff changeset
    65
      widget=helper.widgets.ReadOnlyBool(),
68c0eb8656bc Display state (but dis-allow edits) of User's agrees_to_tos boolean Property.
Todd Larsen <tlarsen@google.com>
parents: 799
diff changeset
    66
      label=soc.models.user.User.agrees_to_tos.verbose_name,
68c0eb8656bc Display state (but dis-allow edits) of User's agrees_to_tos boolean Property.
Todd Larsen <tlarsen@google.com>
parents: 799
diff changeset
    67
      help_text=soc.models.user.User.agrees_to_tos.help_text)
68c0eb8656bc Display state (but dis-allow edits) of User's agrees_to_tos boolean Property.
Todd Larsen <tlarsen@google.com>
parents: 799
diff changeset
    68
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    69
  class Meta:
629
492df53e4a0f Add missing dots and fix too long line in soc.views.helper.dynaform module. Remove unused imports in soc.views.models.document module. Fix too long lines. Add missing docstring for Meta classes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 623
diff changeset
    70
    """Inner Meta class that defines some behavior for the form.
492df53e4a0f Add missing dots and fix too long line in soc.views.helper.dynaform module. Remove unused imports in soc.views.models.document module. Fix too long lines. Add missing docstring for Meta classes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 623
diff changeset
    71
    """
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    72
    model = None
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 507
diff changeset
    74
  def clean_link_id(self):
650
33b6dcae5615 Changed clean_link_id to convert the input to lower characters for user comfort.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 629
diff changeset
    75
    link_id = self.cleaned_data.get('link_id').lower()
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 507
diff changeset
    76
    if not validate.isLinkIdFormatValid(link_id):
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 507
diff changeset
    77
      raise forms.ValidationError("This link ID is in wrong format.")
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    78
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 507
diff changeset
    79
    properties = {'link_id': link_id}
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
531
b74bf6bf1ccf Make editSelf() work by adding 'inheritance_line' to the list of excluded
Todd Larsen <tlarsen@google.com>
parents: 529
diff changeset
    81
    link_id_user = soc.logic.models.user.logic.getForFields(properties,
b74bf6bf1ccf Make editSelf() work by adding 'inheritance_line' to the list of excluded
Todd Larsen <tlarsen@google.com>
parents: 529
diff changeset
    82
                                                            unique=True)
483
70f21691b0e1 Fix broken User link_name validations. Changes in r1014 still caused some problems so I came out with new idea to compare User accounts (previously called "id").
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 482
diff changeset
    83
    key_name = self.data.get('key_name')
70f21691b0e1 Fix broken User link_name validations. Changes in r1014 still caused some problems so I came out with new idea to compare User accounts (previously called "id").
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 482
diff changeset
    84
    if key_name:
856
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
    85
      key_name_user = user_logic.getFromKeyName(key_name)
483
70f21691b0e1 Fix broken User link_name validations. Changes in r1014 still caused some problems so I came out with new idea to compare User accounts (previously called "id").
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 482
diff changeset
    86
      
531
b74bf6bf1ccf Make editSelf() work by adding 'inheritance_line' to the list of excluded
Todd Larsen <tlarsen@google.com>
parents: 529
diff changeset
    87
      if (link_id_user and key_name_user
b74bf6bf1ccf Make editSelf() work by adding 'inheritance_line' to the list of excluded
Todd Larsen <tlarsen@google.com>
parents: 529
diff changeset
    88
          and (link_id_user.account != key_name_user.account)):
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 507
diff changeset
    89
        raise forms.ValidationError("This link ID is already in use.")
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    90
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 507
diff changeset
    91
    return link_id
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    92
479
50bab5e71a66 Make sure the user edit form has the complete mail adress in the user account field when opened. Replace confusing id field in form with email field. Editing the email adress of an existing user will still result in an error but that should be fixed soon.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 473
diff changeset
    93
  def clean_email(self):
481
94834a1e6c01 Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents: 479
diff changeset
    94
    form_account = users.User(email=self.cleaned_data.get('email'))
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    95
    key_name = self.data.get('key_name')
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    96
    if key_name:
856
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
    97
      user = user_logic.getFromKeyName(key_name)
481
94834a1e6c01 Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents: 479
diff changeset
    98
      old_email = user.account.email()
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    99
    else:
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   100
      old_email = None
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   101
481
94834a1e6c01 Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents: 479
diff changeset
   102
    new_email = form_account.email()
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   103
470
7ba510d3fad3 In soc.views.models.user module fix too long line. Delete unused email variable, add missing doc and rename self method and global variable to editSelf and edit_self so it's not confused with "self" used in classes and there is no outerscope variable name overwriting anymore.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 460
diff changeset
   104
    if new_email != old_email \
856
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
   105
        and user_logic.getForFields({'email': new_email}, unique=True):
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   106
      raise forms.ValidationError("This account is already in use.")
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   107
479
50bab5e71a66 Make sure the user edit form has the complete mail adress in the user account field when opened. Replace confusing id field in form with email field. Editing the email adress of an existing user will still result in an error but that should be fixed soon.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 473
diff changeset
   108
    return self.cleaned_data.get('email')
460
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
class EditForm(CreateForm):
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   112
  """Django form displayed when editing a User.
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   113
  """
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   114
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   115
  key_name = forms.CharField(widget=forms.HiddenInput)
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   116
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 495
diff changeset
   117
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   118
class View(base.View):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 495
diff changeset
   119
  """View methods for the User model.
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   120
  """
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   121
547
be0de865ffc9 Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents: 546
diff changeset
   122
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
   123
  def __init__(self, params=None):
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   124
    """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
   125
    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
   126
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   127
    Params:
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
   128
      params: a dict with params for this View
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   129
    """
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   130
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
   131
    new_params = {}
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
   132
    new_params['logic'] = soc.logic.models.user.logic
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   133
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
   134
    new_params['name'] = "User"
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   135
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
   136
    new_params['edit_form'] = EditForm
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
   137
    new_params['create_form'] = CreateForm
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   138
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
   139
    new_params['edit_template'] = 'soc/user/edit.html'
567
53906b0456b7 Add customized User Edit Developer view template with working listing of former accounts.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 561
diff changeset
   140
    
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
   141
    new_params['sidebar_heading'] = 'Users'
542
7cc99461b64d Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents: 531
diff changeset
   142
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
   143
    params = dicts.merge(params, new_params)
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   144
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 650
diff changeset
   145
    super(View, self).__init__(params=params)
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   146
543
280a1ac6bcc1 Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents: 542
diff changeset
   147
479
50bab5e71a66 Make sure the user edit form has the complete mail adress in the user account field when opened. Replace confusing id field in form with email field. Editing the email adress of an existing user will still result in an error but that should be fixed soon.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 473
diff changeset
   148
  def _editGet(self, request, entity, form):
50bab5e71a66 Make sure the user edit form has the complete mail adress in the user account field when opened. Replace confusing id field in form with email field. Editing the email adress of an existing user will still result in an error but that should be fixed soon.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 473
diff changeset
   149
    """See base.View._editGet().
50bab5e71a66 Make sure the user edit form has the complete mail adress in the user account field when opened. Replace confusing id field in form with email field. Editing the email adress of an existing user will still result in an error but that should be fixed soon.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 473
diff changeset
   150
    """
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   151
479
50bab5e71a66 Make sure the user edit form has the complete mail adress in the user account field when opened. Replace confusing id field in form with email field. Editing the email adress of an existing user will still result in an error but that should be fixed soon.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 473
diff changeset
   152
    # fill in the email field with the data from the entity
481
94834a1e6c01 Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents: 479
diff changeset
   153
    form.fields['email'].initial = entity.account.email()
856
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
   154
    form.fields['agrees_to_tos'].example_text = self._getToSExampleText()
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   155
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   156
    super(View, self)._editGet(request, entity, form)
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   157
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   158
  def _editPost(self, request, entity, fields):
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   159
    """See base.View._editPost().
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   160
    """
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   161
481
94834a1e6c01 Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents: 479
diff changeset
   162
    # fill in the account field with the user created from email
94834a1e6c01 Attempt to rename User.id to User.account, in preparation for making User be
Todd Larsen <tlarsen@google.com>
parents: 479
diff changeset
   163
    fields['account'] = users.User(fields['email'])
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   164
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   165
    super(View, self)._editPost(request, entity, fields)
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   166
856
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
   167
  def _getToSExampleText(self):
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
   168
    """Returns example_text linking to site-wide ToS, or a warning message.
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
   169
    """
891
3d40190f35b6 Move getToSLink() to soc.views.helper.redirects.getToSRedirect().
Todd Larsen <tlarsen@google.com>
parents: 858
diff changeset
   170
    tos_link = redirects.getToSRedirect(site_logic.getSingleton())
856
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
   171
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
   172
    if not tos_link:
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
   173
      return ('<div class="notice">&nbsp;<i>No site-wide</i> Terms of'
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
   174
              ' Service <i>are currently set!</i>&nbsp;</div>')
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
   175
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
   176
    return ('<i>current site-wide <b><a href=%s>Terms of Service</a></b></i>'
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
   177
            % tos_link)
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
   178
3d14b31e72e4 Set agrees_to_tos example text to link to site-wide ToS (or a warning message).
Todd Larsen <tlarsen@google.com>
parents: 813
diff changeset
   179
460
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   180
view = View()
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   181
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   182
create = view.create
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   183
delete = view.delete
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   184
edit = view.edit
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   185
list = view.list
3a508b1ebaac Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   186
public = view.public
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 856
diff changeset
   187
export = view.export
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 856
diff changeset
   188