Add an export() view, and implement it as text/text for Document.
For every Model except Document, the public() view is displayed for any
attempts to access the export() view.
Currently, the permissions for export() are the same as for public(). This
seems reasonable for Document, since anyone could extract the raw HTML from
the page source anyway. The permissions should probably be different for
other types of exports, such as vCard or iCard exports of profiles, CSV
exports of lists, etc.
Patch by: Todd Larsen
Review by: to-be-reviewed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/document/export.html Wed Jan 21 00:27:39 2009 +0000
@@ -0,0 +1,14 @@
+{% comment %}
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+{{ entity.content|safe }}
--- a/app/soc/templates/soc/models/edit.html Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/templates/soc/models/edit.html Wed Jan 21 00:27:39 2009 +0000
@@ -55,6 +55,11 @@
<td>
<input type="button" onclick="location.href='/{{ entity_type_url|lower }}/delete/{{ entity_suffix }}'" value="Delete"/>
</td>
+{% if export_link %}
+ <td>
+ <input type="button" onclick="location.href='/{{ entity_type_url|lower }}/export/{{ entity_suffix }}'" value="Export"/>
+ </td>
+{% endif %}
{% endif %}
{% endblock %}
</tr>
--- a/app/soc/views/helper/params.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/helper/params.py Wed Jan 21 00:27:39 2009 +0000
@@ -121,6 +121,8 @@
new_params['django_patterns_defaults'] = [
(r'^%(url_name)s/(?P<access_type>show)/%(key_fields)s$',
'soc.views.models.%(module_name)s.public', 'Show %(name_short)s'),
+ (r'^%(url_name)s/(?P<access_type>export)/%(key_fields)s$',
+ 'soc.views.models.%(module_name)s.export', 'Show %(name_short)s'),
(r'^%(url_name)s/(?P<access_type>create)$',
'soc.views.models.%(module_name)s.create', 'Create %(name_short)s'),
(r'^%(url_name)s/(?P<access_type>create)/%(scope)s$',
@@ -139,13 +141,17 @@
'soc.views.models.%(module_name)s.create', 'Create %(name_short)s')]
new_params['public_template'] = 'soc/%(module_name)s/public.html' % params
+ new_params['export_template'] = 'soc/%(module_name)s/export.html' % params
new_params['create_template'] = 'soc/models/edit.html'
new_params['edit_template'] = 'soc/models/edit.html'
new_params['list_template'] = 'soc/models/list.html'
new_params['invite_template'] = 'soc/models/invite.html'
+ new_params['export_content_type'] = None
+
new_params['error_public'] = 'soc/%(module_name)s/error.html' % params
- new_params['error_edit'] = 'soc/%(module_name)s/error.html' % params
+ new_params['error_export'] = new_params['error_public']
+ new_params['error_edit'] = new_params['error_public']
new_params['list_main'] = 'soc/list/main.html'
new_params['list_pagination'] = 'soc/list/pagination.html'
--- a/app/soc/views/helper/redirects.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/helper/redirects.py Wed Jan 21 00:27:39 2009 +0000
@@ -56,6 +56,15 @@
return '/%s/show/%s' % (
params['url_name'], entity.key().name())
+
+
+def getExportRedirect(entity, params):
+ """Returns the export redirect for the specified entity.
+ """
+
+ return '/%s/export/%s' % (
+ params['url_name'], entity.key().name())
+
def getReviewRedirect(entity, params):
"""Returns the redirect to review the specified entity
--- a/app/soc/views/models/base.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/base.py Wed Jan 21 00:27:39 2009 +0000
@@ -32,6 +32,7 @@
from soc.views import out_of_band
from soc.views.helper import access
from soc.views.helper import forms
+from soc.views.helper import redirects
from soc.views import sitemap
import soc.logic
@@ -125,7 +126,72 @@
template = params['public_template']
- return helper.responses.respond(request, template, context)
+ return helper.responses.respond(request, template, context=context)
+
+ def export(self, request, access_type,
+ page_name=None, params=None, **kwargs):
+ """Displays the export page for the entity specified by **kwargs.
+
+ Params usage:
+ rights: The rights dictionary is used to check if the user has
+ the required rights to view the export page for this entity.
+ See checkAccess for more details on how the rights dictionary
+ is used to check access rights.
+ error_export: The error_export value is used as template when
+ the key values (as defined by the page's url) do not
+ correspond to an existing entity.
+ name: The name value is used to set the entity_type in the
+ context so that the template can refer to it.
+ export_template: The export_template value is used as template
+ to display the export page of the found entity.
+ export_content_type: The export_content_type value is used to set
+ the Content-Type header of the HTTP response. If empty (or None),
+ public() is called instead.
+
+ Args:
+ request: the standard Django HTTP request object
+ page_name: the page name displayed in templates as page and header title
+ params: a dict with params for this View
+ kwargs: the Key Fields for the specified entity
+ """
+ params = dicts.merge(params, self._params)
+
+ if not params.get('export_content_type'):
+ return self.public(request, access_type, page_name=page_name,
+ params=params, kwargs=kwargs)
+
+ try:
+ access.checkAccess(access_type, request, rights=params['rights'])
+ except out_of_band.Error, error:
+ return helper.responses.errorResponse(error, request)
+
+ # create default template context for use with any templates
+ context = helper.responses.getUniversalContext(request)
+ context['page_name'] = page_name
+ entity = None
+
+ if not all(kwargs.values()):
+ #TODO: Change this into a proper redirect
+ return http.HttpResponseRedirect('/')
+
+ try:
+ key_fields = self._logic.getKeyFieldsFromDict(kwargs)
+ entity = self._logic.getIfFields(key_fields)
+ except out_of_band.Error, error:
+ return helper.responses.errorResponse(
+ error, request, template=params['error_export'], context=context)
+
+ self._export(request, entity, context)
+
+ context['entity'] = entity
+ context['entity_type'] = params['name']
+
+ template = params['export_template']
+
+ response_args = {'mimetype': params['export_content_type']}
+
+ return helper.responses.respond(request, template, context=context,
+ response_args=response_args)
def create(self, request, access_type,
page_name=None, params=None, **kwargs):
@@ -521,14 +587,23 @@
fields['scope'] = scope
def _public(self, request, entity, context):
- """Performs any required processing to get an entities public page.
+ """Performs any required processing to get an entity' public page.
Args:
request: the django request object
entity: the entity to make public
context: the context object
"""
+ pass
+ def _export(self, request, entity, context):
+ """Performs any required processing to get an entity's export page.
+
+ Args:
+ request: the django request object
+ entity: the entity to export
+ context: the context object
+ """
pass
def _editGet(self, request, entity, form):
@@ -587,6 +662,9 @@
context['entity_type_short'] = params['name_short']
context['entity_type_url'] = params['url_name']
+ if params.get('export_content_type'):
+ context['export_link'] = redirects.getExportRedirect(entity, params)
+
if entity:
template = params['edit_template']
else:
@@ -630,3 +708,4 @@
params = dicts.merge(params, self._params)
return sitemap.sitemap.getDjangoURLPatterns(params)
+
--- a/app/soc/views/models/club.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/club.py Wed Jan 21 00:27:39 2009 +0000
@@ -121,3 +121,5 @@
edit = view.edit
list = view.list
public = view.public
+export = view.export
+
--- a/app/soc/views/models/club_admin.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/club_admin.py Wed Jan 21 00:27:39 2009 +0000
@@ -68,3 +68,5 @@
edit = view.edit
list = view.list
public = view.public
+export = view.export
+
--- a/app/soc/views/models/club_app.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/club_app.py Wed Jan 21 00:27:39 2009 +0000
@@ -335,5 +335,7 @@
edit = view.edit
list = view.list
public = view.public
+export = view.export
review = view.review
showReviewOverview = view.showReviewOverview
+
--- a/app/soc/views/models/document.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/document.py Wed Jan 21 00:27:39 2009 +0000
@@ -104,6 +104,8 @@
new_params['logic'] = soc.logic.models.document.logic
new_params['rights'] = rights
+ new_params['export_content_type'] = 'text/text'
+
new_params['name'] = "Document"
new_params['edit_form'] = EditForm
@@ -170,6 +172,7 @@
return submenus
+
view = View()
create = view.create
@@ -177,3 +180,5 @@
delete = view.delete
list = view.list
public = view.public
+export = view.export
+
--- a/app/soc/views/models/group.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/group.py Wed Jan 21 00:27:39 2009 +0000
@@ -85,3 +85,4 @@
fields['founder'] = user
super(View, self)._editPost(request, entity, fields)
+
--- a/app/soc/views/models/group_app.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/group_app.py Wed Jan 21 00:27:39 2009 +0000
@@ -52,3 +52,4 @@
params = dicts.merge(params, new_params)
super(View, self).__init__(params=params)
+
--- a/app/soc/views/models/host.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/host.py Wed Jan 21 00:27:39 2009 +0000
@@ -152,4 +152,6 @@
edit = view.edit
list = view.list
public = view.public
+export = view.export
invite = view.invite
+
--- a/app/soc/views/models/notification.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/notification.py Wed Jan 21 00:27:39 2009 +0000
@@ -210,3 +210,5 @@
delete = view.delete
list = view.list
public = view.public
+export = view.export
+
--- a/app/soc/views/models/organization.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/organization.py Wed Jan 21 00:27:39 2009 +0000
@@ -73,3 +73,5 @@
edit = view.edit
list = view.list
public = view.public
+export = view.export
+
--- a/app/soc/views/models/presence.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/presence.py Wed Jan 21 00:27:39 2009 +0000
@@ -214,4 +214,5 @@
delete = view.delete
list = view.list
public = view.public
+export = view.export
--- a/app/soc/views/models/program.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/program.py Wed Jan 21 00:27:39 2009 +0000
@@ -154,3 +154,5 @@
edit = view.edit
list = view.list
public = view.public
+export = view.export
+
--- a/app/soc/views/models/request.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/request.py Wed Jan 21 00:27:39 2009 +0000
@@ -218,3 +218,5 @@
list = view.list
list_self = view.listSelf
public = view.public
+export = view.export
+
--- a/app/soc/views/models/role.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/role.py Wed Jan 21 00:27:39 2009 +0000
@@ -120,3 +120,4 @@
contents = [content]
return self._list(request, params, contents, page_name)
+
--- a/app/soc/views/models/site.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/site.py Wed Jan 21 00:27:39 2009 +0000
@@ -175,5 +175,7 @@
delete = view.delete
list = view.list
public = view.public
+export = view.export
main_public = view.mainPublic
main_edit = view.mainEdit
+
--- a/app/soc/views/models/sponsor.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/sponsor.py Wed Jan 21 00:27:39 2009 +0000
@@ -62,3 +62,5 @@
edit = view.edit
list = view.list
public = view.public
+export = view.export
+
--- a/app/soc/views/models/timeline.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/timeline.py Wed Jan 21 00:27:39 2009 +0000
@@ -110,3 +110,5 @@
edit = view.edit
list = view.list
public = view.public
+export = view.export
+
--- a/app/soc/views/models/user.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/user.py Wed Jan 21 00:27:39 2009 +0000
@@ -184,3 +184,5 @@
edit = view.edit
list = view.list
public = view.public
+export = view.export
+
--- a/app/soc/views/models/user_self.py Tue Jan 20 23:13:03 2009 +0000
+++ b/app/soc/views/models/user_self.py Wed Jan 21 00:27:39 2009 +0000
@@ -280,3 +280,5 @@
view = View()
edit = view.edit
+export = view.export
+