forked from Gig-o-Matic/GO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgigcomment.py
More file actions
52 lines (38 loc) · 1.32 KB
/
gigcomment.py
File metadata and controls
52 lines (38 loc) · 1.32 KB
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
"""
comment class for Gig-o-Matic 2
Aaron Oppenheimer
3 November 2013
"""
from google.appengine.api import search
def add_comment_for_gig(the_comment, the_comment_id=None):
""" if there's a comment document for a gig, add comment to it; if there isn't one, make one """
if the_comment_id:
the_comment_text=get_comment(the_comment_id)
the_comment_text = u'{0}\n-----\n'.format(the_comment_text)
else:
the_comment_text=""
the_comment_text = u'{0}{1}'.format(the_comment_text,the_comment)
# create a document
my_document = search.Document(
doc_id = the_comment_id,
fields=[
search.TextField(name='comment', value=the_comment_text),
search.TextField(name='type', value='comment')
])
try:
index = search.Index(name="gigomatic_index")
result = index.put(my_document)
except search.Error:
logging.exception('Put failed')
doc_id = result[0].id
return doc_id, the_comment_text
def get_comment(comment_id):
index = search.Index(name="gigomatic_index")
doc = index.get(comment_id)
if doc:
return doc.fields[0].value
else:
return ''
def delete_comment(comment_id):
index = search.Index(name="gigomatic_index")
index.delete([comment_id])