allow editing of track data in management interface
This commit is contained in:
		
							parent
							
								
									ed996977f9
								
							
						
					
					
						commit
						17af65c461
					
				
					 3 changed files with 108 additions and 0 deletions
				
			
		|  | @ -21,9 +21,11 @@ View classes for tracks. | ||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
| from zope import component | from zope import component | ||||||
|  | from zope.app.pagetemplate import ViewPageTemplateFile | ||||||
| from zope.app.security.interfaces import IAuthentication, PrincipalLookupError | from zope.app.security.interfaces import IAuthentication, PrincipalLookupError | ||||||
| from zope.cachedescriptors.property import Lazy | from zope.cachedescriptors.property import Lazy | ||||||
| from zope.app.pagetemplate import ViewPageTemplateFile | from zope.app.pagetemplate import ViewPageTemplateFile | ||||||
|  | from zope.security.proxy import removeSecurityProxy | ||||||
| from zope.traversing.browser import absoluteURL | from zope.traversing.browser import absoluteURL | ||||||
| from zope.traversing.api import getName | from zope.traversing.api import getName | ||||||
| 
 | 
 | ||||||
|  | @ -34,6 +36,8 @@ from loops.browser.form import ObjectForm, EditObject | ||||||
| from loops.organize.party import getPersonForUser | from loops.organize.party import getPersonForUser | ||||||
| from loops import util | from loops import util | ||||||
| 
 | 
 | ||||||
|  | track_edit_template = ViewPageTemplateFile('edit_track.pt') | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| class BaseTrackView(TrackView): | class BaseTrackView(TrackView): | ||||||
| 
 | 
 | ||||||
|  | @ -102,6 +106,30 @@ class BaseTrackView(TrackView): | ||||||
|         return self.request.principal.id |         return self.request.principal.id | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | class EditForm(BaseTrackView): | ||||||
|  | 
 | ||||||
|  |     template = track_edit_template | ||||||
|  | 
 | ||||||
|  |     def update(self): | ||||||
|  |         form = self.request.form | ||||||
|  |         if not form.get('form_submitted'): | ||||||
|  |             return True | ||||||
|  |         data = {} | ||||||
|  |         print '*** update', form | ||||||
|  |         for row in form.get('data') or []: | ||||||
|  |             key = row['key'] | ||||||
|  |             if not key: | ||||||
|  |                 continue | ||||||
|  |             value = row['value'] | ||||||
|  |             # TODO: unmarshall value if necessary | ||||||
|  |             data[key] = value | ||||||
|  |         context = removeSecurityProxy(self.context) | ||||||
|  |         context.data = data | ||||||
|  |         return True | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | # specialized views | ||||||
|  | 
 | ||||||
| class ChangeView(BaseTrackView): | class ChangeView(BaseTrackView): | ||||||
| 
 | 
 | ||||||
|     pass |     pass | ||||||
|  |  | ||||||
|  | @ -82,6 +82,13 @@ | ||||||
|       class="loops.organize.tracking.browser.ChangeView" |       class="loops.organize.tracking.browser.ChangeView" | ||||||
|       permission="zope.View" /> |       permission="zope.View" /> | ||||||
| 
 | 
 | ||||||
|  |   <browser:page | ||||||
|  |       name="edit.html" | ||||||
|  |       for="cybertools.tracking.interfaces.ITrack" | ||||||
|  |       class="loops.organize.tracking.browser.EditForm" | ||||||
|  |       permission="loops.ManageSite" | ||||||
|  |       menu="zmi_views" title="Edit" /> | ||||||
|  | 
 | ||||||
|   <browser:page |   <browser:page | ||||||
|       for="loops.organize.tracking.access.IAccessRecord" |       for="loops.organize.tracking.access.IAccessRecord" | ||||||
|       name="index.html" |       name="index.html" | ||||||
|  |  | ||||||
							
								
								
									
										73
									
								
								organize/tracking/edit_track.pt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								organize/tracking/edit_track.pt
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,73 @@ | ||||||
|  | <tal:tag condition="view/update"> | ||||||
|  | <html metal:use-macro="context/@@standard_macros/view" | ||||||
|  |       i18n:domain="loops"> | ||||||
|  | <body> | ||||||
|  | 
 | ||||||
