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) error_msg = None # Handle contribute request if self.request.get(u'contribute'): try: name = self.request.get(u'name').strip() if not name: raise Exception( u'You must provide a name for the public template') if dao.get_public_template_by_name(name): raise Exception(u'Sorry, that name is taken') new_template = dao.Project( name=name, project_type=dao.PUBLIC_TEMPLATE, status=dao.STATUS_PENDING, description=self.request.get(u'description')) new_template.put() for assignment_entity in dao.get_assignments(template): assignment_entity.clone(new_template).put() for document_entity in dao.get_documents(template): template_document_entity = document_entity.clone( new_template) template_document_entity.put() for document_item_entity in dao.get_document_items( document_entity): document_item_entity.clone( template_document_entity).put() for interview_entity in dao.get_interviews(template): cloned_interview_entity = interview_entity.clone( new_template) cloned_interview_entity.put() for style_entity in dao.get_styles(template): style_entity.clone(new_template).put() for variable_entity in dao.get_variables(template): variable_entity.clone(new_template).put() self.redirect("/template?template_id={}".format( template.key.id())) return except Exception as e: error_msg = u'Contributing project failed: {}'.format(e) # Display the webpage self.render(template, error_msg)
def get_documents(self, template, variable): documents = u'' variable_name = variable["name"] for document in dao.get_documents(template): for document_item in dao.get_document_items(document): if document_item.variable_name == variable_name: if len(documents): documents += u', ' documents += u'<a href="/template/document/structure?template_id={}&document_id={}">{}</a>'.format( template.key.id(), document.key.id(), document.name) return documents
def get_documents(self, project, variable): documents = u'' variable_name = variable["name"] for document in dao.get_documents(project): for document_item in dao.get_document_items(document): if document_item.variable_name == variable_name: if len(documents): documents += u', ' documents += u'<a href="/project/document/structure?project_id={}&document_id={}">{}</a>'.format( project.key.id(), document.key.id(), document.name) return documents
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_list = list() for document_entity in dao.get_documents(template): document = dict() document[u'id'] = document_entity.key.id() document[u'name'] = document_entity.name document[u'description'] = document_entity.description document[u'style'] = document_entity.style_name document_list.append(document) # Create template and template values, render the page jinja_template = ui.get_template(self, u'template/document/index.html') jinja_template_values = dao.get_standard_template_values(template) jinja_template_values[u'documents'] = document_list self.response.out.write(jinja_template.render(jinja_template_values))
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_list = list() for document_entity in dao.get_documents(project): document = dict() document[u'id'] = document_entity.key.id() document[u'key'] = document_entity.key document[u'name'] = document_entity.name document[u'description'] = document_entity.description document[u'style'] = document_entity.style_name document_list.append(document) # Create template and template values, render the page jinja_template = ui.get_template(self, u'project/document/index.html') jinja_template_values = dao.get_standard_project_values(project) jinja_template_values[u'documents'] = document_list self.response.out.write(jinja_template.render(jinja_template_values))
def post(self): if not dao.test_current_user_registered(): webapp2.abort(401) current_user = users.get_current_user() current_email = current_user.email().lower() # Attempt to create a new project try: name = self.request.get(u'name').strip() if not name: raise Exception(u'You must provide a name for your project') for project in dao.get_projects_by_name(name): if dao.test_email_is_project_owner(project, current_email): raise Exception( u'Sorry, you already own a project by that name') # Create the new Project entity project = dao.Project(name=name, project_type=dao.PROJECT, description=self.request.get(u'description')) project_key = project.put() # Create a ProjectUser entity, making the current user owner of the new project dao.ProjectUser(email=dao.get_current_site_user().email, permissions=[dao.PROJECT_OWN], parent=project_key).put() # Get the selected template ID template_id = self.request.get(u'template_id') if template_id: # Generate HTML for the template template_entity = dao.get_template_by_id(template_id) html_generator_service = HtmlGeneratorService(template_entity) html_generator_service.generate_all_html() # Copy entities owned by the template entity into the project for assignment_entity in dao.get_assignments(template_entity): assignment_entity.clone(project).put() for document_entity in dao.get_documents(template_entity): template_document_entity = document_entity.clone(project) template_document_entity.put() for document_item_entity in dao.get_document_items( document_entity): document_item_entity.clone( template_document_entity).put() for interview_entity in dao.get_interviews(template_entity): cloned_interview_entity = interview_entity.clone(project) if cloned_interview_entity.auto_assign: cloned_interview_entity.assigned_email = current_email cloned_interview_entity.put() for style_entity in dao.get_styles(template_entity): style_entity.clone(project).put() for variable_entity in dao.get_variables(template_entity): variable_entity.clone(project).put() self.redirect("/project?project_id={}".format(project_key.id())) return except Exception as e: error_msg = u'Creating project failed: {}'.format(e) # Display the webpage self.render(error_msg)
def generate_all_documents(self): for document in dao.get_documents(self.template): self.generate_document_html(document)