Commit d1f81f33cb1a9ebb7e797d5a216ef85ad0e587e0

Added getBlockAsHtml method. Some fixes to getNotes method.
timApp/ephemeralclient.py
(15 / 0)
  
9494 return responseStr
9595
9696 @contract
97 def getBlockAsHtml(self, document_id : 'int', block_id : 'int') -> 'str':
98 """Gets an individual block from a document.
99
100 :param document_id: The id of the document.
101 :param block_id: The id of the block.
102 :returns: The content of the block.
103 """
104 req = urllib.request.Request(url=self.server_path + '/{}/{}/html'.format(document_id, block_id), method='GET')
105 response = urllib.request.urlopen(req)
106 responseStr = str(response.read(), encoding='utf-8')
107 if responseStr == '{"Error":"No block found"}':
108 raise EphemeralException('No block found with document id %d and index %d' % (document_id, block_id))
109 return responseStr
110
111 @contract
97112 def getDocumentAsHtmlBlocks(self, document_id: 'int') -> 'list(str)':
98113 """Gets the document as a list of HTML blocks.
99114
timApp/timdb/timdb2.py
(21 / 3)
  
136136 :param block_id: The id of the block whose notes will be fetched.
137137 """
138138 cursor = self.db.cursor()
139 cursor.execute("""select id, UserGroup_id from Block where id in
140 (select Block_id from BlockRelation where parent_block_id = ?) and type_id = ? and UserGroup_id in
139 cursor.execute("""select id, parent_block_specifier from Block,BlockRelation where
140 Block.id = BlockRelation.Block_id
141 and id in
142 (select Block_id from BlockRelation where parent_block_id = ?)
143 and type_id = ?
144 and UserGroup_id in
141145 (select UserGroup_id from UserGroupMember where User_id = ?)""", [document_id, blocktypes.NOTE, user_id])
142146 rows = [x for x in cursor.fetchall()]
143147
144148 notes = []
145149 for row in rows:
146150 note_id = row[0]
147 note = {'id' : note_id}
151 note = {'id' : note_id, 'specifier' : row[1]}
148152 with open(self.getBlockPath(note_id)) as f:
149153 note['content'] = f.read()
150154 notes.append(note)
380380 except EphemeralException as e:
381381 raise TimDbException(str(e))
382382 return block
383
384 def getBlockAsHtml(self, document_id : 'int', block_id : 'int') -> 'str':
385 """Gets a block of a document.
383386
387 :param document_id: The id of the document.
388 :param block_id: The id (index) of the block in the document.
389 """
390
391 ec = EphemeralClient(EPHEMERAL_URL)
392 try:
393 block = ec.getBlockAsHtml(document_id, block_id)
394 except EphemeralException as e:
395 raise TimDbException(str(e))
396 return block
397
384398 @contract
385399 def getDocumentBlocks(self, document_id : 'int') -> 'list(dict[2](str: str))':
386400 """Gets all the blocks of the specified document.