Added link to edit the Document on the Document's public page.
authorLennard de Rijk <ljvderijk@gmail.com>
Thu, 04 Jun 2009 20:21:15 +0200
changeset 2382 3a6302dd346b
parent 2380 f23025455742
child 2384 71780864a5ed
Added link to edit the Document on the Document's public page. This link will only show if the user is allowed to edit the document. Fixes issue 271. Update issue 271 Owner: ljvderijk
app/soc/templates/soc/document/public.html
app/soc/views/models/document.py
--- a/app/soc/templates/soc/document/public.html	Thu Jun 04 18:21:04 2009 +0200
+++ b/app/soc/templates/soc/document/public.html	Thu Jun 04 20:21:15 2009 +0200
@@ -14,14 +14,17 @@
 {% endcomment %}
 
 {% block page_title %}
-{{ entity.title }}
+	{{ entity.title }}
 {% endblock %}
 
 {% block header_title %}
-{{ entity.title }}
+	{{ entity.title }}
+	{% if edit_redirect %}
+		<a href={{ edit_redirect }}> (Edit this {{entity_type}})</a>
+	{% endif %}
 {% endblock %}
 
 {% block body %}
-<div id="created">Last modified on {{ entity.modified }} by {{ entity.modified_by.name }}</div>
-<div id="content">{{ entity.content|safe }}</div>
+	<div id="created">Last modified on {{ entity.modified }} by {{ entity.modified_by.name }}</div>
+	<div id="content">{{ entity.content|safe }}</div>
 {% endblock %}
--- a/app/soc/views/models/document.py	Thu Jun 04 18:21:04 2009 +0200
+++ b/app/soc/views/models/document.py	Thu Jun 04 20:21:15 2009 +0200
@@ -123,6 +123,30 @@
     return super(View, self).list(request, access_type, page_name=page_name,
                                   params=params, filter=kwargs)
 
+  def _public(self, request, entity, context):
+    """Performs any processing needed for the Document's public page.
+
+    For args see base.View._public().
+    """
+
+    # check if the current user is allowed to visit the edit page
+    rights = self._params['rights']
+
+    allowed_to_edit = False
+    try:
+      # use the IsDocumentWritable check because we have no django args
+      rights.checkIsDocumentWritable({'key_name': entity.key().name()},
+                                     'key_name')
+      allowed_to_edit = True
+    except:
+      pass
+
+    if allowed_to_edit:
+      context['edit_redirect'] = redirects.getEditRedirect(
+          entity, {'url_name': 'document'})
+
+    return super(View, self)._public(request, entity, context)
+
   def _editPost(self, request, entity, fields):
     """See base.View._editPost().
     """