A testing submit view that doesn't work but is getting closer to working.
authorChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 27 Mar 2011 22:32:27 +0000 (17:32 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 27 Mar 2011 22:32:27 +0000 (17:32 -0500)
mediagoblin/templates/mediagoblin/test_submit.html
mediagoblin/templates/mediagoblin/utils/wtforms.html [new file with mode: 0644]
mediagoblin/views.py

index bf91d26b5ce656ec223598932be4b95cecee6d0e..2fae634c28d49d18bbb0989eee23e0b596e4279c 100644 (file)
@@ -1,14 +1,11 @@
+{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %}
+
 <html>
   <body>
     <form action="{{ request.urlgen('test_submit') }}" method="POST"
           enctype="multipart/form-data">
       <table>
-        {% for field in image_form %}
-          <tr>
-            <td>{{ field.label }}</td>
-            <td>{{ field }}</td>
-          </tr>
-        {% endfor %}
+        {{ wtforms_util.render_table(image_form) }}
         <tr>
           <td></td>
           <td><input type="submit" value="submit" /></td>
diff --git a/mediagoblin/templates/mediagoblin/utils/wtforms.html b/mediagoblin/templates/mediagoblin/utils/wtforms.html
new file mode 100644 (file)
index 0000000..641f51d
--- /dev/null
@@ -0,0 +1,18 @@
+{% macro render_table(form) -%}
+  {% for field in form %}
+    <tr>
+      <th>{{field.label}}</th>
+      <td>
+        {{field}}
+        {% if field.errors %}
+          <br />
+          <ul class="errors">
+            {% for error in field.errors %}
+              <li>{{error}}</li>
+            {% endfor %}
+          </ul>
+        {% endif %}
+      </td>
+    </tr>
+  {% endfor %}
+{%- endmacro %}
index 116237b788923aa9ec9bb76e83303b6649af8f26..eca40203e672b8f10ddde7af07d9699b3944f743 100644 (file)
@@ -3,6 +3,8 @@ import datetime
 from webob import Response, exc
 import wtforms
 
+from mediagoblin import models
+
 def root_view(request):
     return Response("This is the root")
 
@@ -19,13 +21,21 @@ def submit_test(request):
     image_form = ImageSubmitForm(request.POST)
     if request.method == 'POST' and image_form.validate():
         # create entry and save in database
-        work_id = request.app.db.works.insert(
-            {'title': image_form.title.data,
-             'created': datetime.datetime.now(),
-             'description': image_form.description.data})
+
+        entry = request.db.MediaEntry()
+        entry['title'] = request.POST['title']
+        entry['description'] = request.POST.get(['description'])o
+        entry['media_type'] = u'image'
+
+        # TODO this does NOT look save, we should clean the filename somenow?
+        entry['file_store'] = request.POST['file'].filename
+
+        entry.save(validate=True)
 
         # save file to disk
         ## TODO
+        #open('/tmp/read_file.png', 'wb').write(request.POST['file'].file.read())
+
 
         # resize if necessary
         ## Hm.  This should be done on a separate view?
@@ -33,6 +43,8 @@ def submit_test(request):
         # redirect
         pass
 
+
+
     # render
     template = request.template_env.get_template(
         'mediagoblin/test_submit.html')