Adds and uses a modified_by property in models/work.py
authorLennard de Rijk <ljvderijk@gmail.com>
Mon, 24 Nov 2008 22:34:56 +0000
changeset 584 ba8a624506e5
parent 583 12960609a69c
child 585 903890857ed8
Adds and uses a modified_by property in models/work.py This property is used to display the user who last edited the work in the document viewer. Fixes author being set on every edit. Also edited the style-sheet to fix issue i128. Patch by: Lennard de Rijk
app/soc/content/css/soc-081111.css
app/soc/models/work.py
app/soc/templates/soc/document/public.html
app/soc/views/models/document.py
--- a/app/soc/content/css/soc-081111.css	Mon Nov 24 18:31:46 2008 +0000
+++ b/app/soc/content/css/soc-081111.css	Mon Nov 24 22:34:56 2008 +0000
@@ -276,7 +276,9 @@
 }
 
 #created {
-  font-size: small;
+  font-size: x-small;
+  color:#C0C0C0;
+  text-align: right;
 }
 
 /* SIDEBAR MENU */
--- a/app/soc/models/work.py	Mon Nov 24 18:31:46 2008 +0000
+++ b/app/soc/models/work.py	Mon Nov 24 22:34:56 2008 +0000
@@ -45,7 +45,7 @@
   #: Work (this relationship is needed to keep track of lifetime document
   #: creation limits, used to prevent spamming, etc.).
   author = db.ReferenceProperty(reference_class=soc.models.user.User,
-                                 required=True, collection_name="documents",
+                                 required=True, collection_name="created_documents",
                                  verbose_name=ugettext_lazy('Created by'))
 
   #: Required field indicating the "title" of the work, which may have
@@ -72,6 +72,11 @@
   
   #: date when the work was last modified
   modified = db.DateTimeProperty(auto_now=True)
+  
+  # indicating wich user last modified the work. Used in displaying Work
+  modified_by = db.ReferenceProperty(reference_class=soc.models.user.User,
+                                 required=True, collection_name="modified_documents",
+                                 verbose_name=ugettext_lazy('Modified by'))
 
   # TODO: some sort of access control preferences are needed at this basic
   #   level.  Works need to be restrict-able to:
--- a/app/soc/templates/soc/document/public.html	Mon Nov 24 18:31:46 2008 +0000
+++ b/app/soc/templates/soc/document/public.html	Mon Nov 24 22:34:56 2008 +0000
@@ -22,6 +22,6 @@
 {% endblock %}
 
 {% block body %}
-<div id="created">Created on {{ entity.created }} by {{ entity.author.name }}</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	Mon Nov 24 18:31:46 2008 +0000
+++ b/app/soc/views/models/document.py	Mon Nov 24 22:34:56 2008 +0000
@@ -52,7 +52,7 @@
     model = soc.models.document.Document
 
     #: list of model fields which will *not* be gathered by the form
-    exclude = ['author', 'created', 'modified', 'scope']
+    exclude = ['author', 'created', 'modified_by', 'modified', 'scope']
 
   def clean_scope_path(self):
     scope_path = self.cleaned_data.get('scope_path')
@@ -76,6 +76,8 @@
   doc_key_name = forms.fields.CharField(widget=forms.HiddenInput)
   created_by = forms.fields.CharField(widget=helper.widgets.ReadOnlyInput(),
                                       required=False)
+  last_modified_by = forms.fields.CharField(widget=helper.widgets.ReadOnlyInput(),
+                                      required=False)
 
 
 class View(base.View):
@@ -114,14 +116,19 @@
     account = users.get_current_user()
     user = soc.logic.models.user.logic.getForFields({'account': account},
                                                     unique=True)
-    fields['author'] = user
+    if not entity:
+      # new document so set author
+      fields['author'] = user
+    
+    fields['modified_by'] = user
 
   def _editGet(self, request, entity, form):
     """See base.View._editGet().
     """
-
-    form.fields['created_by'].initial = entity.author.link_id
-    form.fields['doc_key_name'].initial = entity.key().name(),
+    
+    form.fields['created_by'].initial = entity.author.name
+    form.fields['last_modified_by'].initial = entity.modified_by.name
+    form.fields['doc_key_name'].initial = entity.key().name()
 
 
 view = View()