|  | <div metal:fill-slot="body"> | ||||||
|  |   <form action="." tal:attributes="action request/URL" method="post"> | ||||||
|  |     <input type="hidden" name="form_submitted" value="true" /> | ||||||
|  |     <h1>Edit Track <span tal:content="view/id" /></h1> | ||||||
|  |     <div class="row"> | ||||||
|  |       <table> | ||||||
|  |         <tr> | ||||||
|  |           <td>Task:</td> | ||||||
|  |           <td><a tal:omit-tag="not:view/taskUrl" | ||||||
|  |                  tal:attributes="href view/taskUrl" | ||||||
|  |                  tal:content="view/taskTitle" /></td></tr> | ||||||
|  |         <tr> | ||||||
|  |           <td>Run:</td> | ||||||
|  |           <td tal:content="view/run"></td></tr> | ||||||
|  |         <tr> | ||||||
|  |           <td>User:</td> | ||||||
|  |           <td><a tal:define="userUrl view/userUrl|nothing" | ||||||
|  |                  tal:omit-tag="not:userUrl" | ||||||
|  |                  tal:attributes="href userUrl" | ||||||
|  |                  tal:content="view/userTitle" /></td></tr> | ||||||
|  |         <tr> | ||||||
|  |           <td>Timestamp:</td> | ||||||
|  |           <td tal:content="view/timeStamp"></td></tr> | ||||||
|  |         <tr tal:repeat="key view/additionalMetadataFields"> | ||||||
|  |           <td><span tal:replace="key" />:</td> | ||||||
|  |           <td><a tal:define="target python: view.getMetadataTarget(key)" | ||||||
|  |                  tal:omit-tag="not:target/url" | ||||||
|  |                  tal:attributes="href target/url" | ||||||
|  |                  tal:content="python: target['title'] or '???'" /></td></tr> | ||||||
|  |       </table> | ||||||
|  |     </div> | ||||||
|  |     <h2>Data</h2> | ||||||
|  |     <div class="row"> | ||||||
|  |       <table width="100%"> | ||||||
|  |         <tr> | ||||||
|  |           <th>Key</th> | ||||||
|  |           <th>Value</th> | ||||||
|  |         </tr> | ||||||
|  |         <tr tal:repeat="row python:sorted(context.data.items())"> | ||||||
|  |           <td> | ||||||
|  |             <input name="data.key:records" | ||||||
|  |                    tal:attributes="value python:row[0]" /></td> | ||||||
|  |           <td style="width: 100%"> | ||||||
|  |             <input name="data.value:records" | ||||||
|  |                    style="width: 100%" | ||||||
|  |                    tal:attributes="value python:row[1]" /></td> | ||||||
|  |         </tr> | ||||||
|  |         <tr> | ||||||
|  |           <td> | ||||||
|  |             <input name="data.key:records" /></td> | ||||||
|  |           <td style="width: 100%"> | ||||||
|  |             <input name="data.value:records" | ||||||
|  |                    style="width: 100%" /></td> | ||||||
|  |         </tr> | ||||||
|  |       </table> | ||||||
|  |       <div class="row"> | ||||||
|  |         <div class="controls"> | ||||||
|  |           <input type="submit" name="UPDATE_SUBMIT" value="Change" | ||||||
|  |                  i18n:attributes="value submit-button;" /> | ||||||
|  |         </div> | ||||||
|  |       </div> | ||||||
|  |     </div> | ||||||
|  |   </form> | ||||||
|  | </div> | ||||||
|  | 
 | ||||||
|  | </body> | ||||||
|  | </html> | ||||||
|  | </tal:tag> | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue