Implement fetchdddata view

This commit is contained in:
Jan Dittberner 2015-11-11 00:49:12 +01:00
parent 52066eb904
commit 1c86f707fa
2 changed files with 23 additions and 3 deletions

View file

@ -33,3 +33,7 @@ class DeveloperData(Form):
forumsid = IntegerField('forumsid', default=None, validators=[Optional()])
wikihomepage = StringField('wikihomepage', default=None, validators=[
Optional()])
class DeveloperDataRequest(Form):
email = StringField('email', validators=[DataRequired(), Email()])

View file

@ -1,7 +1,13 @@
import json
import logging
from debianmemberportfolio import app, babel
from flask import g, make_response, request, render_template
from flask import g, make_response, request, render_template, abort
from config import LANGUAGES
from .forms import DeveloperData
from .forms import DeveloperData, DeveloperDataRequest
from .model import dddatabuilder
log = logging.getLogger(__name__)
@babel.localeselector
@ -39,4 +45,14 @@ def formhelper_js():
@app.route('/showformscripts/fetchdddata/')
def fetchdddata():
return 'dddata'
form = DeveloperDataRequest(request.values)
if form.validate():
fields = dddatabuilder.build_data(form.data['email'])
log.debug(fields)
response = make_response(json.dumps(fields))
response.headers['Content-Type'] = 'application/json'
return response
abort(
400,
"\n".join(["%s: %s" % (key, form.errors[key]) for key in form.errors])
)