author | Sverre Rabbelier <srabbelier@gmail.com> |
Sat, 14 Feb 2009 20:22:17 +0000 | |
changeset 1323 | a666374587df |
parent 1308 | 35b75ffcbb37 |
child 1326 | 237d0974654e |
permissions | -rw-r--r-- |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
2 |
# |
1308
35b75ffcbb37
Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1307
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
4 |
# |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
8 |
# |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
10 |
# |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
16 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
17 |
"""Helpers functions for displaying views. |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
18 |
""" |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
19 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
429
e50e18936f06
Fixed typo in e-mail address
Sverre Rabbelier <srabbelier@gmail.com>
parents:
428
diff
changeset
|
21 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
516
ec1dcd70b97e
The list method in models/base.py can now use a filter to make a selection of entities to show.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
514
diff
changeset
|
22 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
471
dcb1f7821b39
Remove stop parameter from home_settings and site_settings views. This is something Sverre didn't mean to commit :-) Add missing params description to the models Base class docs.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
459
diff
changeset
|
23 |
'"Pawel Solyga" <pawel.solyga@gmail.com>', |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
24 |
] |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
25 |
|
1268
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
26 |
from google.appengine.ext import db |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
27 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
28 |
from django import http |
1098
e5c06755ecd8
Use django.utils.simplejson in soc.views.models.base pick method instead of our standalone simplejson module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
1035
diff
changeset
|
29 |
from django.utils import simplejson |
970
8b5611d5b053
Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents:
957
diff
changeset
|
30 |
from django.utils.translation import ugettext |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
31 |
|
387
c55195361cb6
Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents:
373
diff
changeset
|
32 |
from soc.logic import dicts |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
33 |
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
|
34 |
from soc.views import out_of_band |
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
35 |
from soc.views.helper import decorators |
612
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
611
diff
changeset
|
36 |
from soc.views.helper import forms |
858
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
37 |
from soc.views.helper import redirects |
613
4880ffa9f3ba
Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
38 |
from soc.views import sitemap |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
39 |
|
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:
639
diff
changeset
|
40 |
import soc.logic |
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:
639
diff
changeset
|
41 |
import soc.logic.lists |
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:
639
diff
changeset
|
42 |
import soc.views.helper.lists |
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:
639
diff
changeset
|
43 |
import soc.views.helper.responses |
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:
639
diff
changeset
|
44 |
import soc.views.helper.params |
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:
639
diff
changeset
|
45 |
|
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
46 |
|
493
6976c4d8d0ac
Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents:
492
diff
changeset
|
47 |
class View(object): |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
48 |
"""Views for entity classes. |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
49 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
50 |
The View class functions specific to Entity classes by relying |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
51 |
on the the child-classes to define the following fields: |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
52 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
53 |
self._logic: the logic singleton for this entity |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
54 |
""" |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
55 |
|
970
8b5611d5b053
Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents:
957
diff
changeset
|
56 |
DEF_CREATE_NEW_ENTITY_MSG_FMT = ugettext( |
502
e1e24c0a4e82
Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
500
diff
changeset
|
57 |
' You can create a new %(entity_type)s by visiting' |
387
c55195361cb6
Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents:
373
diff
changeset
|
58 |
' <a href="%(create)s">Create ' |
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
59 |
'a New %(entity_type)s</a> page.') |
387
c55195361cb6
Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents:
373
diff
changeset
|
60 |
|
970
8b5611d5b053
Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents:
957
diff
changeset
|
61 |
DEF_CREATE_INSTRUCTION_MSG_FMT = ugettext( |
663
c2dcae606699
Make base.View.create lookup the scope if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
62 |
'Please select a %s for the new %s.') |
c2dcae606699
Make base.View.create lookup the scope if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
63 |
|
507
3603fdafabf7
Fold the _rights dictionary into params
Sverre Rabbelier <srabbelier@gmail.com>
parents:
502
diff
changeset
|
64 |
def __init__(self, params=None): |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
65 |
""" |
373
dcd7013ae0d5
Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents:
363
diff
changeset
|
66 |
|
dcd7013ae0d5
Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents:
363
diff
changeset
|
67 |
Args: |
dcd7013ae0d5
Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents:
363
diff
changeset
|
68 |
params: This dictionary should be filled with the parameters |
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
69 |
specific to this entity. See the methods in this class on |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
70 |
the fields it should contain, and how they are used. |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
71 |
""" |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
72 |
|
611
2ec30182e5f1
Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
610
diff
changeset
|
73 |
self._params = helper.params.constructParams(params) |
2ec30182e5f1
Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
610
diff
changeset
|
74 |
self._logic = params['logic'] |
554
68c7a1dd3c52
Renamed templates/soc/entity/list/entity_*.html to *.html
Sverre Rabbelier <srabbelier@gmail.com>
parents:
553
diff
changeset
|
75 |
|
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
76 |
@decorators.merge_params |
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
77 |
@decorators.check_access |
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
708
diff
changeset
|
78 |
def public(self, request, access_type, |
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
708
diff
changeset
|
79 |
page_name=None, params=None, **kwargs): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
497
diff
changeset
|
80 |
"""Displays the public page for the entity specified by **kwargs. |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
81 |
|
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
82 |
Params usage: |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
83 |
rights: The rights dictionary is used to check if the user has |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
84 |
the required rights to view the public page for this entity. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
85 |
See checkAccess for more details on how the rights dictionary |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
86 |
is used to check access rights. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
87 |
error_public: The error_public value is used as template when |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
88 |
the key values (as defined by the page's url) do not |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
89 |
correspond to an existing entity. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
90 |
name: The name value is used to set the entity_type in the |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
91 |
context so that the template can refer to it. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
92 |
public_template: The public_template value is used as template |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
93 |
to display the public page of the found entity. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
94 |
|
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
95 |
Args: |
373
dcd7013ae0d5
Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents:
363
diff
changeset
|
96 |
request: the standard Django HTTP request object |
957
5b657063b23b
Add missing parameter description to docstring of soc.views.models.base module methods.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
939
diff
changeset
|
97 |
access_type : the name of the access type which should be checked |
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
|
98 |
page_name: the page name displayed in templates as page and header title |
471
dcb1f7821b39
Remove stop parameter from home_settings and site_settings views. This is something Sverre didn't mean to commit :-) Add missing params description to the models Base class docs.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
459
diff
changeset
|
99 |
params: a dict with params for this View |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
100 |
kwargs: the Key Fields for the specified entity |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
101 |
""" |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
102 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
103 |
# create default template context for use with any templates |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
104 |
context = helper.responses.getUniversalContext(request) |
482
839740b061ad
Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents:
471
diff
changeset
|
105 |
context['page_name'] = page_name |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
106 |
entity = None |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
107 |
|
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
445
diff
changeset
|
108 |
if not all(kwargs.values()): |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
445
diff
changeset
|
109 |
#TODO: Change this into a proper redirect |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
445
diff
changeset
|
110 |
return http.HttpResponseRedirect('/') |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
445
diff
changeset
|
111 |
|
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
112 |
try: |
1218
569a3fe9cb88
Cleaned up getKeyNameFromFields in Logic base.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1165
diff
changeset
|
113 |
entity = self._logic.getFromKeyFieldsOr404(kwargs) |
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
|
114 |
except out_of_band.Error, error: |
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:
639
diff
changeset
|
115 |
return helper.responses.errorResponse( |
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:
639
diff
changeset
|
116 |
error, request, template=params['error_public'], context=context) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
117 |
|
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
445
diff
changeset
|
118 |
self._public(request, entity, context) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
119 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
120 |
context['entity'] = entity |
455
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
121 |
context['entity_type'] = params['name'] |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
122 |
|
455
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
123 |
template = params['public_template'] |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
124 |
|
858
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
125 |
return helper.responses.respond(request, template, context=context) |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
126 |
|
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
127 |
@decorators.merge_params |
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
128 |
@decorators.check_access |
858
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
129 |
def export(self, request, access_type, |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
130 |
page_name=None, params=None, **kwargs): |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
131 |
"""Displays the export page for the entity specified by **kwargs. |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
132 |
|
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
133 |
Params usage: |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
134 |
rights: The rights dictionary is used to check if the user has |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
135 |
the required rights to view the export page for this entity. |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
136 |
See checkAccess for more details on how the rights dictionary |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
137 |
is used to check access rights. |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
138 |
error_export: The error_export value is used as template when |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
139 |
the key values (as defined by the page's url) do not |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
140 |
correspond to an existing entity. |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
141 |
name: The name value is used to set the entity_type in the |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
142 |
context so that the template can refer to it. |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
143 |
export_template: The export_template value is used as template |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
144 |
to display the export page of the found entity. |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
145 |
export_content_type: The export_content_type value is used to set |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
146 |
the Content-Type header of the HTTP response. If empty (or None), |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
147 |
public() is called instead. |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
148 |
|
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
149 |
Args: |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
150 |
request: the standard Django HTTP request object |
957
5b657063b23b
Add missing parameter description to docstring of soc.views.models.base module methods.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
939
diff
changeset
|
151 |
access_type : the name of the access type which should be checked |
858
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
152 |
page_name: the page name displayed in templates as page and header title |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
153 |
params: a dict with params for this View |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
154 |
kwargs: the Key Fields for the specified entity |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
155 |
""" |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
156 |
|
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
157 |
if not params.get('export_content_type'): |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
158 |
return self.public(request, access_type, page_name=page_name, |
874
30e9629bf590
Fixed two trivial bugs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
858
diff
changeset
|
159 |
params=params, **kwargs) |
858
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
160 |
|
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
161 |
# create default template context for use with any templates |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
162 |
context = helper.responses.getUniversalContext(request) |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
163 |
context['page_name'] = page_name |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
164 |
entity = None |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
165 |
|
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
166 |
if not all(kwargs.values()): |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
167 |
#TODO: Change this into a proper redirect |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
168 |
return http.HttpResponseRedirect('/') |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
169 |
|
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
170 |
try: |
1218
569a3fe9cb88
Cleaned up getKeyNameFromFields in Logic base.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1165
diff
changeset
|
171 |
entity = self._logic.getFromKeyFieldsOr404(kwargs) |
858
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
172 |
except out_of_band.Error, error: |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
173 |
return helper.responses.errorResponse( |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
174 |
error, request, template=params['error_export'], context=context) |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
175 |
|
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
176 |
self._export(request, entity, context) |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
177 |
|
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
178 |
context['entity'] = entity |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
179 |
context['entity_type'] = params['name'] |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
180 |
|
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
181 |
template = params['export_template'] |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
182 |
|
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
183 |
response_args = {'mimetype': params['export_content_type']} |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
184 |
|
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
185 |
return helper.responses.respond(request, template, context=context, |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
186 |
response_args=response_args) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
187 |
|
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
188 |
@decorators.check_access |
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
708
diff
changeset
|
189 |
def create(self, request, access_type, |
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
708
diff
changeset
|
190 |
page_name=None, params=None, **kwargs): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
497
diff
changeset
|
191 |
"""Displays the create page for this entity type. |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
192 |
|
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
193 |
Params usage: |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
194 |
The params dictionary is passed on to edit, see the docstring |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
195 |
for edit on how it uses it. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
196 |
|
373
dcd7013ae0d5
Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents:
363
diff
changeset
|
197 |
Args: |
dcd7013ae0d5
Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents:
363
diff
changeset
|
198 |
request: the standard Django HTTP request object |
957
5b657063b23b
Add missing parameter description to docstring of soc.views.models.base module methods.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
939
diff
changeset
|
199 |
access_type : the name of the access type which should be checked |
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
|
200 |
page_name: the page name displayed in templates as page and header title |
471
dcb1f7821b39
Remove stop parameter from home_settings and site_settings views. This is something Sverre didn't mean to commit :-) Add missing params description to the models Base class docs.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
459
diff
changeset
|
201 |
params: a dict with params for this View |
373
dcd7013ae0d5
Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents:
363
diff
changeset
|
202 |
kwargs: not used for create() |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
203 |
""" |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
204 |
|
663
c2dcae606699
Make base.View.create lookup the scope if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
205 |
new_params = dicts.merge(params, self._params) |
c2dcae606699
Make base.View.create lookup the scope if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
206 |
|
c2dcae606699
Make base.View.create lookup the scope if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
207 |
if ('scope_view' in new_params) and ('scope_path' not in kwargs): |
c2dcae606699
Make base.View.create lookup the scope if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
208 |
view = new_params['scope_view'].view |
c2dcae606699
Make base.View.create lookup the scope if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
209 |
redirect = new_params['scope_redirect'] |
c2dcae606699
Make base.View.create lookup the scope if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
210 |
return self.select(request, view, redirect, |
c2dcae606699
Make base.View.create lookup the scope if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
211 |
params=params, page_name=page_name, **kwargs) |
c2dcae606699
Make base.View.create lookup the scope if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
212 |
|
c2dcae606699
Make base.View.create lookup the scope if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
213 |
params = new_params |
492
4abdeedfc08e
Fixed redirection after creation to Just Work
Sverre Rabbelier <srabbelier@gmail.com>
parents:
490
diff
changeset
|
214 |
|
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
215 |
# Create page is an edit page with no key fields |
490
7cfa2ad62944
Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents:
482
diff
changeset
|
216 |
empty_kwargs = {} |
410
2af7f84f4fc7
Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
409
diff
changeset
|
217 |
fields = self._logic.getKeyFieldNames() |
2af7f84f4fc7
Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
409
diff
changeset
|
218 |
for field in fields: |
490
7cfa2ad62944
Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents:
482
diff
changeset
|
219 |
empty_kwargs[field] = None |
410
2af7f84f4fc7
Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
409
diff
changeset
|
220 |
|
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
708
diff
changeset
|
221 |
return self.edit(request, access_type, page_name=page_name, |
708
89f1a8c2ea59
Some cleanups in role.py and site.py and create()
Sverre Rabbelier <srabbelier@gmail.com>
parents:
703
diff
changeset
|
222 |
params=params, seed=kwargs, **empty_kwargs) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
223 |
|
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
224 |
@decorators.merge_params |
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
225 |
@decorators.check_access |
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
708
diff
changeset
|
226 |
def edit(self, request, access_type, |
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
708
diff
changeset
|
227 |
page_name=None, params=None, seed=None, **kwargs): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
497
diff
changeset
|
228 |
"""Displays the edit page for the entity specified by **kwargs. |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
229 |
|
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
230 |
Params usage: |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
231 |
The params dictionary is passed on to either editGet or editPost |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
232 |
depending on the method type of the request. See the docstring |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
233 |
for editGet and editPost on how they use it. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
234 |
|
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
235 |
rights: The rights dictionary is used to check if the user has |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
236 |
the required rights to edit (or create) a new entity. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
237 |
See checkAccess for more details on how the rights dictionary |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
238 |
is used to check access rights. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
239 |
name: The name value is used to construct the message_fmt of the |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
240 |
raised error when there key_values do not define an existing |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
241 |
entity. See DEF_CREATE_NEW_ENTITY_MSG_FMT on how the name |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
242 |
(and the lower() version of it) is used. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
243 |
missing_redirect: The missing_redirect value is also used to |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
244 |
construct the message_fmt mentioned above. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
245 |
error_public: The error_public value is used as the template for |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
246 |
the error response mentioned above. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
247 |
|
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
248 |
Args: |
373
dcd7013ae0d5
Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents:
363
diff
changeset
|
249 |
request: the standard Django HTTP request object |
957
5b657063b23b
Add missing parameter description to docstring of soc.views.models.base module methods.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
939
diff
changeset
|
250 |
access_type : the name of the access type which should be checked |
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
|
251 |
page_name: the page name displayed in templates as page and header title |
471
dcb1f7821b39
Remove stop parameter from home_settings and site_settings views. This is something Sverre didn't mean to commit :-) Add missing params description to the models Base class docs.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
459
diff
changeset
|
252 |
params: a dict with params for this View |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
253 |
kwargs: The Key Fields for the specified entity |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
254 |
""" |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
255 |
|
373
dcd7013ae0d5
Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents:
363
diff
changeset
|
256 |
context = helper.responses.getUniversalContext(request) |
482
839740b061ad
Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents:
471
diff
changeset
|
257 |
context['page_name'] = page_name |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
258 |
entity = None |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
259 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
260 |
try: |
439
0658c3c9a9dc
Minor fixes needed for generic key name
Sverre Rabbelier <srabbelier@gmail.com>
parents:
438
diff
changeset
|
261 |
if all(kwargs.values()): |
1218
569a3fe9cb88
Cleaned up getKeyNameFromFields in Logic base.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1165
diff
changeset
|
262 |
entity = self._logic.getFromKeyFieldsOr404(kwargs) |
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
|
263 |
except out_of_band.Error, error: |
490
7cfa2ad62944
Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents:
482
diff
changeset
|
264 |
if not seed: |
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
|
265 |
error.message_fmt = ( |
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
|
266 |
error.message_fmt + self.DEF_CREATE_NEW_ENTITY_MSG_FMT % { |
490
7cfa2ad62944
Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents:
482
diff
changeset
|
267 |
'entity_type_lower' : params['name'].lower(), |
7cfa2ad62944
Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents:
482
diff
changeset
|
268 |
'entity_type' : params['name'], |
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
|
269 |
'create' : params['missing_redirect']}) |
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:
639
diff
changeset
|
270 |
return helper.responses.errorResponse( |
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:
639
diff
changeset
|
271 |
error, request, template=params['error_public'], context=context) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
272 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
273 |
if request.method == 'POST': |
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
274 |
return self.editPost(request, entity, context, params=params) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
275 |
else: |
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
276 |
return self.editGet(request, entity, context, seed, params=params) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
277 |
|
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
278 |
@decorators.merge_params |
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
279 |
def editPost(self, request, entity, context, params=None): |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
632
diff
changeset
|
280 |
"""Processes POST requests for the specified entity. |
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
281 |
|
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
282 |
Params usage: |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
283 |
The params dictionary is passed to _constructResponse when the |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
284 |
form is not valid (see edit_form and create_form below). See |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
285 |
the docstring of _constructResponse on how it uses it. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
286 |
|
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
287 |
edit_form: The edit_form value is used as form when there is an |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
288 |
existing entity. It is provided with with the request.POST |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
289 |
dictionary on construction. The collectCleanedFields method |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
290 |
is called with the newly constructed form. If the form is |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
291 |
not valid, it is passed as argument to _constructResponse. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
292 |
create_form: The create_form value is used in a similar way to |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
293 |
edit_form, only it is used when there is no existing entity. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
294 |
edit_redirect: The edit_redirect value is used as the first part |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
295 |
of the url if the form was valid. The last part of the url is |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
296 |
created using the getKeySuffix method of the _logic object. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
297 |
edit_params: The edit_params dictionary is used as argument to |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
298 |
redirectToChangedSuffix, it will be appended to the url in the |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
299 |
standard ?key=value format. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
300 |
|
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
301 |
Args: |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
302 |
request: a django request object |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
303 |
entity: the entity that will be modified or created, may be None |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
304 |
context: the context dictionary that will be provided to Django |
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
305 |
params: required, a dict with params for this View |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
306 |
""" |
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
307 |
|
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
308 |
if entity: |
455
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
309 |
form = params['edit_form'](request.POST) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
310 |
else: |
455
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
311 |
form = params['create_form'](request.POST) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
312 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
313 |
if not form.is_valid(): |
455
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
314 |
return self._constructResponse(request, entity, context, form, params) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
315 |
|
612
3cca81b1e5a1
Moved checkAccess and getCleanedFields into access and forms
Sverre Rabbelier <srabbelier@gmail.com>
parents:
611
diff
changeset
|
316 |
key_name, fields = forms.collectCleanedFields(form) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
317 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
318 |
self._editPost(request, entity, fields) |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
319 |
|
459
2cfcedaf7c16
Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
458
diff
changeset
|
320 |
if not key_name: |
1218
569a3fe9cb88
Cleaned up getKeyNameFromFields in Logic base.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1165
diff
changeset
|
321 |
key_name = self._logic.getKeyNameFromFields(fields) |
459
2cfcedaf7c16
Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
458
diff
changeset
|
322 |
|
2cfcedaf7c16
Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
458
diff
changeset
|
323 |
entity = self._logic.updateOrCreateFromKeyName(fields, key_name) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
324 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
325 |
if not entity: |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
326 |
return http.HttpResponseRedirect('/') |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
327 |
|
455
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
328 |
page_params = params['edit_params'] |
735
28225172af06
Make it possible to redirect anywhere after editPost
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
329 |
params['suffix'] = self._logic.getKeySuffix(entity) |
28225172af06
Make it possible to redirect anywhere after editPost
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
330 |
|
28225172af06
Make it possible to redirect anywhere after editPost
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
331 |
request.path = params['edit_redirect'] % params |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
332 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
333 |
# redirect to (possibly new) location of the entity |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
334 |
# (causes 'Profile saved' message to be displayed) |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
335 |
return helper.responses.redirectToChangedSuffix( |
735
28225172af06
Make it possible to redirect anywhere after editPost
Sverre Rabbelier <srabbelier@gmail.com>
parents:
714
diff
changeset
|
336 |
request, None, params=page_params) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
337 |
|
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
338 |
@decorators.merge_params |
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
339 |
def editGet(self, request, entity, context, seed, params=None): |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
632
diff
changeset
|
340 |
"""Processes GET requests for the specified entity. |
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
341 |
|
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
342 |
Params usage: |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
343 |
The params dictionary is passed to _constructResponse, see the |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
632
diff
changeset
|
344 |
docstring of _constructResponse on how it uses it. |
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
345 |
|
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
346 |
save_message: The save_message list is used as argument to |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
347 |
getSingleIndexedParamValue when an existing entity was saved. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
348 |
edit_form: The edit_form is used as form if there is an existing |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
349 |
entity. The existing entity is passed as instance to it on |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
350 |
construction. If key_name is part of it's fields it will be |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
351 |
set to the entity's key().name() value. It is also passed as |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
352 |
argument to the _editGet method. See the docstring for |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
353 |
_editGet on how it uses it. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
354 |
create_form: The create_form is used as form if there was no |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
355 |
existing entity. If the seed argument is present, it is passed |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
356 |
as the 'initial' argument on construction. Otherwise, it is |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
357 |
called with no arguments. |
611
2ec30182e5f1
Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
610
diff
changeset
|
358 |
submit_msg_param_name: The submit_msg_param_name value is used |
2ec30182e5f1
Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
610
diff
changeset
|
359 |
as the key part in the ?key=value construct for the submit |
2ec30182e5f1
Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
610
diff
changeset
|
360 |
message parameter (see also save_message). |
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
361 |
|
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
362 |
Args: |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
363 |
request: the django request object |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
364 |
entity: the entity that will be edited, may be None |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
365 |
context: the context dictionary that will be provided to django |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
366 |
seed: if no entity is provided, the initial values for the new entity |
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
367 |
params: required, a dict with params for this View |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
368 |
""" |
403
d3e545a8bd26
Some more improvements to the generic view code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
369 |
|
410
2af7f84f4fc7
Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
409
diff
changeset
|
370 |
suffix = self._logic.getKeySuffix(entity) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
371 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
372 |
# Remove the params from the request, this is relevant only if |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
373 |
# someone bookmarked a POST page. |
387
c55195361cb6
Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents:
373
diff
changeset
|
374 |
is_self_referrer = helper.requests.isReferrerSelf(request, suffix=suffix) |
611
2ec30182e5f1
Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
610
diff
changeset
|
375 |
if request.GET.get(params['submit_msg_param_name']): |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
376 |
if (not entity) or (not is_self_referrer): |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
377 |
return http.HttpResponseRedirect(request.path) |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
378 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
379 |
if entity: |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
380 |
# Note: no message will be displayed if parameter is not present |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
381 |
context['notice'] = helper.requests.getSingleIndexedParamValue( |
611
2ec30182e5f1
Move parameter construction into a seperate module
Sverre Rabbelier <srabbelier@gmail.com>
parents:
610
diff
changeset
|
382 |
request, params['submit_msg_param_name'], |
455
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
383 |
values=params['save_message']) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
384 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
385 |
# populate form with the existing entity |
455
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
386 |
form = params['edit_form'](instance=entity) |
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
387 |
|
459
2cfcedaf7c16
Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
458
diff
changeset
|
388 |
if 'key_name' in form.fields: |
2cfcedaf7c16
Preparation for generic user views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
458
diff
changeset
|
389 |
form.fields['key_name'].initial = entity.key().name() |
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
390 |
|
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
391 |
self._editGet(request, entity, form) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
392 |
else: |
939
b341698bf3b1
Make reference picker work for create too
Sverre Rabbelier <srabbelier@gmail.com>
parents:
937
diff
changeset
|
393 |
seed = seed if seed else {} |
b341698bf3b1
Make reference picker work for create too
Sverre Rabbelier <srabbelier@gmail.com>
parents:
937
diff
changeset
|
394 |
self._editSeed(request, seed) |
b341698bf3b1
Make reference picker work for create too
Sverre Rabbelier <srabbelier@gmail.com>
parents:
937
diff
changeset
|
395 |
|
490
7cfa2ad62944
Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents:
482
diff
changeset
|
396 |
if seed: |
7cfa2ad62944
Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents:
482
diff
changeset
|
397 |
form = params['create_form'](initial=seed) |
7cfa2ad62944
Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents:
482
diff
changeset
|
398 |
else: |
7cfa2ad62944
Allow pre-seeding a create form
Sverre Rabbelier <srabbelier@gmail.com>
parents:
482
diff
changeset
|
399 |
form = params['create_form']() |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
400 |
|
455
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
401 |
return self._constructResponse(request, entity, context, form, params) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
402 |
|
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
403 |
@decorators.merge_params |
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
404 |
@decorators.check_access |
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
708
diff
changeset
|
405 |
def list(self, request, access_type, |
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
708
diff
changeset
|
406 |
page_name=None, params=None, filter=None): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
497
diff
changeset
|
407 |
"""Displays the list page for the entity type. |
373
dcd7013ae0d5
Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents:
363
diff
changeset
|
408 |
|
dcd7013ae0d5
Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents:
363
diff
changeset
|
409 |
Args: |
dcd7013ae0d5
Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents:
363
diff
changeset
|
410 |
request: the standard Django HTTP request object |
957
5b657063b23b
Add missing parameter description to docstring of soc.views.models.base module methods.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
939
diff
changeset
|
411 |
access_type : the name of the access type which should be checked |
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
|
412 |
page_name: the page name displayed in templates as page and header title |
471
dcb1f7821b39
Remove stop parameter from home_settings and site_settings views. This is something Sverre didn't mean to commit :-) Add missing params description to the models Base class docs.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
459
diff
changeset
|
413 |
params: a dict with params for this View |
516
ec1dcd70b97e
The list method in models/base.py can now use a filter to make a selection of entities to show.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
514
diff
changeset
|
414 |
filter: a dict for the properties that the entities should have |
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
415 |
|
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
416 |
Params usage: |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
417 |
The params dictionary is passed as argument to getListContent in |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
632
diff
changeset
|
418 |
the soc.views.helper.list module. See the docstring for getListContent |
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
632
diff
changeset
|
419 |
on how it uses it. The params dictionary is also passed as argument to |
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
632
diff
changeset
|
420 |
the _list method. See the docstring for _list on how it uses it. |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
421 |
""" |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
422 |
|
651
ef6e22d463cb
Remove the logic parameter from getListContent
Sverre Rabbelier <srabbelier@gmail.com>
parents:
646
diff
changeset
|
423 |
content = helper.lists.getListContent(request, params, filter) |
555
3cdfb42d941b
Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents:
554
diff
changeset
|
424 |
contents = [content] |
3cdfb42d941b
Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents:
554
diff
changeset
|
425 |
|
3cdfb42d941b
Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents:
554
diff
changeset
|
426 |
return self._list(request, params, contents, page_name) |
3cdfb42d941b
Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents:
554
diff
changeset
|
427 |
|
1296
64918d0c97ea
Implemented the 2nd part of bulk acceptance.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1269
diff
changeset
|
428 |
def _list(self, request, params, contents, page_name, context={}): |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
632
diff
changeset
|
429 |
"""Returns the list page for the specified contents. |
555
3cdfb42d941b
Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents:
554
diff
changeset
|
430 |
|
3cdfb42d941b
Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents:
554
diff
changeset
|
431 |
Args: |
3cdfb42d941b
Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents:
554
diff
changeset
|
432 |
request: the standard Django HTTP request object |
3cdfb42d941b
Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents:
554
diff
changeset
|
433 |
params: a dict with params for this View |
3cdfb42d941b
Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents:
554
diff
changeset
|
434 |
contents: a list of content dicts |
3cdfb42d941b
Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents:
554
diff
changeset
|
435 |
page_name: the page name displayed in templates as page and header title |
1296
64918d0c97ea
Implemented the 2nd part of bulk acceptance.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1269
diff
changeset
|
436 |
context: the context for this page |
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
437 |
|
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
438 |
Params usage: |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
439 |
name: The name value is used to set the entity_type in the |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
440 |
context so that the template can refer to it. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
441 |
name_plural: The name_plural value is used to set |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
442 |
the entity_type_plural value in the context so that the |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
443 |
template can refer to it. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
444 |
list_template: The list_template value is used as template for |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
445 |
to display the list of all entities for this View. |
555
3cdfb42d941b
Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents:
554
diff
changeset
|
446 |
""" |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
447 |
|
1296
64918d0c97ea
Implemented the 2nd part of bulk acceptance.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1269
diff
changeset
|
448 |
context = dicts.merge(context, |
64918d0c97ea
Implemented the 2nd part of bulk acceptance.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1269
diff
changeset
|
449 |
helper.responses.getUniversalContext(request)) |
555
3cdfb42d941b
Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents:
554
diff
changeset
|
450 |
context['page_name'] = page_name |
3cdfb42d941b
Split the list view code up in three pieces
Sverre Rabbelier <srabbelier@gmail.com>
parents:
554
diff
changeset
|
451 |
context['list'] = soc.logic.lists.Lists(contents) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
452 |
|
455
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
453 |
context['entity_type'] = params['name'] |
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
454 |
context['entity_type_plural'] = params['name_plural'] |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
455 |
|
455
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
456 |
template = params['list_template'] |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
457 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
458 |
return helper.responses.respond(request, template, context) |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
459 |
|
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
460 |
@decorators.merge_params |
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
461 |
@decorators.check_access |
710
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
708
diff
changeset
|
462 |
def delete(self, request, access_type, |
edb5dbb1dea7
Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents:
708
diff
changeset
|
463 |
page_name=None, params=None, **kwargs): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
497
diff
changeset
|
464 |
"""Shows the delete page for the entity specified by **kwargs. |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
465 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
466 |
Args: |
373
dcd7013ae0d5
Add the Page object to the context of each view method. Also, add some missing
Todd Larsen <tlarsen@google.com>
parents:
363
diff
changeset
|
467 |
request: the standard Django HTTP request object |
957
5b657063b23b
Add missing parameter description to docstring of soc.views.models.base module methods.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
939
diff
changeset
|
468 |
access_type : the name of the access type which should be checked |
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
|
469 |
page_name: the page name displayed in templates as page and header title |
471
dcb1f7821b39
Remove stop parameter from home_settings and site_settings views. This is something Sverre didn't mean to commit :-) Add missing params description to the models Base class docs.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
459
diff
changeset
|
470 |
params: a dict with params for this View |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
471 |
kwargs: The Key Fields for the specified entity |
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
472 |
|
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
473 |
Params usage: |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
474 |
rights: The rights dictionary is used to check if the user has |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
632
diff
changeset
|
475 |
the required rights to delete the specified entity. See checkAccess |
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
632
diff
changeset
|
476 |
for more details on how the rights dictionary is used to check access |
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
632
diff
changeset
|
477 |
rights. |
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
478 |
name: used in the same way as in edit(), see it's docstring for |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
479 |
a more detailed explanation on how it is used. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
480 |
missing_redirect: see name |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
481 |
error_edit: see name |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
482 |
delete_redirect: The delete_redirect value is used as the url to |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
483 |
redirect to after having successfully deleted the entity. |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
484 |
""" |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
485 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
486 |
# create default template context for use with any templates |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
487 |
context = helper.responses.getUniversalContext(request) |
482
839740b061ad
Factor out direct use of the page object
Sverre Rabbelier <srabbelier@gmail.com>
parents:
471
diff
changeset
|
488 |
context['page_name'] = page_name |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
489 |
entity = None |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
490 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
491 |
try: |
1218
569a3fe9cb88
Cleaned up getKeyNameFromFields in Logic base.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
1165
diff
changeset
|
492 |
entity = self._logic.getFromKeyFieldsOr404(kwargs) |
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
|
493 |
except out_of_band.Error, error: |
280a1ac6bcc1
Merge soc/logic/out_of_band.py into soc/views/out_of_band.py. Merge
Todd Larsen <tlarsen@google.com>
parents:
542
diff
changeset
|
494 |
error.message_fmt = ( |
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
|
495 |
error.message_fmt + self.DEF_CREATE_NEW_ENTITY_MSG_FMT % { |
455
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
496 |
'entity_type_lower' : params['name'].lower(), |
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
497 |
'entity_type' : params['name'], |
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
|
498 |
'create' : params['missing_redirect']}) |
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:
639
diff
changeset
|
499 |
return helper.responses.errorResponse( |
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:
639
diff
changeset
|
500 |
error, request, template=params['error_edit'], context=context) |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
501 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
502 |
if not entity: |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
503 |
#TODO: Create a proper error page for this |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
504 |
return http.HttpResponseRedirect('/') |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
505 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
506 |
if not self._logic.isDeletable(entity): |
389
9b873166d7d5
Fix identions, too long lines, unused imports and some other mistakes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
387
diff
changeset
|
507 |
# TODO: Update the notice area telling the user that they |
9b873166d7d5
Fix identions, too long lines, unused imports and some other mistakes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
387
diff
changeset
|
508 |
# can't delete the entity |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
509 |
pass |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
510 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
511 |
self._logic.delete(entity) |
455
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
512 |
redirect = params['delete_redirect'] |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
513 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
514 |
return http.HttpResponseRedirect(redirect) |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
515 |
|
933
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
516 |
def select(self, request, view, redirect, |
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
517 |
page_name=None, params=None, filter=None): |
668
77f9a6ea6e67
Some style and typo fixes in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
663
diff
changeset
|
518 |
"""Displays a list page allowing the user to select an entity. |
653
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
519 |
|
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
520 |
After having selected the Scope, the user is redirected to the |
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
521 |
'create a new entity' page with the scope_path set appropriately. |
653
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
522 |
|
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
523 |
Params usage: |
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
524 |
The params dictionary is also passed to getListContent from |
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
525 |
the helper.list module, please refer to its docstring also. |
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
526 |
The params dictionary is passed to self._list as well, refer |
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
527 |
to its docstring for details on how it uses it. |
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
528 |
|
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
529 |
Args: |
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
530 |
request: the standard Django HTTP request object |
933
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
531 |
view: the view for which to generate the select page |
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
532 |
redirect: the redirect to use |
653
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
533 |
page_name: the page name displayed in templates as page and header title |
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
534 |
params: a dict with params for this View |
933
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
535 |
filter: a filter that all displayed entities should satisfy |
653
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
536 |
""" |
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
537 |
|
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
538 |
params = dicts.merge(params, view.getParams()) |
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
539 |
params = dicts.merge(params, self._params) |
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
540 |
params['list_action'] = (redirect, self._params) |
663
c2dcae606699
Make base.View.create lookup the scope if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
541 |
params['list_description'] = self.DEF_CREATE_INSTRUCTION_MSG_FMT % ( |
c2dcae606699
Make base.View.create lookup the scope if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
662
diff
changeset
|
542 |
params['name'], self._params['name']) |
653
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
543 |
|
933
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
544 |
content = helper.lists.getListContent(request, params, filter=filter) |
653
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
545 |
contents = [content] |
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
546 |
|
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
547 |
return self._list(request, params, contents, page_name) |
5105939d3bb4
Make the 'select entity' View generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
652
diff
changeset
|
548 |
|
933
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
549 |
@decorators.merge_params |
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
550 |
@decorators.check_access |
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
551 |
def pick(self, request, acces_type, page_name=None, params=None): |
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
552 |
"""Displays a list page allowing the user to select an entity. |
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
553 |
|
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
554 |
After having selected an entity, the user is redirected to the |
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
555 |
return_url as specified in the GET args. |
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
556 |
|
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
557 |
Params usage: |
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
558 |
The params dictionary is passed to self.select, refer |
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
559 |
to its docstring for details on how it uses it. |
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
560 |
|
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
561 |
Args: |
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
562 |
request: the standard Django HTTP request object |
957
5b657063b23b
Add missing parameter description to docstring of soc.views.models.base module methods.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
939
diff
changeset
|
563 |
access_type : the name of the access type which should be checked |
933
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
564 |
page_name: the page name displayed in templates as page and header title |
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
565 |
params: a dict with params for this View |
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
566 |
""" |
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
567 |
|
1304
b736aed728c2
Convert the QueryDict to a regular dictionary
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1296
diff
changeset
|
568 |
# convert to a regular dict |
b736aed728c2
Convert the QueryDict to a regular dictionary
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1296
diff
changeset
|
569 |
filter = {} |
b736aed728c2
Convert the QueryDict to a regular dictionary
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1296
diff
changeset
|
570 |
for key in request.GET.keys(): |
b736aed728c2
Convert the QueryDict to a regular dictionary
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1296
diff
changeset
|
571 |
# need to use getlist as we want to support multiple values |
b736aed728c2
Convert the QueryDict to a regular dictionary
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1296
diff
changeset
|
572 |
filter[key] = request.GET.getlist(key) |
933
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
573 |
|
1304
b736aed728c2
Convert the QueryDict to a regular dictionary
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1296
diff
changeset
|
574 |
entities = self._logic.getForFields(filter=filter, limit=1000) |
b736aed728c2
Convert the QueryDict to a regular dictionary
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1296
diff
changeset
|
575 |
data = [i.toDict() for i in entities] |
933
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
576 |
|
977
d212d5f4c41a
Have /entity/pick return a JSON object instead of a user view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
973
diff
changeset
|
577 |
to_json = { |
d212d5f4c41a
Have /entity/pick return a JSON object instead of a user view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
973
diff
changeset
|
578 |
'data': data, |
d212d5f4c41a
Have /entity/pick return a JSON object instead of a user view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
973
diff
changeset
|
579 |
} |
d212d5f4c41a
Have /entity/pick return a JSON object instead of a user view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
973
diff
changeset
|
580 |
|
d212d5f4c41a
Have /entity/pick return a JSON object instead of a user view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
973
diff
changeset
|
581 |
json = simplejson.dumps(to_json) |
d212d5f4c41a
Have /entity/pick return a JSON object instead of a user view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
973
diff
changeset
|
582 |
|
d212d5f4c41a
Have /entity/pick return a JSON object instead of a user view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
973
diff
changeset
|
583 |
context = {'json': json} |
d212d5f4c41a
Have /entity/pick return a JSON object instead of a user view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
973
diff
changeset
|
584 |
template = 'soc/json.html' |
d212d5f4c41a
Have /entity/pick return a JSON object instead of a user view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
973
diff
changeset
|
585 |
|
d212d5f4c41a
Have /entity/pick return a JSON object instead of a user view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
973
diff
changeset
|
586 |
return helper.responses.respond(request, template, context) |
933
7331232d6356
Added a 'pick' view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
880
diff
changeset
|
587 |
|
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
588 |
def _editPost(self, request, entity, fields): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
497
diff
changeset
|
589 |
"""Performs any required processing on the entity to post its edit page. |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
590 |
|
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
591 |
Args: |
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
592 |
request: the django request object |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
632
diff
changeset
|
593 |
entity: the entity to create or update from POST contents |
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
594 |
fields: the new field values |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
595 |
""" |
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
596 |
|
1268
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
597 |
scope_path = self._logic.getKeyNameFromFields(fields) |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
598 |
|
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
599 |
key_fields = { |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
600 |
'scope_path': scope_path, |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
601 |
'prefix': self._params['document_prefix'], |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
602 |
} |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
603 |
|
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
604 |
for field_name, original_name, logic, _ in self._params['references']: |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
605 |
if field_name not in fields: |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
606 |
continue |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
607 |
|
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
608 |
key_fields['link_id'] = fields[field_name] |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
609 |
|
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
610 |
# TODO notify the user if home_doc is not found |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
611 |
entity = logic.getFromKeyFields(key_fields) |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
612 |
fields[original_name] = entity |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
613 |
|
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
653
diff
changeset
|
614 |
# If scope_logic is not defined, this entity has no scope |
677
c8f24e3078b8
Fix scope lookup for unscoped entities
Sverre Rabbelier <srabbelier@gmail.com>
parents:
668
diff
changeset
|
615 |
if not self._params['scope_logic']: |
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
653
diff
changeset
|
616 |
return |
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
653
diff
changeset
|
617 |
|
714
3e2ce3d8057a
Add missing dots in docstrings, proper sorting of imports and small docstring typo fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
710
diff
changeset
|
618 |
# If this entity is unscoped, do not try to retrieve a scope |
701
d6f5d34cff5a
If an entity is unscoped, do not try to retrieve a scope
Sverre Rabbelier <srabbelier@gmail.com>
parents:
677
diff
changeset
|
619 |
if 'scope_path' not in fields: |
d6f5d34cff5a
If an entity is unscoped, do not try to retrieve a scope
Sverre Rabbelier <srabbelier@gmail.com>
parents:
677
diff
changeset
|
620 |
return |
d6f5d34cff5a
If an entity is unscoped, do not try to retrieve a scope
Sverre Rabbelier <srabbelier@gmail.com>
parents:
677
diff
changeset
|
621 |
|
755
1ed041c0cdc6
Remove unused imports and variables in different soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
735
diff
changeset
|
622 |
scope = self._params['scope_logic'].logic.getFromKeyName( |
1ed041c0cdc6
Remove unused imports and variables in different soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
735
diff
changeset
|
623 |
fields['scope_path']) |
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
653
diff
changeset
|
624 |
fields['scope'] = scope |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
445
diff
changeset
|
625 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
445
diff
changeset
|
626 |
def _public(self, request, entity, context): |
880 | 627 |
"""Performs any required processing to get an entity's public page. |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
445
diff
changeset
|
628 |
|
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
445
diff
changeset
|
629 |
Args: |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
445
diff
changeset
|
630 |
request: the django request object |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
445
diff
changeset
|
631 |
entity: the entity to make public |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
445
diff
changeset
|
632 |
context: the context object |
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
445
diff
changeset
|
633 |
""" |
858
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
634 |
pass |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
445
diff
changeset
|
635 |
|
858
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
636 |
def _export(self, request, entity, context): |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
637 |
"""Performs any required processing to get an entity's export page. |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
638 |
|
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
639 |
Args: |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
640 |
request: the django request object |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
641 |
entity: the entity to export |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
642 |
context: the context object |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
643 |
""" |
446
0b479d573a4c
Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
445
diff
changeset
|
644 |
pass |
363
d35ffa6ca643
Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
645 |
|
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
646 |
def _editGet(self, request, entity, form): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
497
diff
changeset
|
647 |
"""Performs any required processing on the form to get its edit page. |
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
648 |
|
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
649 |
Args: |
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
650 |
request: the django request object |
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
651 |
entity: the entity to get |
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
652 |
form: the django form that will be used for the page |
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
653 |
""" |
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
654 |
|
662
0e89b027b140
Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents:
653
diff
changeset
|
655 |
# fill in the email field with the data from the entity |
677
c8f24e3078b8
Fix scope lookup for unscoped entities
Sverre Rabbelier <srabbelier@gmail.com>
parents:
668
diff
changeset
|
656 |
if 'scope_path' in form.fields: |
c8f24e3078b8
Fix scope lookup for unscoped entities
Sverre Rabbelier <srabbelier@gmail.com>
parents:
668
diff
changeset
|
657 |
form.fields['scope_path'].initial = entity.scope_path |
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
658 |
|
1268
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
659 |
for field_name, original_name, _, getter in self._params['references']: |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
660 |
try: |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
661 |
field = getter(entity) |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
662 |
form.fields[field_name].initial = field.link_id if field else None |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
663 |
except db.Error: |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
664 |
pass |
9d092b702f92
Resolve references if they are specified
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1227
diff
changeset
|
665 |
|
934
9fcc08971efe
Add a 'pick' view to the appropriate views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
933
diff
changeset
|
666 |
field = request.GET.get('field', None) |
9fcc08971efe
Add a 'pick' view to the appropriate views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
933
diff
changeset
|
667 |
value = request.GET.get('value', None) |
9fcc08971efe
Add a 'pick' view to the appropriate views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
933
diff
changeset
|
668 |
|
937
9c930fa3661c
Do not crash if an invalid field name is entered
Sverre Rabbelier <srabbelier@gmail.com>
parents:
935
diff
changeset
|
669 |
if field and value and field in form.fields: |
934
9fcc08971efe
Add a 'pick' view to the appropriate views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
933
diff
changeset
|
670 |
form.fields[field].initial = value |
9fcc08971efe
Add a 'pick' view to the appropriate views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
933
diff
changeset
|
671 |
|
497
73666a7cd718
Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
495
diff
changeset
|
672 |
def _editSeed(self, request, seed): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
497
diff
changeset
|
673 |
"""Performs any required processing on the form to get its edit page. |
497
73666a7cd718
Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
495
diff
changeset
|
674 |
|
73666a7cd718
Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
495
diff
changeset
|
675 |
Args: |
73666a7cd718
Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
495
diff
changeset
|
676 |
request: the django request object |
73666a7cd718
Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
495
diff
changeset
|
677 |
seed: the fields to seed the create page with |
73666a7cd718
Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
495
diff
changeset
|
678 |
""" |
73666a7cd718
Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
495
diff
changeset
|
679 |
|
939
b341698bf3b1
Make reference picker work for create too
Sverre Rabbelier <srabbelier@gmail.com>
parents:
937
diff
changeset
|
680 |
field = request.GET.get('field', None) |
b341698bf3b1
Make reference picker work for create too
Sverre Rabbelier <srabbelier@gmail.com>
parents:
937
diff
changeset
|
681 |
value = request.GET.get('value', None) |
b341698bf3b1
Make reference picker work for create too
Sverre Rabbelier <srabbelier@gmail.com>
parents:
937
diff
changeset
|
682 |
|
b341698bf3b1
Make reference picker work for create too
Sverre Rabbelier <srabbelier@gmail.com>
parents:
937
diff
changeset
|
683 |
if field and value: |
b341698bf3b1
Make reference picker work for create too
Sverre Rabbelier <srabbelier@gmail.com>
parents:
937
diff
changeset
|
684 |
seed[field] = value |
497
73666a7cd718
Added a default _editSeed method
Sverre Rabbelier <srabbelier@gmail.com>
parents:
495
diff
changeset
|
685 |
|
1269
62b1e9ee46c5
Add an _editContext hook
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1268
diff
changeset
|
686 |
def _editContext(self, request, context): |
62b1e9ee46c5
Add an _editContext hook
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1268
diff
changeset
|
687 |
"""Performs any required processing on the context for edit pages. |
62b1e9ee46c5
Add an _editContext hook
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1268
diff
changeset
|
688 |
|
62b1e9ee46c5
Add an _editContext hook
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1268
diff
changeset
|
689 |
Args: |
62b1e9ee46c5
Add an _editContext hook
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1268
diff
changeset
|
690 |
request: the django request object |
62b1e9ee46c5
Add an _editContext hook
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1268
diff
changeset
|
691 |
context: the context dictionary that will be used |
62b1e9ee46c5
Add an _editContext hook
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1268
diff
changeset
|
692 |
""" |
62b1e9ee46c5
Add an _editContext hook
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1268
diff
changeset
|
693 |
|
62b1e9ee46c5
Add an _editContext hook
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1268
diff
changeset
|
694 |
pass |
62b1e9ee46c5
Add an _editContext hook
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1268
diff
changeset
|
695 |
|
455
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
696 |
def _constructResponse(self, request, entity, context, form, params): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
497
diff
changeset
|
697 |
"""Updates the context and returns a response for the specified arguments. |
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
698 |
|
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
699 |
Args: |
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
700 |
request: the django request object |
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
701 |
entity: the entity that is used and set in the context |
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
702 |
context: the context to be used |
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
703 |
form: the form that will be used and set in the context |
471
dcb1f7821b39
Remove stop parameter from home_settings and site_settings views. This is something Sverre didn't mean to commit :-) Add missing params description to the models Base class docs.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
459
diff
changeset
|
704 |
params: a dict with params for this View |
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
705 |
|
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
706 |
Params usage: |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
707 |
name: The name_plural value is used to set the entity_type |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
708 |
value in the context so that the template can refer to it. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
709 |
name_plural: same as name, but used to set entity_type_plural |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
710 |
name_short: same as name, but used to set entity_type_short |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
711 |
url_name: same as name, but used to set entity_type_url |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
712 |
edit_template: The edit_template value is used as template when |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
713 |
there is an existing entity to display the edit page for the |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
714 |
specified entity. |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
715 |
create_template: similar to edit_template, but is used when |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
716 |
there is no existing entity. |
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
717 |
""" |
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
718 |
|
410
2af7f84f4fc7
Moved all key_name related things to the logic modules
Sverre Rabbelier <srabbelier@gmail.com>
parents:
409
diff
changeset
|
719 |
suffix = self._logic.getKeySuffix(entity) |
403
d3e545a8bd26
Some more improvements to the generic view code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
720 |
|
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
721 |
context['form'] = form |
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
722 |
context['entity'] = entity |
403
d3e545a8bd26
Some more improvements to the generic view code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
402
diff
changeset
|
723 |
context['entity_suffix'] = suffix |
455
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
724 |
context['entity_type'] = params['name'] |
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
725 |
context['entity_type_plural'] = params['name_plural'] |
4d98832b43ba
Added support for providing a custom params dict
Sverre Rabbelier <srabbelier@gmail.com>
parents:
446
diff
changeset
|
726 |
context['entity_type_short'] = params['name_short'] |
502
e1e24c0a4e82
Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
500
diff
changeset
|
727 |
context['entity_type_url'] = params['url_name'] |
1035
04229d710ce9
Allow for setting a edit_cancel_redirect
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1017
diff
changeset
|
728 |
context['edit_cancel_redirect'] = params.get('edit_cancel_redirect') |
935
09f47e08f805
Adust the as_table tag to render a pick link if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents:
934
diff
changeset
|
729 |
context['return_url'] = request.path |
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
730 |
|
874
30e9629bf590
Fixed two trivial bugs
Sverre Rabbelier <srabbelier@gmail.com>
parents:
858
diff
changeset
|
731 |
if params.get('export_content_type') and entity: |
858
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
732 |
context['export_link'] = redirects.getExportRedirect(entity, params) |
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
733 |
|
576
6614d3f545b7
Fixed spurious 'Invite Host' button in 'create host'
Sverre Rabbelier <srabbelier@gmail.com>
parents:
573
diff
changeset
|
734 |
if entity: |
6614d3f545b7
Fixed spurious 'Invite Host' button in 'create host'
Sverre Rabbelier <srabbelier@gmail.com>
parents:
573
diff
changeset
|
735 |
template = params['edit_template'] |
6614d3f545b7
Fixed spurious 'Invite Host' button in 'create host'
Sverre Rabbelier <srabbelier@gmail.com>
parents:
573
diff
changeset
|
736 |
else: |
6614d3f545b7
Fixed spurious 'Invite Host' button in 'create host'
Sverre Rabbelier <srabbelier@gmail.com>
parents:
573
diff
changeset
|
737 |
template = params['create_template'] |
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
738 |
|
1269
62b1e9ee46c5
Add an _editContext hook
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1268
diff
changeset
|
739 |
self._editContext(request, context) |
399
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
740 |
return helper.responses.respond(request, template, context) |
b82852e6963e
Various improvements to the generic View code
Sverre Rabbelier <srabbelier@gmail.com>
parents:
389
diff
changeset
|
741 |
|
652
02323664d532
Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
651
diff
changeset
|
742 |
def getParams(self): |
668
77f9a6ea6e67
Some style and typo fixes in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
663
diff
changeset
|
743 |
"""Returns this view's params attribute. |
652
02323664d532
Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
651
diff
changeset
|
744 |
""" |
02323664d532
Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
651
diff
changeset
|
745 |
|
02323664d532
Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
651
diff
changeset
|
746 |
return self._params |
02323664d532
Cleanups in preparation of general selector view
Sverre Rabbelier <srabbelier@gmail.com>
parents:
651
diff
changeset
|
747 |
|
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
748 |
@decorators.merge_params |
1017
6ad4fdb48840
Cache access checks and disable sidebar caching
Sverre Rabbelier <srabbelier@gmail.com>
parents:
977
diff
changeset
|
749 |
def getSidebarMenus(self, id, user, params=None): |
499
d22e4fe8e64b
Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
497
diff
changeset
|
750 |
"""Returns an dictionary with one sidebar entry. |
493
6976c4d8d0ac
Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents:
492
diff
changeset
|
751 |
|
6976c4d8d0ac
Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents:
492
diff
changeset
|
752 |
Args: |
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
753 |
params: a dict with params for this View |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
754 |
|
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
755 |
Params usage: |
614
53a3e46fc512
Moved getSidebarLinks to sitemap.sidebar
Sverre Rabbelier <srabbelier@gmail.com>
parents:
613
diff
changeset
|
756 |
The params dictionary is passed as argument to getSidebarItems |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
632
diff
changeset
|
757 |
from the soc.views.sitemap.sidebar module, see the docstring |
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
632
diff
changeset
|
758 |
of _getSidebarItems on how it uses it. |
493
6976c4d8d0ac
Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents:
492
diff
changeset
|
759 |
""" |
6976c4d8d0ac
Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents:
492
diff
changeset
|
760 |
|
1017
6ad4fdb48840
Cache access checks and disable sidebar caching
Sverre Rabbelier <srabbelier@gmail.com>
parents:
977
diff
changeset
|
761 |
return sitemap.sidebar.getSidebarMenus(id, user, params=params) |
494
5e9c656a1b68
Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
493
diff
changeset
|
762 |
|
876
0c1329d4b514
Make use of the new decorators in all applicable views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
874
diff
changeset
|
763 |
@decorators.merge_params |
494
5e9c656a1b68
Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
493
diff
changeset
|
764 |
def getDjangoURLPatterns(self, params=None): |
614
53a3e46fc512
Moved getSidebarLinks to sitemap.sidebar
Sverre Rabbelier <srabbelier@gmail.com>
parents:
613
diff
changeset
|
765 |
"""Retrieves a list of sidebar entries for this view |
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
766 |
|
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
767 |
Params usage: |
614
53a3e46fc512
Moved getSidebarLinks to sitemap.sidebar
Sverre Rabbelier <srabbelier@gmail.com>
parents:
613
diff
changeset
|
768 |
The params dictionary is passed to the getDjangoURLPatterns |
639
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
632
diff
changeset
|
769 |
function in the soc.views.sitemap.sitemap module, see the |
1f92bd41b914
Some docstring fixes in few modules (soc.views.helper soc.views.models.base).
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
632
diff
changeset
|
770 |
docstring of getDjangoURLPatterns on how it uses it. |
610
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
771 |
|
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
772 |
Args: |
e0bd276ffd82
Documented params usage in soc/views/models/base.py
Sverre Rabbelier <srabbelier@gmail.com>
parents:
606
diff
changeset
|
773 |
params: a dict with params for this View |
494
5e9c656a1b68
Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
493
diff
changeset
|
774 |
""" |
5e9c656a1b68
Refactored SiteMap to be generic
Sverre Rabbelier <srabbelier@gmail.com>
parents:
493
diff
changeset
|
775 |
|
613
4880ffa9f3ba
Moved getDjangoURLPatterns to sitemap.sitemap
Sverre Rabbelier <srabbelier@gmail.com>
parents:
612
diff
changeset
|
776 |
return sitemap.sitemap.getDjangoURLPatterns(params) |
858
e79e7a22326f
Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents:
755
diff
changeset
|
777 |