Skip to content
Newer
Older
100644 59 lines (49 sloc) 2.06 KB
2523fce @dezza initial commit
authored
1 import re
2 import web
3
4 #db = web.database(dbn='mysql', db='bb', user='root', pw='pass')
5 import config # ^ this is
6
7 def getTopics(fid):
8 return db.select('topics', order='id', where='fid='+str(fid))
9
10 def getTopic(s, tid):
11 return db.where('topics', slug=s, id=tid)
12
13 def getPosts(tid):
14 return db.where('posts', order='id', tid=str(tid))
15
16 def addTopic(t, b):
17 tt = t
18 t = t.lower()
19 t = re.sub('[\s]+', '-', t)
20 t = re.sub(r'[^a-z0-9-]', '', t)
21 result = db.insert('topics', uid=1, title=tt, date=1, fid=0, slug=t, replies=0)
22 if(result):
23 db.update('topics', where='id=%s' % result, last_poster='%s' % 'johndoe')
24 return db.insert('posts', uid=1, body=b, date=1, tid=result)
25 else:
26 return 'error'
27 # SLUG TODO
28 #import re
29 #topic = topic.lower()
30 #topic = re.sub('[\s]+', '-', topic)
31 #topic = re.sub(r'[^a-z0-9-]', '', topic)
32 # return 'slug'
33 # db.insert(topics, uid=1,title=t, body=b, date=1, fid=0, slug=#TODO)
34
35 def addReply(id, reply, userid):
36 # TODO LASTPOST
37 # db.query('UPDATE LASTPOST ?
38 # db.update ?
39 replies_update = db.query('UPDATE topics SET replies=replies+1 WHERE id=%s' % id)
40 post = db.insert('posts', uid=userid, body=reply, tid=id)
41 last_poster = db.update('topics', where='id=%s' % id, last_poster='%s' % 'johndoe')
42 return db.update('topics', where='id=%s' % id, last_post='%s' % post)
43 #last_post_update = db.update('topics', where='id=%s' % id, last_post='%s' % reply)
44 # last_post_update = db.query('UPDATE topics SET last_post=%s WHERE id=%s') % reply, id
45 # return db.query('UPDATE topics SET last_post=%s' % reply)
46
47 # return db.insert('posts', uid=userid, body=reply, tid=id)
48
49 # pid = postid, tid = topic-id
50 def delPost(pid, tid):
51 replies_update = db.query('UPDATE topics SET replies=replies-1 WHERE id=%s' % tid)
52 return db.delete('posts', where='id=%s' % pid)
53
54 def search(query):
55 # match against
56 a = db.query('SELECT title FROM topics WHERE MATCH(title) AGAINST (\'*%s*\' IN BOOLEAN MODE)' % query)
57 #b = db.query('SELECT body FROM posts WHERE MATCH(body) AGAINST (\'*%s*\' IN BOOLEAN MODE)' % query)
58 return a
Something went wrong with that request. Please try again.