Commit 5b3a64ab authored by Duc Anh Tran's avatar Duc Anh Tran Committed by GitHub

modify modelconverter to support GeoPtProperty of appengine

parent 7d05926b
from wtforms.fields import TextField
from google.appengine.ext import ndb
import decimal
class GeoPtPropertyField(TextField):
def process_formdata(self, valuelist):
if valuelist:
try:
lat, lon = valuelist[0].split(',')
self.data = ndb.GeoPt(
decimal.Decimal(lat.strip()),
decimal.Decimal(lon.strip())
)
except (decimal.InvalidOperation, ValueError):
raise ValueError('Not a valid coordinate location')
from wtforms_appengine.ndb import ModelConverter
from .fields import GeoPtPropertyField
from flask_admin.model.form import converts
class AdminModelConverter(ModelConverter):
@converts('GeoPt')
def convert_GeoPtProperty(self, model, prop, kwargs):
"""Returns a form field for a ``ndb.GeoPtProperty``."""
return GeoPtPropertyField(**kwargs)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment