A testing submit view that doesn't work but is getting closer to working.
This commit is contained in:
parent
6f86cfe95c
commit
ef7cdac5b9
@ -1,14 +1,11 @@
|
|||||||
|
{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %}
|
||||||
|
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<form action="{{ request.urlgen('test_submit') }}" method="POST"
|
<form action="{{ request.urlgen('test_submit') }}" method="POST"
|
||||||
enctype="multipart/form-data">
|
enctype="multipart/form-data">
|
||||||
<table>
|
<table>
|
||||||
{% for field in image_form %}
|
{{ wtforms_util.render_table(image_form) }}
|
||||||
<tr>
|
|
||||||
<td>{{ field.label }}</td>
|
|
||||||
<td>{{ field }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td><input type="submit" value="submit" /></td>
|
<td><input type="submit" value="submit" /></td>
|
||||||
|
18
mediagoblin/templates/mediagoblin/utils/wtforms.html
Normal file
18
mediagoblin/templates/mediagoblin/utils/wtforms.html
Normal file
@ -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 %}
|
@ -3,6 +3,8 @@ import datetime
|
|||||||
from webob import Response, exc
|
from webob import Response, exc
|
||||||
import wtforms
|
import wtforms
|
||||||
|
|
||||||
|
from mediagoblin import models
|
||||||
|
|
||||||
def root_view(request):
|
def root_view(request):
|
||||||
return Response("This is the root")
|
return Response("This is the root")
|
||||||
|
|
||||||
@ -19,13 +21,21 @@ def submit_test(request):
|
|||||||
image_form = ImageSubmitForm(request.POST)
|
image_form = ImageSubmitForm(request.POST)
|
||||||
if request.method == 'POST' and image_form.validate():
|
if request.method == 'POST' and image_form.validate():
|
||||||
# create entry and save in database
|
# create entry and save in database
|
||||||
work_id = request.app.db.works.insert(
|
|
||||||
{'title': image_form.title.data,
|
entry = request.db.MediaEntry()
|
||||||
'created': datetime.datetime.now(),
|
entry['title'] = request.POST['title']
|
||||||
'description': image_form.description.data})
|
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
|
# save file to disk
|
||||||
## TODO
|
## TODO
|
||||||
|
#open('/tmp/read_file.png', 'wb').write(request.POST['file'].file.read())
|
||||||
|
|
||||||
|
|
||||||
# resize if necessary
|
# resize if necessary
|
||||||
## Hm. This should be done on a separate view?
|
## Hm. This should be done on a separate view?
|
||||||
@ -33,6 +43,8 @@ def submit_test(request):
|
|||||||
# redirect
|
# redirect
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# render
|
# render
|
||||||
template = request.template_env.get_template(
|
template = request.template_env.get_template(
|
||||||
'mediagoblin/test_submit.html')
|
'mediagoblin/test_submit.html')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user