author | Pawel Solyga <Pawel.Solyga@gmail.com> |
Sat, 24 Jan 2009 12:51:47 +0000 | |
changeset 958 | b4309e3cb899 |
parent 890 | b3bf833c4580 |
child 970 | 8b5611d5b053 |
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 |
|
590
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
587
diff
changeset
|
17 |
"""Views for the User's own 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 |
630
0ac985fd8efa
Add missing import, remove unused import and add missing parameters to methods in soc.views.models.user_self module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
612
diff
changeset
|
29 |
from django import http |
826
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
30 |
from django.utils.encoding import force_unicode |
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
31 |
from django.utils.safestring import mark_safe |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
32 |
from django.utils.translation import ugettext_lazy |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
33 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
34 |
from soc.logic import dicts |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
35 |
from soc.logic import validate |
826
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
36 |
from soc.logic import models as model_logic |
860
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
37 |
from soc.logic.models.site import logic as site_logic |
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
38 |
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
|
39 |
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
|
40 |
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
|
41 |
from soc.views.helper import access |
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
860
diff
changeset
|
42 |
from soc.views.helper import decorators |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
43 |
from soc.views.models import base |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
44 |
|
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
|
45 |
import soc.models.linkable |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
46 |
import soc.models.user |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
47 |
import soc.views.helper |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
48 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
49 |
|
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
50 |
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
|
51 |
"""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
|
52 |
""" |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
53 |
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
|
54 |
"""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
|
55 |
""" |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
56 |
#: 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
|
57 |
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
|
58 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
59 |
#: 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
|
60 |
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
|
61 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
62 |
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:
646
diff
changeset
|
63 |
link_id = self.cleaned_data.get('link_id').lower() |
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
64 |
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
|
65 |
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
|
66 |
|
860
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
67 |
user = user_logic.getForFields({'link_id': link_id}, unique=True) |
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
68 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
69 |
# 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
|
70 |
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
|
71 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
72 |
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
|
73 |
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
|
74 |
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
|
75 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
76 |
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
|
77 |
|
860
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
78 |
def clean_agrees_to_tos(self): |
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
79 |
agrees_to_tos = self.cleaned_data.get('agrees_to_tos') |
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
80 |
|
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
81 |
if not site_logic.getToS(site_logic.getSingleton()): |
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
82 |
return agrees_to_tos |
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
83 |
|
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
84 |
# Site settings specify a site-wide ToS, so agreement is *required* |
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
85 |
if agrees_to_tos: |
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
86 |
return True |
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
87 |
|
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
88 |
raise forms.ValidationError( |
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
89 |
'The site-wide Terms of Service must be accepted to participate' |
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
90 |
' on this site.') |
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
91 |
|
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
92 |
|
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
93 |
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
|
94 |
"""View methods for the User model. |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
95 |
""" |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
96 |
|
547
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
97 |
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
|
98 |
'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
|
99 |
' 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
|
100 |
'<ul>' |
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
101 |
' <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
|
102 |
' <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
|
103 |
' 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
|
104 |
' <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
|
105 |
'</ul>') |
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
106 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
107 |
def __init__(self, params=None): |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
108 |
"""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
|
109 |
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
|
110 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
111 |
Params: |
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
112 |
params: a dict with params for this View |
460
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 |
|
587
7504504209a3
Fixed some access related bugs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
586
diff
changeset
|
115 |
rights = {} |
590
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
587
diff
changeset
|
116 |
rights['unspecified'] = [access.deny] |
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
587
diff
changeset
|
117 |
rights['any_access'] = [access.allow] |
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
696
diff
changeset
|
118 |
rights['edit'] = [access.checkIsLoggedIn] |
890
b3bf833c4580
Tighten more checkIsUser() access to checkAgreesToSiteToS() instead.
Todd Larsen <tlarsen@google.com>
parents:
876
diff
changeset
|
119 |
rights['roles'] = [access.checkAgreesToSiteToS] |
590
37735d97b541
Created a seperate module for editSelf things
Sverre Rabbelier <srabbelier@gmail.com>
parents:
587
diff
changeset
|
120 |
rights['signIn'] = [access.checkNotLoggedIn] |
890
b3bf833c4580
Tighten more checkIsUser() access to checkAgreesToSiteToS() instead.
Todd Larsen <tlarsen@google.com>
parents:
876
diff
changeset
|
121 |
rights['notification'] = [access.checkAgreesToSiteToS] |
587
7504504209a3
Fixed some access related bugs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
586
diff
changeset
|
122 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
123 |
new_params = {} |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
124 |
new_params['rights'] = rights |
860
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
125 |
new_params['logic'] = user_logic |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
126 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
127 |
new_params['name'] = "User" |
799
30a912906a57
Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
787
diff
changeset
|
128 |
new_params['module_name'] = "user_self" |
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
129 |
new_params['url_name'] = "user" |
799
30a912906a57
Construct names automatically from base name.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
787
diff
changeset
|
130 |
|
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
860
diff
changeset
|
131 |
new_params['edit_template'] = 'soc/user/edit_self.html' |
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
860
diff
changeset
|
132 |
|
696
0d8515fb5314
Make use of the 'sidebar' param for user_self
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
133 |
new_params['sidebar_heading'] = 'User (self)' |
0d8515fb5314
Make use of the 'sidebar' param for user_self
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
134 |
new_params['sidebar'] = [ |
787 | 135 |
(users.create_login_url("/user/edit"), 'Sign In', 'signIn'), |
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
696
diff
changeset
|
136 |
('/' + new_params['url_name'] + '/edit', 'Profile', 'edit'), |
696
0d8515fb5314
Make use of the 'sidebar' param for user_self
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
137 |
('/' + new_params['url_name'] + '/roles', 'Roles', 'roles'), |
0d8515fb5314
Make use of the 'sidebar' param for user_self
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
138 |
] |
542
7cc99461b64d
Remove redundant dicts for URL patterns and sidebar menu text, and use the
Todd Larsen <tlarsen@google.com>
parents:
531
diff
changeset
|
139 |
|
660
5a381b290691
Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
140 |
patterns = [] |
5a381b290691
Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
141 |
|
5a381b290691
Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
142 |
page_name = "Profile" |
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
696
diff
changeset
|
143 |
patterns += [(r'^%(url_name)s/(?P<access_type>edit)$', |
660
5a381b290691
Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
144 |
'soc.views.models.%(module_name)s.edit', page_name)] |
5a381b290691
Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
145 |
|
5a381b290691
Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
146 |
page_name = "Requests Overview" |
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
696
diff
changeset
|
147 |
patterns += [(r'^%(url_name)s/(?P<access_type>roles)$', |
660
5a381b290691
Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
148 |
'soc.views.models.request.list_self', page_name)] |
726 | 149 |
|
660
5a381b290691
Introduced django_extra_patterns
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
150 |
new_params['django_patterns_defaults'] = patterns |
726 | 151 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
152 |
params = dicts.merge(params, new_params) |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
153 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
650
diff
changeset
|
154 |
super(View, self).__init__(params=params) |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
155 |
|
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
860
diff
changeset
|
156 |
@decorators.merge_params |
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
860
diff
changeset
|
157 |
@decorators.check_access |
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
696
diff
changeset
|
158 |
def edit(self, request, access_type, |
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
696
diff
changeset
|
159 |
page_name=None, params=None, seed=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
|
160 |
"""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
|
161 |
|
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
|
162 |
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
|
163 |
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
|
164 |
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
|
165 |
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
|
166 |
kwargs: The Key Fields for the specified entity |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
167 |
""" |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
168 |
|
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
169 |
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
|
170 |
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
|
171 |
|
860
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
172 |
user = user_logic.getForFields(properties, unique=True) |
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
173 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
174 |
# 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
|
175 |
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
|
176 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
177 |
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
|
178 |
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
|
179 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
properties = { |
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
183 |
'link_id': new_link_id, |
857
9767c1afe494
If a site-wide ToS exist, display the User profile "Agrees to ToS" checkbox.
Todd Larsen <tlarsen@google.com>
parents:
840
diff
changeset
|
184 |
'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
|
185 |
'account': account, |
857
9767c1afe494
If a site-wide ToS exist, display the User profile "Agrees to ToS" checkbox.
Todd Larsen <tlarsen@google.com>
parents:
840
diff
changeset
|
186 |
'agrees_to_tos': form.cleaned_data.get('agrees_to_tos'), |
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
187 |
} |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
188 |
|
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
189 |
# 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
|
190 |
# if it is show error message that account is invalid |
860
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
191 |
if 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
|
192 |
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
|
193 |
'email': account.email()} |
be0de865ffc9
Fixed former_accounts detection by supplying the missing error message.
Todd Larsen <tlarsen@google.com>
parents:
546
diff
changeset
|
194 |
error = out_of_band.Error(msg) |
646
860e17e5118f
Remove cyclic imports by moving response method of out_of_band.Error class to soc.views.helper.responses module as errorResponse function. Apply changes to affected files.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
630
diff
changeset
|
195 |
return helper.responses.errorResponse( |
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
860
diff
changeset
|
196 |
error, request, template=params['edit_template'], 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
|
197 |
|
860
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
198 |
user = user_logic.updateOrCreateFromFields( |
531
b74bf6bf1ccf
Make editSelf() work by adding 'inheritance_line' to the list of excluded
Todd Larsen <tlarsen@google.com>
parents:
529
diff
changeset
|
199 |
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
|
200 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
201 |
# 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
|
202 |
# (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
|
203 |
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
|
204 |
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
|
205 |
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
|
206 |
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
|
207 |
# 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
|
208 |
# (e.g. someone bookmarked the GET that followed the POST submit) |
611
2ec30182e5f1
Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
605
diff
changeset
|
209 |
if (request.GET.get(params['submit_msg_param_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
|
210 |
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
|
211 |
# 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
|
212 |
return http.HttpResponseRedirect(request.path) |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
213 |
|
515
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
214 |
# 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
|
215 |
# (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
|
216 |
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
|
217 |
helper.requests.getSingleIndexedParamValue( |
611
2ec30182e5f1
Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
605
diff
changeset
|
218 |
request, params['submit_msg_param_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
|
219 |
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
|
220 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
221 |
# 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
|
222 |
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
|
223 |
else: |
611
2ec30182e5f1
Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
605
diff
changeset
|
224 |
if request.GET.get(params['submit_msg_param_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
|
225 |
# 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
|
226 |
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
|
227 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
228 |
# 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
|
229 |
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
|
230 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
231 |
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
|
232 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
233 |
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
|
234 |
|
fa235f6759f3
Moved the last remnant of soc.views.user.profile to soc.views.models
Sverre Rabbelier <srabbelier@gmail.com>
parents:
514
diff
changeset
|
235 |
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
|
236 |
|
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
|
237 |
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
|
238 |
"""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
|
239 |
""" |
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
660
diff
changeset
|
240 |
|
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
|
241 |
# 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
|
242 |
form.fields['email'].initial = entity.account.email() |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
243 |
|
755
1ed041c0cdc6
Remove unused imports and variables in different soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
726
diff
changeset
|
244 |
super(View, self)._editGet(request, entity, form) |
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
660
diff
changeset
|
245 |
|
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
246 |
def _editPost(self, request, entity, fields): |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
247 |
"""See base.View._editPost(). |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
248 |
""" |
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
660
diff
changeset
|
249 |
|
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
|
250 |
# 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
|
251 |
fields['account'] = users.User(fields['email']) |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
252 |
|
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
660
diff
changeset
|
253 |
super(View, self)._editPost(request, entity, fields) |
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
660
diff
changeset
|
254 |
|
826
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
255 |
def getSidebarMenus(self, request, params=None): |
837
bc1c951bf3a0
Add missing blank line in soc.views.helper.params module. Fix docstring typo in soc.views.models.role module. Add missing dots at the end of sentences in soc.logic.cleaning and soc.view.models.user_self modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
826
diff
changeset
|
256 |
"""See base.View.getSidebarMenus(). |
826
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
257 |
""" |
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
258 |
|
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
259 |
link_title = ugettext_lazy('Notifications') |
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
260 |
|
860
cfb57fe35d3c
Add a clean_agrees_to_tos() validator that requires "Yes" if ToS exists.
Todd Larsen <tlarsen@google.com>
parents:
858
diff
changeset
|
261 |
user = user_logic.getForCurrentAccount() |
826
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
262 |
|
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
263 |
filter = { |
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
264 |
'scope': user, |
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
265 |
'unread': True, |
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
266 |
} |
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
267 |
|
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
268 |
notifications = model_logic.notification.logic.getForFields(filter) |
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
269 |
count = len(list(notifications)) |
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
270 |
|
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
271 |
if count > 0: |
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
272 |
link_title = '<b>%s (%d)</b>' % (force_unicode(link_title), count) |
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
273 |
link_title = mark_safe(link_title) |
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
274 |
|
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
275 |
items = [('/' + 'notification/list', link_title, 'notification')] |
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
276 |
|
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
277 |
new_params = {} |
840
d3f9fff0860b
When constructing the sidebar don't overide 'sidebar'
Sverre Rabbelier <srabbelier@gmail.com>
parents:
837
diff
changeset
|
278 |
new_params['sidebar_additional'] = items |
826
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
279 |
|
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
280 |
params = dicts.merge(params, new_params) |
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
281 |
|
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
282 |
return super(View, self).getSidebarMenus(request, params=params) |
c8dbcfd38c03
Add an unread count indication next to the notification link
Sverre Rabbelier <srabbelier@gmail.com>
parents:
825
diff
changeset
|
283 |
|
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
284 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
285 |
view = View() |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
286 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
287 |
edit = view.edit |
858
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
857
diff
changeset
|
288 |
export = view.export |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
857
diff
changeset
|
289 |