def post(self): template = dao.get_template_by_id(self.request.get(u'template_id')) if not dao.test_template_permissions( template, [dao.TEMPLATE_OWN, dao.TEMPLATE_EDIT]): webapp2.abort(401) document_entity = dao.get_document_by_id( template, self.request.get(u'document_id')) error_msg = None if document_entity else u'Unable to access specified document' # Handle delete request if document_entity and self.request.get(u'delete'): try: document_entity.key.delete() self.redirect("/template/document?template_id={}".format( template.key.id())) return except Exception as e: error_msg = u'Deleting document from template failed: {}'.format( e) # Handle update request if document_entity and self.request.get(u'update'): try: document_entity.description = self.request.get(u'description') document_entity.style_name = self.request.get(u'doc_style') document_entity.put() self.redirect("/template/document?template_id={}".format( template.key.id())) return except Exception as e: error_msg = u'Updating document failed: {}'.format(e) # Display the webpage self.render(template, document_entity, error_msg)
def get(self): template = dao.get_template_by_id(self.request.get(u'template_id')) if not dao.test_template_permissions(template, [dao.TEMPLATE_OWN, dao.TEMPLATE_EDIT]): webapp2.abort(401) document_entity = dao.get_document_by_id(template, self.request.get(u'document_id')) error_msg = None if document_entity else u'Unable to access specified document' # Display the webpage self.render(template, document_entity, error_msg)
def get(self): project = dao.get_project_by_id(self.request.get(u'project_id')) if not dao.test_project_permissions(project, [dao.PROJECT_OWN, dao.PROJECT_MANAGE]): webapp2.abort(401) document_entity = dao.get_document_by_id(project, self.request.get(u'document_id')) error_msg = None if document_entity else u'Unable to access specified document' # Display the webpage self.render(project, document_entity, error_msg)
def get(self): project = dao.get_project_by_id(self.request.get(u'project_id')) if not dao.test_project_permissions(project, []): webapp2.abort(401) document = dao.get_document_by_id(project, self.request.get(u'document_id')) html_document = self.generate_html_document(project, document) html_document = self.replace_image_elements(project, html_document) # Deliver HTTP response jinja_template = ui.get_template(self, u'project/produce_document.html') jinja_template_values = dao.get_standard_project_values(project) jinja_template_values[u'document'] = document jinja_template_values[u'html_document'] = html_document self.response.out.write(jinja_template.render(jinja_template_values))
def post(self): project = dao.get_project_by_id(self.request.get(u'project_id')) if not dao.test_project_permissions( project, [dao.PROJECT_OWN, dao.PROJECT_MANAGE]): webapp2.abort(401) document_entity = dao.get_document_by_id( project, self.request.get(u'document_id')) error_msg = None if document_entity else u'Unable to access specified document' # Handle delete request if document_entity and self.request.get(u'delete'): try: document_entity.key.delete() dao.touch_project_documents(project) self.redirect("/project/document?project_id={}".format( project.key.id())) return except Exception as e: error_msg = u'Deleting document from project failed: {}'.format( e) # Handle update request if document_entity and self.request.get(u'update'): try: document_entity.description = self.request.get(u'description') document_entity.style_name = self.request.get(u'doc_style') document_entity.put() dao.touch_project_documents(project) self.redirect("/project/document?project_id={}".format( project.key.id())) return except Exception as e: error_msg = u'Updating document failed: {}'.format(e) # Display the webpage self.render(project, document_entity, error_msg)
def post(self): template = dao.get_template_by_id(self.request.get(u'template_id')) if not dao.test_template_permissions(template, [dao.TEMPLATE_OWN, dao.TEMPLATE_EDIT]): webapp2.abort(401) document_entity = dao.get_document_by_id(template, self.request.get(u'document_id')) error_msg = None if document_entity else u'Unable to access specified document' if document_entity: # Handle add request item_type = None if self.request.get(u'add_text'): item_type = dao.TEXT elif self.request.get(u'add_single_variable'): item_type = dao.SINGLE_VARIABLE elif self.request.get(u'add_repeating_variable'): item_type = dao.REPEATING_VARIABLE if item_type: try: dao.DocumentItem(item_type=item_type, position=dao.get_document_item_count(document_entity) + 1, parent=document_entity.key).put() except Exception as e: error_msg = u'Adding document item failed: {}'.format(e) # Handle request items = [item for item in dao.get_document_items(document_entity)] # Update items for item in items: index = item.position - 1 if item.item_type == dao.SINGLE_VARIABLE: item.variable_name = self.request.get(u'single_name.{}'.format(index)) elif item.item_type == dao.REPEATING_VARIABLE: item.variable_name = self.request.get(u'repeating_name.{}'.format(index)) elif item.item_type == dao.TEXT: item.text = self.request.get(u'text.{}'.format(index)) item.style_name = self.request.get(u'style_name.{}'.format(index)) item.flow_control = self.request.get(u'flow_control.{}'.format(index)) try: item.put() except Exception as e: error_msg = u'Updating document failed: {}'.format(e) break for request in self.request.arguments(): # Handle change-position request change_position = change_pattern.match(request) if change_position: old_index = int(change_position.group(1)) new_position_string = None try: new_position_string = self.request.get(u'position.{}'.format(old_index)) new_position = int(new_position_string) except: error_msg = u'Invalid position specified: {}'.format(new_position_string) break if new_position < 1: new_position = 1 if new_position > len(items): new_position = len(items) new_index = new_position - 1 compressed_items = items[:old_index] + items[old_index + 1:] new_items = compressed_items[:new_index] new_items.append(items[old_index]) new_items += compressed_items[new_index:] self.compute_positions(new_items) # Handle remove request remove_position = remove_pattern.match(request) if remove_position: index = int(remove_position.group(1)) item = items[index] item.key.delete() new_items = items[:index] + items[index + 1:] self.compute_positions(new_items) if self.request.get(u'update') and not error_msg: self.redirect("/template/document?template_id={}".format(template.key.id())) return # Display the webpage self.render(template, document_entity, error_msg)