summaryrefslogtreecommitdiff
path: root/extras/appengine
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2009-04-30 06:21:23 +0200
committerAndi Albrecht <albrecht.andi@gmail.com>2009-04-30 06:21:23 +0200
commit7670fc3c2304a4b569a42ef13892eea65aac0e21 (patch)
treeda63b5fbeddb8b1518d69da07880cfff8d6247b6 /extras/appengine
parent1fd167879df0a65ec2cc2bcf023ca3b45cff8d9c (diff)
downloadsqlparse-7670fc3c2304a4b569a42ef13892eea65aac0e21.tar.gz
* Provide better error message when example client fails.
* Allow empty output_format setting and use 'sql' then.
Diffstat (limited to 'extras/appengine')
-rw-r--r--extras/appengine/sqlformat/views.py13
-rw-r--r--extras/appengine/static/sqlformat_client_example.py5
2 files changed, 16 insertions, 2 deletions
diff --git a/extras/appengine/sqlformat/views.py b/extras/appengine/sqlformat/views.py
index d135c44..d8799c0 100644
--- a/extras/appengine/sqlformat/views.py
+++ b/extras/appengine/sqlformat/views.py
@@ -3,6 +3,7 @@
import logging
import md5
import os
+import sys
import time
from django import forms
@@ -92,6 +93,12 @@ class FormOptions(forms.Form):
raise forms.ValidationError('Whoops, I need a file OR text!')
return self.cleaned_data
+ def clean_output_format(self):
+ frmt = self.cleaned_data.get('output_format')
+ if not frmt:
+ frmt = 'sql'
+ return frmt.lower()
+
def get_data(self):
data = self.cleaned_data.get('data')
if self._datafile:
@@ -176,7 +183,11 @@ def format(request):
if request.method == 'POST':
form = FormOptions(request.POST)
if form.is_valid():
- response = format_sql(form, format='text')
+ try:
+ response = format_sql(form, format='text')
+ except:
+ err = sys.exc_info()[1]
+ response = 'ERROR: Parsing failed. %s' % str(err)
else:
response = 'ERROR: %s' % str(form.errors)
else:
diff --git a/extras/appengine/static/sqlformat_client_example.py b/extras/appengine/static/sqlformat_client_example.py
index 3b3bf0f..e4d1606 100644
--- a/extras/appengine/static/sqlformat_client_example.py
+++ b/extras/appengine/static/sqlformat_client_example.py
@@ -3,6 +3,9 @@
import urllib
import urllib2
+REMOTE_API = 'http://sqlformat.appspot.com/format/'
+REMOTE_API = 'http://127.0.0.1:8080/format/'
+
payload = (
('data', 'select * from foo join bar on val1 = val2 where id = 123;'),
('format', 'text'),
@@ -11,7 +14,7 @@ payload = (
('n_indents', 2),
)
-response = urllib2.urlopen('http://sqlformat.appspot.com/format/',
+response = urllib2.urlopen(REMOTE_API,
urllib.urlencode(payload))
print response.read()