author | Sverre Rabbelier <srabbelier@gmail.com> |
Sun, 16 Nov 2008 22:11:58 +0000 | |
changeset 492 | 4abdeedfc08e |
parent 483 | 70f21691b0e1 |
child 493 | 6976c4d8d0ac |
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 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
25 |
from google.appengine.api import users |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
26 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
27 |
from django import forms |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
28 |
from django.utils.translation import ugettext_lazy |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
29 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
from soc.logic import dicts |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
31 |
from soc.logic import validate |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
32 |
from soc.logic.models import user as user_logic |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
33 |
from soc.views import helper |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
34 |
from soc.views.models import base |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
35 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
36 |
import soc.models.user |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
37 |
import soc.logic.models.user |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
38 |
import soc.views.helper |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
39 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
40 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
41 |
class CreateForm(helper.forms.BaseForm): |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
42 |
"""Django form displayed when creating a User. |
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 |
|
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
|
45 |
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
|
46 |
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
|
47 |
help_text=soc.models.user.User.account.help_text) |
460
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 |
link_name = forms.CharField( |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
50 |
label=soc.models.user.User.link_name.verbose_name, |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
51 |
help_text=soc.models.user.User.link_name.help_text) |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
52 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
53 |
nick_name = forms.CharField( |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
54 |
label=soc.models.user.User.nick_name.verbose_name) |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
55 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
56 |
is_developer = forms.BooleanField(required=False, |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
57 |
label=soc.models.user.User.is_developer.verbose_name, |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
58 |
help_text=soc.models.user.User.is_developer.help_text) |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
59 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
60 |
class Meta: |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
61 |
model = None |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
62 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
63 |
def clean_link_name(self): |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
64 |
link_name = self.cleaned_data.get('link_name') |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
65 |
if not validate.isLinkNameFormatValid(link_name): |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
66 |
raise forms.ValidationError("This link name is in wrong format.") |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
67 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
68 |
properties = {'link_name': link_name} |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
69 |
user = soc.logic.models.user.logic.getForFields(properties, unique=True) |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
70 |
|
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
|
71 |
link_name_user = soc.logic.models.user.logic.getForFields(properties, unique=True) |
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
|
72 |
|
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
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
|
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
|
77 |
if link_name_user and key_name_user and \ |
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 |
link_name_user.account != key_name_user.account: |
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 |
raise forms.ValidationError("This link name is already in use.") |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
80 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
81 |
return link_name |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
82 |
|
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
|
83 |
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
|
84 |
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
|
85 |
key_name = self.data.get('key_name') |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
86 |
if key_name: |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
87 |
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
|
88 |
old_email = user.account.email() |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
89 |
else: |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
90 |
old_email = None |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
91 |
|
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
|
92 |
new_email = form_account.email() |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
93 |
|
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
|
94 |
if new_email != old_email \ |
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
|
95 |
and user_logic.logic.getFromFields(email=new_email): |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
96 |
raise forms.ValidationError("This account is already in use.") |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
97 |
|
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
|
98 |
return self.cleaned_data.get('email') |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
99 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
100 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
101 |
class EditForm(CreateForm): |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
102 |
"""Django form displayed when editing a User. |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
103 |
""" |
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 |
key_name = forms.CharField(widget=forms.HiddenInput) |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
106 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
107 |
class View(base.View): |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
108 |
"""View methods for the User model |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
109 |
""" |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
110 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
111 |
def __init__(self, original_params=None, original_rights=None): |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
112 |
"""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
|
113 |
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
|
114 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
115 |
Params: |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
116 |
original_params: a dict with params for this View |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
117 |
original_rights: a dict with right definitions for this View |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
118 |
""" |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
119 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
120 |
self._logic = soc.logic.models.user.logic |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
121 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
122 |
params = {} |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
123 |
rights = {} |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
124 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
125 |
params['name'] = "User" |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
126 |
params['name_short'] = "User" |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
127 |
params['name_plural'] = "Users" |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
128 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
129 |
params['edit_form'] = EditForm |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
130 |
params['create_form'] = CreateForm |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
131 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
132 |
# TODO(tlarsen) Add support for Django style template lookup |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
133 |
params['edit_template'] = 'soc/models/edit.html' |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
134 |
params['public_template'] = 'soc/user/public.html' |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
135 |
params['list_template'] = 'soc/models/list.html' |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
136 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
137 |
params['lists_template'] = { |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
138 |
'list_main': 'soc/list/list_main.html', |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
139 |
'list_pagination': 'soc/list/list_pagination.html', |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
140 |
'list_row': 'soc/user/list/user_row.html', |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
141 |
'list_heading': 'soc/user/list/user_heading.html', |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
142 |
} |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
143 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
144 |
params['delete_redirect'] = '/user/list' |
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 |
params['save_message'] = [ugettext_lazy('Profile saved.')] |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
147 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
148 |
params['edit_params'] = { |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
149 |
self.DEF_SUBMIT_MSG_PARAM_NAME: self.DEF_SUBMIT_MSG_PROFILE_SAVED, |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
150 |
} |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
151 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
152 |
rights['list'] = [helper.access.checkIsDeveloper] |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
153 |
rights['delete'] = [helper.access.checkIsDeveloper] |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
154 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
155 |
params = dicts.merge(original_params, params) |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
156 |
rights = dicts.merge(original_rights, rights) |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
157 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
158 |
base.View.__init__(self, rights=rights, params=params) |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
159 |
|
482
839740b061ad
Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
160 |
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
|
161 |
"""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
|
162 |
|
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 |
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
|
164 |
request: the standard Django HTTP request object |
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 |
page: a soc.logic.site.page.Page object which is abstraction |
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 |
that combines a Django view with sidebar menu info |
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
|
167 |
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
|
168 |
kwargs: The Key Fields for the specified entity |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
169 |
""" |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
170 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
171 |
params = dicts.merge(params, {'edit_template': 'soc/user/edit_self.html'}) |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
172 |
|
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
|
173 |
properties = {'account': users.get_current_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 |
entity = self._logic.getForFields(properties, unique=True) |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
176 |
keys = self._logic.getKeyFieldNames() |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
177 |
values = self._logic.getKeyValues(entity) |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
178 |
key_fields = dicts.zip(keys, values) |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
179 |
|
482
839740b061ad
Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents:
481
diff
changeset
|
180 |
return self.edit(request, page_name, params=params, **key_fields) |
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
|
181 |
|
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
|
182 |
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
|
183 |
"""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
|
184 |
""" |
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
|
185 |
# 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
|
186 |
form.fields['email'].initial = entity.account.email() |
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
|
187 |
|
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
188 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
189 |
def _editPost(self, request, entity, fields): |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
190 |
"""See base.View._editPost(). |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
191 |
""" |
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
|
192 |
# 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
|
193 |
fields['account'] = users.User(fields['email']) |
460
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
194 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
195 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
196 |
view = View() |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
197 |
|
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
198 |
create = view.create |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
199 |
delete = view.delete |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
200 |
edit = view.edit |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
201 |
list = view.list |
3a508b1ebaac
Added a generic user page
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
202 |
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
|
203 |
edit_self = view.editSelf |