author | Todd Larsen <tlarsen@google.com> |
Tue, 20 Jan 2009 22:30:21 +0000 | |
changeset 854 | bb43b74c58f6 |
parent 844 | b55c68d25b35 |
child 858 | e79e7a22326f |
permissions | -rw-r--r-- |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
2 |
# |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
4 |
# |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
8 |
# |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
10 |
# |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
16 |
|
534
c31cfbf1a20f
Replace HomeSettings with Presence Model class. Replace SiteSettings with
Todd Larsen <tlarsen@google.com>
parents:
514
diff
changeset
|
17 |
"""Views for Models with a "presence" on a Melange site. |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
18 |
""" |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
19 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
21 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
22 |
] |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
23 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
24 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
25 |
from google.appengine.ext import db |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
26 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
27 |
from django import forms |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
28 |
from django.utils.translation import ugettext_lazy |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
29 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
from soc.logic import dicts |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
31 |
from soc.logic import validate |
452
160c748988a2
Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
32 |
from soc.logic.models import document as document_logic |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
33 |
from soc.views import helper |
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
34 |
from soc.views.helper import access |
844
b55c68d25b35
Make getToSLink() an actual method for re-use by others.
Todd Larsen <tlarsen@google.com>
parents:
807
diff
changeset
|
35 |
from soc.views.helper import redirects |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
36 |
from soc.views.models import base |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
37 |
|
534
c31cfbf1a20f
Replace HomeSettings with Presence Model class. Replace SiteSettings with
Todd Larsen <tlarsen@google.com>
parents:
514
diff
changeset
|
38 |
import soc.models.presence |
c31cfbf1a20f
Replace HomeSettings with Presence Model class. Replace SiteSettings with
Todd Larsen <tlarsen@google.com>
parents:
514
diff
changeset
|
39 |
import soc.logic.models.presence |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
40 |
import soc.logic.dicts |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
41 |
import soc.views.helper |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
42 |
import soc.views.helper.widgets |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
43 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
44 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
45 |
class SettingsValidationForm(helper.forms.BaseForm): |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
46 |
"""Django form displayed when creating or editing Settings. |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
47 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
48 |
This form includes validation functions for Settings fields. |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
49 |
""" |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
50 |
|
807
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
51 |
# TODO(tlarsen): scope_path will be a hard-coded read-only |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
52 |
# field for some (most?) User Roles |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
53 |
home_scope_path = forms.CharField(required=False, |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
54 |
label=ugettext_lazy('home page Document scope path'), |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
55 |
help_text=soc.models.work.Work.scope_path.help_text) |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
56 |
|
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
57 |
# TODO(tlarsen): actually, using these two text fields to specify |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
58 |
# the Document is pretty cheesy; this needs to be some much better |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
59 |
# Role-scoped Document selector that we don't have yet. See: |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
60 |
# http://code.google.com/p/soc/issues/detail?id=151 |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
61 |
home_link_id = forms.CharField(required=False, |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
62 |
label=ugettext_lazy('home page Document link ID'), |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
63 |
help_text=soc.models.work.Work.link_id.help_text) |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
64 |
|
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
65 |
# TODO(tlarsen): scope_path will be a hard-coded read-only |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
66 |
# field for some (most?) User Roles |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
67 |
tos_scope_path = forms.CharField(required=False, |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
68 |
label=ugettext_lazy('Terms of Service Document scope path'), |
513
3c1e16637ad7
Rename partial_path to scope_path, ignoring case, etc.
Todd Larsen <tlarsen@google.com>
parents:
512
diff
changeset
|
69 |
help_text=soc.models.work.Work.scope_path.help_text) |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
70 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
71 |
# TODO(tlarsen): actually, using these two text fields to specify |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
72 |
# the Document is pretty cheesy; this needs to be some much better |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
73 |
# Role-scoped Document selector that we don't have yet |
807
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
74 |
# See: |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
75 |
# http://code.google.com/p/soc/issues/detail?id=151 |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
76 |
tos_link_id = forms.CharField(required=False, |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
77 |
label=ugettext_lazy('Terms of Service Document link ID'), |
512
aae25d2b4464
Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents:
507
diff
changeset
|
78 |
help_text=soc.models.work.Work.link_id.help_text) |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
79 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
80 |
def clean_feed_url(self): |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
81 |
feed_url = self.cleaned_data.get('feed_url') |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
82 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
83 |
if feed_url == '': |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
84 |
# feed url not supplied (which is OK), so do not try to validate it |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
85 |
return None |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
86 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
87 |
if not validate.isFeedURLValid(feed_url): |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
88 |
raise forms.ValidationError('This URL is not a valid ATOM or RSS feed.') |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
89 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
90 |
return feed_url |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
91 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
92 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
93 |
class CreateForm(SettingsValidationForm): |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
94 |
"""Django form displayed when creating or editing Settings. |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
95 |
""" |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
96 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
97 |
class Meta: |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
98 |
"""Inner Meta class that defines some behavior for the form. |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
99 |
""" |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
100 |
#: db.Model subclass for which the form will gather information |
534
c31cfbf1a20f
Replace HomeSettings with Presence Model class. Replace SiteSettings with
Todd Larsen <tlarsen@google.com>
parents:
514
diff
changeset
|
101 |
model = soc.models.presence.Presence |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
102 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
103 |
#: list of model fields which will *not* be gathered by the form |
807
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
104 |
exclude = ['scope', |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
105 |
# TODO(tlarsen): this needs to be enabled once a button to a list |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
106 |
# selection "interstitial" page is implemented, see: |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
107 |
# http://code.google.com/p/soc/issues/detail?id=151 |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
108 |
'home', 'tos'] |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
109 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
110 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
111 |
class EditForm(CreateForm): |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
112 |
"""Django form displayed a Document is edited. |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
113 |
""" |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
114 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
115 |
pass |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
116 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
117 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
118 |
class View(base.View): |
844
b55c68d25b35
Make getToSLink() an actual method for re-use by others.
Todd Larsen <tlarsen@google.com>
parents:
807
diff
changeset
|
119 |
"""View methods for the Presence model. |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
120 |
""" |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
121 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
632
diff
changeset
|
122 |
def __init__(self, params=None): |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
123 |
"""Defines the fields and methods required for the base View class |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
124 |
to provide the user with list, public, create, edit and delete views. |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
125 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
126 |
Params: |
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
632
diff
changeset
|
127 |
params: a dict with params for this View |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
128 |
""" |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
129 |
|
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
130 |
rights = {} |
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
131 |
rights['any_access'] = [access.allow] |
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
132 |
rights['show'] = [access.allow] |
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
133 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
632
diff
changeset
|
134 |
new_params = {} |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
632
diff
changeset
|
135 |
new_params['logic'] = soc.logic.models.presence.logic |
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
136 |
new_params['rights'] = rights |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
137 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
632
diff
changeset
|
138 |
new_params['name'] = "Home Settings" |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
632
diff
changeset
|
139 |
new_params['url_name'] = "home/settings" |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
632
diff
changeset
|
140 |
new_params['module_name'] = "presence" |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
141 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
632
diff
changeset
|
142 |
new_params['edit_form'] = EditForm |
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
632
diff
changeset
|
143 |
new_params['create_form'] = CreateForm |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
144 |
|
586
a4a36b06a870
Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents:
569
diff
changeset
|
145 |
# Disable the presence sidebar until we have some use for it |
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
632
diff
changeset
|
146 |
new_params['sidebar_defaults'] = [] |
586
a4a36b06a870
Make the sidebar dynamic depending on the user's rights
Sverre Rabbelier <srabbelier@gmail.com>
parents:
569
diff
changeset
|
147 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
632
diff
changeset
|
148 |
params = dicts.merge(params, new_params) |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
149 |
|
656
a76f1b443ea4
Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
632
diff
changeset
|
150 |
super(View, self).__init__(params=params) |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
151 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
152 |
def _public(self, request, entity, context): |
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
153 |
"""See base.View._public(). |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
154 |
""" |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
155 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
156 |
if not entity: |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
157 |
return |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
158 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
159 |
try: |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
160 |
home_doc = entity.home |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
161 |
except db.Error: |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
162 |
home_doc = None |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
163 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
164 |
if home_doc: |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
165 |
home_doc.content = helper.templates.unescape(home_doc.content) |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
166 |
context['home_document'] = home_doc |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
167 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
168 |
def _editGet(self, request, entity, form): |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
169 |
"""See base.View._editGet(). |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
170 |
""" |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
171 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
172 |
try: |
452
160c748988a2
Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
173 |
if entity.home: |
807
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
174 |
form.fields['home_scope_path'].initial = entity.home.scope_path |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
175 |
form.fields['home_link_id'].initial = entity.home.link_id |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
176 |
|
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
177 |
if entity.tos: |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
178 |
form.fields['tos_scope_path'].initial = entity.tos.scope_path |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
179 |
form.fields['tos_link_id'].initial = entity.tos.link_id |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
180 |
except db.Error: |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
181 |
pass |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
182 |
|
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
183 |
super(View, self)._editGet(request, entity, form) |
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
184 |
|
452
160c748988a2
Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
185 |
def _editPost(self, request, entity, fields): |
160c748988a2
Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
186 |
"""See base.View._editPost(). |
160c748988a2
Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
187 |
""" |
160c748988a2
Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
188 |
|
807
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
189 |
home_scope_path = fields['home_scope_path'] |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
190 |
home_link_id = fields['home_link_id'] |
452
160c748988a2
Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
191 |
|
160c748988a2
Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
192 |
# TODO notify the user if home_doc is not found |
160c748988a2
Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
193 |
home_doc = document_logic.logic.getFromFields( |
807
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
194 |
scope_path=home_scope_path, link_id=home_link_id) |
452
160c748988a2
Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
195 |
|
160c748988a2
Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
196 |
fields['home'] = home_doc |
160c748988a2
Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
197 |
|
807
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
198 |
tos_scope_path = fields['tos_scope_path'] |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
199 |
tos_link_id = fields['tos_link_id'] |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
200 |
|
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
201 |
# TODO notify the user if tos_doc is not found |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
202 |
tos_doc = document_logic.logic.getFromFields( |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
203 |
scope_path=tos_scope_path, link_id=tos_link_id) |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
204 |
|
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
205 |
fields['tos'] = tos_doc |
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
206 |
|
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
656
diff
changeset
|
207 |
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:
656
diff
changeset
|
208 |
|
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
209 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
210 |
view = View() |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
211 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
212 |
create = view.create |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
213 |
edit = view.edit |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
214 |
delete = view.delete |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
215 |
list = view.list |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
216 |
public = view.public |
807
b6db9fb1246d
Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents:
799
diff
changeset
|
217 |