Esempio n. 1
0
    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)
Esempio n. 2
0
 def get_assignments(self, template, variable):
     assignment_count = 0
     assignments = u''
     variable_name = variable["name"]
     for assignment in dao.get_assignments(template):
         if variable_name in assignment.variable_names:
             assignment_count += 1
             if len(assignments):
                 assignments += u', '
             assignments += u'<a href="/template/assignment/structure?template_id={}&assignment_id={}">{}</a>'.format(
                 template.key.id(), assignment.key.id(), assignment.name)
     if assignment_count > 1:
         assignments = u'<span style="color: red;">{}</span>'.format(
             assignments)
     return assignments
Esempio n. 3
0
    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)

        assignment_list = list()

        for assignment_entity in dao.get_assignments(template):
            assignment = dict()
            assignment[u'id'] = assignment_entity.key.id()
            assignment[u'name'] = assignment_entity.name
            assignment[u'description'] = assignment_entity.description
            assignment[u'is_repeating'] = assignment_entity.is_repeating
            assignment_list.append(assignment)

        # Create template and template values, render the page
        jinja_template = ui.get_template(self,
                                         u'template/assignment/index.html')

        jinja_template_values = dao.get_standard_template_values(template)
        jinja_template_values[u'assignments'] = assignment_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)
Esempio n. 5
0
 def generate_all_assignments(self):
     for assignment in dao.get_assignments(self.template):
         self.generate_interview_html(assignment)