Commits

Carsten Rebbien committed 9c2cbe4

added asset editing

Comments (0)

Files changed (8)

quantumbuster/assets/forms.py

 upload_form=UploadForm()
 
 
+edit_fields = [
+    String("title", description="Give your files a default title", size=80, required=True ),
+    Textarea("description", rows=10, cols=60, description="A default description for all files", size=80, required=False),
+    String("tags", description="Separate tags by commas or spaces.", size=80, required=False),
+]
+
+class EditForm(Form):
+    """ the edit form """
+    
+    fields = edit_fields
+    name = "edit_file_data" # name of form
+    action_url = "" # empty action -> submits to self
+    
+    @action("submit", label="Send")
+    def submit(self, params, **kw):
+        """submit the form"""
+        result = self.process(params)
+        if result.success:
+            # save data here somehow: result.data['firstname']...
+            import pdb;pdb.set_trace()
+            pass
+        return result
+
+
+        
+edit_form=EditForm()
+

quantumbuster/assets/main.py

 import forms
 import upload
 import pdf_view
+from quantumcore.formlib.context import FormContext
 
 class Application(object):
     """a WSGI based Asset Manager"""
         self.settings = setup(index_dir)
         self.pdf_view = pdf_view.PDFApplication(self.settings)
         self.upload_handler = upload.UploadHandler(self.settings)
+        self.edit_handler = upload.EditHandler(self.settings)
+        self.assetstore = self.settings['assetstore']
         
     def __call__(self, environ, start_response):
         settings = self.settings
             form = forms.upload_form()
             html = settings['templates']['templates/add.pt'](settings = settings, form=form)
             return webob.Response(html)(environ, start_response)
+        elif path[1]=="edit":
+            return self.edit_handler(environ, start_response)
         elif path[1]=="upload":
             self.upload_handler.upload(environ, start_response)
             return webob.Response("ok")(environ, start_response)
     wsgiref.simple_server.make_server('', port, app).serve_forever()
 
 if __name__=="__main__":
-    main()
-    
+    main()    

quantumbuster/assets/pdf_view.py

     
     def __init__(self, settings):
         self.settings = settings
-        self.coll = settings['comments_collection']
         self.upload_handler = upload.UploadHandler(self.settings)
         self.assetstore = settings['assetstore']
         
         """return a JSON response"""
         res = webob.Response(payload)
         return res(environ, start_response)
-        
+        

quantumbuster/assets/setup.py

 def setup(index_dir="indexdir"):
     
     settings = {}
-    assetdir = settings['assetdir'] = "/Users/cs/assets"
+    assetdir = settings['assetdir'] = "/home/cr/projects/assets"
     settings['staticapp'] = get_static_urlparser(resource_filename(__name__, 'static'))
     settings['assetapp'] = get_static_urlparser(assetdir)
     

quantumbuster/assets/templates/edit.pt

+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<metal:block use-macro="settings['master_template']">
+  <metal:content fill-slot="content">
+	  <h2>Edit File</h2> 
+	  <tal:block replace="structure form"></tal:block>
+  </metal:content>
+  <metal:sidebar fill-slot="sidebar">
+    hhu
+  </metal:sidebar>
+</metal:block>
+
+
+
+

quantumbuster/assets/templates/index.pt

       <div id="thumbs">
       <tal:block repeat="asset latest">
         <a class="noopener" id="o-${asset.get_id()}" href="/pdf/${asset.filename}"><img class="thumb" src="/assets/${asset.context.variants['squared']}" width="100" height="100" /></a>
+		<div class="button-edit"><a href="/edit/${asset.filename}">[ edit ]</a></div>
         <div tal:content="asset.context.mimetype" style="display:none"/>
           <div class="dialog" id="d-${asset.get_id()}" style="display:none">
             <div class="info-image">

quantumbuster/assets/upload.py

 
 import copy
 import werkzeug
+import webob
+from webob.exc import HTTPFound
 
+import forms
 import storage
 import converters
 
         return self.context._id
 
 
-class UploadHandler(object):
-    """the upload handler"""
-    
-    
+class AssetHandler(object):
+    """ asset handler base object """
+
     def __init__(self, settings):
         self.settings = settings
         self.filestore = settings['filestore']
             'parent' : None,
         }
         
+
+class UploadHandler(AssetHandler):
+    """the upload handler"""
+    
+    
+    def __init__(self, settings):
+        super(UploadHandler, self).__init__(settings)
         # initialize the dispatcher for creating asset variants
         self.dispatcher = converters.get_dispatcher(self.filestore, self.assetstore)
         
         print list(assets)
         return [AssetWrapper(asset) for asset in assets]
         
+        
+class EditHandler(AssetHandler):
+
+    def edit(self, environ, start_response):
+        request=werkzeug.Request(environ)
+        d = copy.copy(self.defaults)
+        d.update(dict(request.form))
+        
+        import pdb;pdb.set_trace()
+        asset = Asset(**d)
+        
+    def __call__(self, environ, start_response):
+        settings = self.settings
+        path = environ['PATH_INFO'].split("/")
+        filename = path[2]
+        assets = self.assetstore.find({'filename': filename})
+        defaults = {}
+        if assets:
+            asset = assets[0]
+            defaults = {'title' : asset.title,
+                        'description' : asset.description,
+                        'tags' : asset.tags}
+            request = webob.Request(environ)
+            form_context = forms.edit_form.process(defaults, request.params)
+            if form_context.success:
+                # save asset
+                for k,v in request.params.items():
+                    setattr(asset, k, v)
+                self.assetstore.update(asset)
+                return HTTPFound(location="/")(environ, start_response)
+        form = forms.edit_form(form_context)
+        html = settings['templates']['templates/edit.pt'](settings = settings, form=form)
+        return webob.Response(html)(environ, start_response)
+    
+        
           'quantumcore.storages',
           'quantumcore.formlib',
           'quantumcore.contenttypes',
+          'quantumcore.media',
           # -*- Extra requirements: -*-
       ],
       entry_points={