Exemplo n.º 1
0
 def insertMessage(self, content, pid, gid):
     cursor = self.conn.cursor()
     query = "INSERT INTO messages (content, pid, gid) VALUES (%s, %s, %s)" \
             "RETURNING mid, date;"
     cursor.execute(query, (content, pid, gid))
     mid_date = cursor.fetchone()
     self.conn.commit()
     reaction_dao = ReactionDAO()
     hashtags = set(tag[1:] for tag in content.split()
                    if tag.startswith("#"))
     for tag in hashtags:
         hid = reaction_dao.getTagId(tag)
         if not hid:
             hid = reaction_dao.createHashtag(tag)
             reaction_dao.insertTag(mid_date[0], hid)
         else:
             reaction_dao.insertTag(mid_date[0], hid)
     return mid_date
Exemplo n.º 2
0
 def tagToMessage(self, form):
     """Add a hashtag on a specified message"""
     if len(form) != 2:
         return jsonify(Error="Malformed post request"), 400
     else:
         mid = form['mid']
         hid = form['hid']
         if hid and mid:
             dao = ReactionDAO()
             mid = dao.insertTag(mid, hid)
             result = self.map_message_tags_attributes(mid, hid)
             return jsonify(Hashtag=result), 201
         else:
             return jsonify(Error="Unexpected attributes in post request"), 400