author | Todd Larsen <tlarsen@google.com> |
Sun, 23 Nov 2008 07:38:00 +0000 | |
changeset 580 | 9fefe7895f38 |
parent 569 | 96d9655a7538 |
child 586 | a4a36b06a870 |
permissions | -rw-r--r-- |
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>', |
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 |
from django.utils.translation import ugettext_lazy |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
31 |
from soc.logic import dicts |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
32 |
from soc.logic import validate |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
33 |
from soc.logic.models import user as user_logic |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
34 |
from soc.views import helper |
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
|
35 |
from soc.views import out_of_band |
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
36 |
from soc.views.helper import access |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
37 |
from soc.views.models import base |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
38 |
|
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
|
39 |
import soc.models.linkable |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
40 |
import soc.models.user |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
41 |
import soc.logic.models.user |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
42 |
import soc.views.helper |
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 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
45 |
class CreateForm(helper.forms.BaseForm): |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
46 |
"""Django form displayed when creating a User. |
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 |
|
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
|
49 |
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
|
50 |
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
|
51 |
help_text=soc.models.user.User.account.help_text) |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
52 |
|
512
aae25d2b4464
Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents:
507
diff
changeset
|
53 |
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
|
54 |
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
|
55 |
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
|
56 |
|
546
850d9a5ad894
Rename the User.public_name Property to simply 'name' (but leave the verbose
Todd Larsen <tlarsen@google.com>
parents:
543
diff
changeset
|
57 |
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
|
58 |
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
|
59 |
help_text=soc.models.user.User.name.help_text) |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
60 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
61 |
is_developer = forms.BooleanField(required=False, |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
62 |
label=soc.models.user.User.is_developer.verbose_name, |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
63 |
help_text=soc.models.user.User.is_developer.help_text) |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
64 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
65 |
class Meta: |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
66 |
model = None |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
67 |
|
512
aae25d2b4464
Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents:
507
diff
changeset
|
68 |
def clean_link_id(self): |
aae25d2b4464
Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents:
507
diff
changeset
|
69 |
link_id = self.cleaned_data.get('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
|
70 |
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
|
71 |
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
|
72 |
|
512
aae25d2b4464
Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents:
507
diff
changeset
|
73 |
properties = {'link_id': link_id} |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
74 |
user = soc.logic.models.user.logic.getForFields(properties, unique=True) |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
75 |
|
531
b74bf6bf1ccf
Make editSelf() work by adding 'inheritance_line' to the list of excluded
Todd Larsen <tlarsen@google.com>
parents:
529
diff
changeset
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
if 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
|
80 |
key_name_user = user_logic.logic.getFromKeyName(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
|
81 |
|
531
b74bf6bf1ccf
Make editSelf() work by adding 'inheritance_line' to the list of excluded
Todd Larsen <tlarsen@google.com>
parents:
529
diff
changeset
|
82 |
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
|
83 |
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
|
84 |
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
|
85 |
|
512
aae25d2b4464
Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents:
507
diff
changeset
|
86 |
return link_id |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
87 |
|
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
|
88 |
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
|
89 |
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
|
90 |
key_name = self.data.get('key_name') |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
91 |
if key_name: |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
92 |
user = user_logic.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
|
93 |
old_email = user.account.email() |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
94 |
else: |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
95 |
old_email = None |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
96 |
|
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
|
97 |
new_email = form_account.email() |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
98 |
|
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
|
99 |
if new_email != old_email \ |
494
5e9c656a1b68
Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
493
diff
changeset
|
100 |
and user_logic.logic.getForFields({'email': new_email}, unique=True): |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
101 |
raise forms.ValidationError("This account is already in use.") |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
102 |
|
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
|
103 |
return self.cleaned_data.get('email') |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
104 |
|
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 |
class EditForm(CreateForm): |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
107 |
"""Django form displayed when editing a User. |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
108 |
""" |
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 |
key_name = forms.CharField(widget=forms.HiddenInput) |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
111 |
|
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
495
diff
changeset
|
112 |
|
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
113 |
class UserForm(helper.forms.BaseForm): |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
114 |
"""Django form displayed when creating or editing a User. |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
115 |
""" |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
116 |
class Meta: |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
117 |
"""Inner Meta class that defines some behavior for the form. |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
118 |
""" |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
119 |
#: db.Model subclass for which the form will gather information |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
120 |
model = soc.models.user.User |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
121 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
122 |
#: list of model fields which will *not* be gathered by the form |
569
96d9655a7538
Remove inheritance_line from Form meta class excludes in all currently used forms.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
567
diff
changeset
|
123 |
exclude = ['account', 'former_accounts', 'is_developer'] |
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
124 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
125 |
def clean_link_id(self): |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
126 |
link_id = self.cleaned_data.get('link_id') |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
127 |
if not validate.isLinkIdFormatValid(link_id): |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
128 |
raise forms.ValidationError("This link ID is in wrong format.") |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
129 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
130 |
user = soc.logic.models.user.logic.getForFields({'link_id': link_id}, |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
131 |
unique=True) |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
132 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
133 |
# Get the currently logged in user account |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
134 |
current_account = users.get_current_user() |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
135 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
136 |
if user: |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
137 |
if current_account != user.account: |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
138 |
raise forms.ValidationError("This link ID is already in use.") |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
139 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
140 |
return link_id |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
141 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
142 |
|
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
143 |
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
|
144 |
"""View methods for the User model. |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
145 |
""" |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
146 |
|
547
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
147 |
DEF_USER_ACCOUNT_INVALID_MSG_FMT = ugettext_lazy( |
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
148 |
'The <b><i>%(email)s</i></b> account cannot be used with this site, for' |
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
149 |
' one or more of the following reasons:' |
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
150 |
'<ul>' |
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
151 |
' <li>the account is invalid</li>' |
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
152 |
' <li>the account is already attached to a User profile and cannot be' |
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
153 |
' used to create another one</li>' |
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
154 |
' <li>the account is a former account that cannot be used again</li>' |
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
155 |
'</ul>') |
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
156 |
|
507
3603fdafabf7
Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents:
502
diff
changeset
|
157 |
def __init__(self, original_params=None): |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
158 |
"""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
|
159 |
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
|
160 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
161 |
Params: |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
162 |
original_params: a dict with params for this View |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
163 |
""" |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
164 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
165 |
self._logic = soc.logic.models.user.logic |
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 |
params = {} |
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 |
params['name'] = "User" |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
170 |
params['name_short'] = "User" |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
171 |
params['name_plural'] = "Users" |
502
e1e24c0a4e82
Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
500
diff
changeset
|
172 |
params['url_name'] = "user" |
e1e24c0a4e82
Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
500
diff
changeset
|
173 |
params['module_name'] = "user" |
460
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 |
params['edit_form'] = EditForm |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
176 |
params['create_form'] = CreateForm |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
177 |
|
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
|
178 |
params['edit_template'] = 'soc/user/edit.html' |
53906b0456b7
Add customized User Edit Developer view template with working listing of former accounts.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
561
diff
changeset
|
179 |
|
542
7cc99461b64d
Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents:
531
diff
changeset
|
180 |
params['sidebar_heading'] = 'Users' |
7cc99461b64d
Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents:
531
diff
changeset
|
181 |
|
507
3603fdafabf7
Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents:
502
diff
changeset
|
182 |
params = dicts.merge(original_params, params) |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
183 |
|
507
3603fdafabf7
Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents:
502
diff
changeset
|
184 |
base.View.__init__(self, params=params) |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
185 |
|
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
|
186 |
EDIT_SELF_TMPL = 'soc/user/edit_self.html' |
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
|
187 |
|
482
839740b061ad
Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
188 |
def editSelf(self, request, page_name=None, params=None, **kwargs): |
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
|
189 |
"""Displays User self edit page for the entity specified by **kwargs. |
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
|
190 |
|
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
|
191 |
Args: |
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
|
192 |
request: the standard Django HTTP request object |
500
44ea4620c5c0
Replace old page parameter doc string description with new one for page_name.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
499
diff
changeset
|
193 |
page_name: the page name displayed in templates as page and header title |
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
|
194 |
params: a dict with params for this View |
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
|
195 |
kwargs: The Key Fields for the specified entity |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
196 |
""" |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
197 |
|
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
198 |
rights = {} |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
199 |
rights['any_access'] = [access.checkIsLoggedIn] |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
200 |
rights['unspecified'] = [access.deny] |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
201 |
rights['editSelf'] = [access.allow] |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
202 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
203 |
try: |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
204 |
self.checkAccess('editSelf', request, rights=rights) |
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
|
205 |
except out_of_band.Error, error: |
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
|
206 |
return error.response(request, template=self.EDIT_SELF_TMPL) |
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
207 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
208 |
new_params = {} |
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
|
209 |
new_params['edit_template'] = self.EDIT_SELF_TMPL |
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
210 |
new_params['rights'] = rights |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
211 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
212 |
params = dicts.merge(params, new_params) |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
213 |
params = dicts.merge(params, self._params) |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
214 |
|
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
215 |
account = users.get_current_user() |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
216 |
properties = {'account': account} |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
217 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
218 |
user = soc.logic.models.user.logic.getForFields(properties, unique=True) |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
219 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
220 |
# create default template context for use with any templates |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
221 |
context = helper.responses.getUniversalContext(request) |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
222 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
223 |
if request.method == 'POST': |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
224 |
form = UserForm(request.POST) |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
225 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
226 |
if form.is_valid(): |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
227 |
new_link_id = form.cleaned_data.get('link_id') |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
228 |
properties = { |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
229 |
'link_id': new_link_id, |
546
850d9a5ad894
Rename the User.public_name Property to simply 'name' (but leave the verbose
Todd Larsen <tlarsen@google.com>
parents:
543
diff
changeset
|
230 |
'name': form.cleaned_data.get("name"), |
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
231 |
'account': account, |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
232 |
} |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
233 |
|
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
234 |
# check if user account is not in former_accounts |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
235 |
# if it is show error message that account is invalid |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
236 |
if soc.logic.models.user.logic.isFormerAccount(account): |
547
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
237 |
msg = self.DEF_USER_ACCOUNT_INVALID_MSG_FMT % { |
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
238 |
'email': account.email()} |
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
239 |
error = out_of_band.Error(msg) |
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
240 |
return error.response(request, template=self.EDIT_SELF_TMPL, |
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
241 |
context=context) |
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
242 |
|
531
b74bf6bf1ccf
Make editSelf() work by adding 'inheritance_line' to the list of excluded
Todd Larsen <tlarsen@google.com>
parents:
529
diff
changeset
|
243 |
user = soc.logic.models.user.logic.updateOrCreateFromFields( |
b74bf6bf1ccf
Make editSelf() work by adding 'inheritance_line' to the list of excluded
Todd Larsen <tlarsen@google.com>
parents:
529
diff
changeset
|
244 |
properties, {'link_id': new_link_id}) |
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
245 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
246 |
# redirect to /user/profile?s=0 |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
247 |
# (causes 'Profile saved' message to be displayed) |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
248 |
return helper.responses.redirectToChangedSuffix( |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
249 |
request, None, params=params['edit_params']) |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
250 |
else: # request.method == 'GET' |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
251 |
if user: |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
252 |
# is 'Profile saved' parameter present, but referrer was not ourself? |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
253 |
# (e.g. someone bookmarked the GET that followed the POST submit) |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
254 |
if (request.GET.get(self.DEF_SUBMIT_MSG_PARAM_NAME) |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
255 |
and (not helper.requests.isReferrerSelf(request))): |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
256 |
# redirect to aggressively remove 'Profile saved' query parameter |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
257 |
return http.HttpResponseRedirect(request.path) |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
258 |
|
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
259 |
# referrer was us, so select which submit message to display |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
260 |
# (may display no message if ?s=0 parameter is not present) |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
261 |
context['notice'] = ( |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
262 |
helper.requests.getSingleIndexedParamValue( |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
263 |
request, self.DEF_SUBMIT_MSG_PARAM_NAME, |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
264 |
values=params['save_message'])) |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
265 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
266 |
# populate form with the existing User entity |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
267 |
form = UserForm(instance=user) |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
268 |
else: |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
269 |
if request.GET.get(self.DEF_SUBMIT_MSG_PARAM_NAME): |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
270 |
# redirect to aggressively remove 'Profile saved' query parameter |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
271 |
return http.HttpResponseRedirect(request.path) |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
272 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
273 |
# no User entity exists for this Google Account, so show a blank form |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
274 |
form = UserForm() |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
275 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
276 |
context['form'] = form |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
277 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
278 |
template = params['edit_template'] |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
279 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
280 |
return helper.responses.respond(request, template, context) |
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
|
281 |
|
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
|
282 |
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
|
283 |
"""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
|
284 |
""" |
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
|
285 |
# 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
|
286 |
form.fields['email'].initial = entity.account.email() |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
287 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
288 |
def _editPost(self, request, entity, fields): |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
289 |
"""See base.View._editPost(). |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
290 |
""" |
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
|
291 |
# 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
|
292 |
fields['account'] = users.User(fields['email']) |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
293 |
|
493
6976c4d8d0ac
Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents:
492
diff
changeset
|
294 |
def getUserSidebar(self): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
495
diff
changeset
|
295 |
"""Returns an dictionary with the user sidebar entry. |
493
6976c4d8d0ac
Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents:
492
diff
changeset
|
296 |
""" |
6976c4d8d0ac
Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents:
492
diff
changeset
|
297 |
|
6976c4d8d0ac
Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents:
492
diff
changeset
|
298 |
params = {} |
542
7cc99461b64d
Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents:
531
diff
changeset
|
299 |
params['sidebar_heading'] = "User (self)" |
493
6976c4d8d0ac
Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents:
492
diff
changeset
|
300 |
params['sidebar'] = [ |
502
e1e24c0a4e82
Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
500
diff
changeset
|
301 |
('/' + self._params['url_name'] + '/edit', 'Profile'), |
e1e24c0a4e82
Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
500
diff
changeset
|
302 |
('/' + self._params['url_name'] + '/roles', 'Roles'), |
493
6976c4d8d0ac
Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents:
492
diff
changeset
|
303 |
] |
6976c4d8d0ac
Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents:
492
diff
changeset
|
304 |
return self.getSidebarLinks(params) |
6976c4d8d0ac
Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents:
492
diff
changeset
|
305 |
|
494
5e9c656a1b68
Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
493
diff
changeset
|
306 |
def getDjangoURLPatterns(self): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
495
diff
changeset
|
307 |
"""See base.View.getDjangoURLPatterns(). |
494
5e9c656a1b68
Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
493
diff
changeset
|
308 |
""" |
5e9c656a1b68
Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
493
diff
changeset
|
309 |
|
5e9c656a1b68
Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
493
diff
changeset
|
310 |
patterns = super(View, self).getDjangoURLPatterns() |
528
5e6ae12cc495
Some indention and too long lines fixes in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
521
diff
changeset
|
311 |
patterns += [(r'^' + self._params['url_name'] + '/edit$', |
5e6ae12cc495
Some indention and too long lines fixes in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
521
diff
changeset
|
312 |
'soc.views.models.user.edit_self')] |
521
07b2c382a4d6
Minor improvements to roles page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
519
diff
changeset
|
313 |
|
561
4db464032b25
Added a requests overview using the new multi-list page.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
554
diff
changeset
|
314 |
page_name = "Requests Overview" |
521
07b2c382a4d6
Minor improvements to roles page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
519
diff
changeset
|
315 |
patterns += [(r'^' + self._params['url_name'] + '/roles$', |
528
5e6ae12cc495
Some indention and too long lines fixes in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
521
diff
changeset
|
316 |
'soc.views.models.request.list_self', |
5e6ae12cc495
Some indention and too long lines fixes in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
521
diff
changeset
|
317 |
{'page_name': page_name}, page_name)] |
521
07b2c382a4d6
Minor improvements to roles page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
519
diff
changeset
|
318 |
|
494
5e9c656a1b68
Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
493
diff
changeset
|
319 |
return patterns |
5e9c656a1b68
Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
493
diff
changeset
|
320 |
|
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
321 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
322 |
view = View() |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
323 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
324 |
create = view.create |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
325 |
delete = view.delete |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
326 |
edit = view.edit |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
327 |
list = view.list |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
328 |
public = view.public |
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
|
329 |
edit_self = view.editSelf |