/
ajax.py
53 lines (47 loc) · 1.7 KB
/
ajax.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from google.appengine.api import memcache
import logging, web
import app.db.models as models
from google.appengine.ext import ereporter
import app.utility.utils as utils
from app.utility.utils import cachepage
ereporter.register_logger()
render = web.render
class Tags:
"""
Return tags for auto completion
"""
@cachepage()
def GET(self):
web.header('Content-type', 'text/plain')
try:
tag_filter = web.input()['q']
return models.Tag.get_tags_by_filter(tag_filter)
except Exception, exception:
return ""
class Markdown:
"""
Return markdown data for Markitup preview
"""
def POST(self):
data = web.input(data = None)['data']
return render.admin.markdown_preview(data)
class Links:
"""
Check if a given link is already stored
"""
def GET(self):
web.header('Content-type', 'application/json')
link = web.input(check = None)['check']
if link and utils.link_is_valid(link):
link_is_stored = models.Post.get_post_by_link(link.strip())
if not link_is_stored:
if link.strip().endswith('/'):
link_is_stored = models.Post.get_post_by_link(link.strip()[:-1]) #check without slash
else:
link_is_stored = models.Post.get_post_by_link("%s%s" % (link.strip(), '/')) #check with slash
if link_is_stored:
return '{"result":"[ The link is known ]","clazz":"message_KO"}'
else:
return '{"result":"[ This link looks new ]","clazz":"message_OK"}'
else:
return '{"result":"","clazz":""}'