Beispiel #1
0
  def post(self):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    save_message = 'ok'

    project_name = self.request.get('project-name')
    project_visible_to_owner_only = (self.request.get(
        'project-visible-to-owner-only') == 'on')

    if (project_name == '' or project_name == None):
      save_message = 'No project name provided'
    else:

      project = Project(
        name=project_name,
        owner=UserManager.get_email(),
        visible_to_owner_only=project_visible_to_owner_only,
        secret=base64.b64encode(os.urandom(48))
      )

      project.put()

    template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/project-create.json')
    self.response.write(template.render({
      "message": save_message
    }))
Beispiel #2
0
    def post(self):

        if UserManager.get_current_user() == None:
            self.redirect('/user-not-found')
            return

        save_message = 'ok'

        project_key_string = self.request.get('project-key')
        project_name = self.request.get('project-name')
        project_visible_to_owner_only = (
            self.request.get('project-visible-to-owner-only') == 'on')

        if (project_key_string == '' or project_key_string == None):
            save_message = 'No project key provided'
        else:

            project = Project.get_by_id(int(project_key_string))
            if project == None:
                save_message = 'No project found'
            else:

                if UserManager.get_user_has_privilege_for_operation(project):
                    project.name = project_name
                    project.visible_to_owner_only = project_visible_to_owner_only

                    project.put()
                else:
                    save_message = 'Permission denied.'

        template = JINJA_ENVIRONMENT.get_template(
            'templates/_endpoints/action-update.json')
        self.response.write(template.render({"message": save_message}))
Beispiel #3
0
  def get (self, url):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    if (url == '' or os.path.isdir('help/%s' % url)):
      url += 'index.md'

    template = JINJA_ENVIRONMENT.get_template('templates/help/help.html')
    help_file_path = 'help/%s' % re.sub('html$', 'md', url)

    if not os.path.exists(help_file_path):
      print help_file_path
      return

    with codecs.open(help_file_path, 'r', 'utf-8') as md_file:
      help_file = md_file.read()

    self.response.write(template.render({
      'sign_out_url': UserManager.get_signout_url(),
      'gravatar_url': UserManager.get_gravatar_url(),
      'user_email': UserManager.get_email(),
      'user_is_admin': UserManager.is_admin(),
      'sections': [{
        "name": "Help"
      }],
      'help': markdown.markdown(help_file, extensions=['markdown.extensions.fenced_code'])
    }))
Beispiel #4
0
  def post (self):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    save_message = 'ok'

    user_email = self.request.get('user-email')

    if (user_email == '' or user_email == None):
      save_message = 'No email address provided.'
    elif (UserManager.get_user_by_email_address(user_email) == None):
      save_message = 'User does not exist.'
    else:

      projects_to_reassign = Project.query().filter(Project.owner==user_email)
      to_update = []

      for project in projects_to_reassign:
        project.owner = UserManager.get_email()
        to_update.append(project)

      if len(to_update) > 0:
        ndb.put_multi(to_update)

      user = UserManager.get_user_by_email_address(user_email)
      user.key.delete()

    template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json')
    self.response.write(template.render({
      "message": save_message
    }))
Beispiel #5
0
    def post(self):

        if UserManager.get_current_user() == None:
            self.redirect('/user-not-found')
            return

        save_message = 'ok'

        project_name = self.request.get('project-name')
        project_visible_to_owner_only = (
            self.request.get('project-visible-to-owner-only') == 'on')

        if (project_name == '' or project_name == None):
            save_message = 'No project name provided'
        else:

            project = Project(
                name=project_name,
                owner=UserManager.get_email(),
                visible_to_owner_only=project_visible_to_owner_only,
                secret=base64.b64encode(os.urandom(48)))

            project.put()

        template = JINJA_ENVIRONMENT.get_template(
            'templates/_endpoints/project-create.json')
        self.response.write(template.render({"message": save_message}))
Beispiel #6
0
  def post(self):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    save_message = 'ok'

    project_key_string = self.request.get('project-key')
    project_name = self.request.get('project-name')
    project_visible_to_owner_only = (
      self.request.get('project-visible-to-owner-only') == 'on')

    if (project_key_string == '' or project_key_string == None):
      save_message = 'No project key provided'
    else:

      project = Project.get_by_id(int(project_key_string))
      if project == None:
        save_message = 'No project found'
      else:

        if UserManager.get_user_has_privilege_for_operation(project):
          project.name = project_name
          project.visible_to_owner_only = project_visible_to_owner_only

          project.put()
        else:
          save_message = 'Permission denied.'

    template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json')
    self.response.write(template.render({
      "message": save_message
    }))
Beispiel #7
0
  def post(self, url):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    message = 'ok'

    project_key_string = self.request.get('project-key')
    action_key_string = self.request.get('action-detail-key')
    endpoint = self.request.get('endpoint')
    subscription_id = self.request.get('subscription-id')
    email = UserManager.get_email()

    if (project_key_string == '' or project_key_string == None):
      message = 'No project key provided'
    elif (action_key_string == '' or action_key_string == None):
      message = 'No action key provided'
    elif (endpoint == '' or endpoint == None):
      message = 'No endpoint provided'
    else:

      project_key = ndb.Key(
        Project, int(project_key_string),
      )

      project = project_key.get()

      if UserManager.get_user_has_privilege_for_operation(project):

        action_key = ndb.Key(Project, int(project_key_string),
            Action, int(action_key_string))
        subscription = Subscription.query(ancestor=action_key).filter(
              ndb.query.AND(
                Subscription.email==email,
                Subscription.endpoint==endpoint
              )
            ).get()

        if url == 'unsubscribe' and subscription is not None:
          ndb.delete_multi([subscription.key])
        elif url == 'subscribe' and subscription is None:
          message = 'new'

          subscription = Subscription(
              parent=action_key,
              endpoint=endpoint,
              email=email)

          subscription.put()

      else:
        message = 'Permission denied.'

    template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json')
    self.response.write(template.render({
      "message": message
    }))
Beispiel #8
0
  def post(self):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    save_message = 'ok'

    project_key_string = self.request.get('project-key')
    action_name = self.request.get('action-name')
    action_label = self.request.get('action-label')
    action_type = self.request.get('action-type')
    y_axis_max = 'duration'
    y_axis = 0 # Relative

    if (action_type != 'Load' and
        action_type != 'Response' and
        action_type != 'Animation'):
      action_type = 'Load'

    if (action_type == 'Animation'):
      y_axis_max = 'fps'
      y_axis = 1 # Default to absolute

    if (project_key_string == '' or project_key_string == None):
      save_message = 'No project key provided'
    else:

      project_key = ndb.Key(
        Project, int(project_key_string),
      )

      project = project_key.get()

      if UserManager.get_user_has_privilege_for_operation(project):

        action = Action(
          parent=project_key,
          name=action_name,
          type=action_type,
          label=action_label,
          x_axis=0,
          y_axis=0,
          y_axis_max=y_axis_max
        )

        action.put()
      else:
        save_message = 'Permission denied.'

    template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json')
    self.response.write(template.render({
      "message": save_message
    }))
Beispiel #9
0
  def get (self):

    if UserManager.get_current_user() != None:
      self.redirect('/')

    template = JINJA_ENVIRONMENT.get_template('templates/user-not-found.html')
    self.response.write(template.render({
      'sign_out_url': UserManager.get_signout_url(),
      'user_email': UserManager.get_email(),
      'sections': [{
        "name": "User not found"
      }]}))
Beispiel #10
0
    def post(self):

        if UserManager.get_current_user() == None:
            self.redirect('/user-not-found')
            return

        save_message = 'ok'

        project_key_string = self.request.get('project-key')
        action_name = self.request.get('action-name')
        action_label = self.request.get('action-label')
        action_type = self.request.get('action-type')
        y_axis_max = 'duration'
        y_axis = 0  # Relative

        if (action_type != 'Load' and action_type != 'Response'
                and action_type != 'Animation'):
            action_type = 'Load'

        if (action_type == 'Animation'):
            y_axis_max = 'fps'
            y_axis = 1  # Default to absolute

        if (project_key_string == '' or project_key_string == None):
            save_message = 'No project key provided'
        else:

            project_key = ndb.Key(
                Project,
                int(project_key_string),
            )

            project = project_key.get()

            if UserManager.get_user_has_privilege_for_operation(project):

                action = Action(parent=project_key,
                                name=action_name,
                                type=action_type,
                                label=action_label,
                                x_axis=0,
                                y_axis=0,
                                y_axis_max=y_axis_max)

                action.put()
            else:
                save_message = 'Permission denied.'

        template = JINJA_ENVIRONMENT.get_template(
            'templates/_endpoints/action-update.json')
        self.response.write(template.render({"message": save_message}))
Beispiel #11
0
  def post(self):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    delete_message = 'ok'

    project_key_string = self.request.get('project-key')

    if (project_key_string == '' or project_key_string == None):
      delete_message = 'No project key provided'
    else:

      project = Project.get_by_id(int(project_key_string))

      if UserManager.get_user_has_privilege_for_operation(project):

        project_key = ndb.Key(Project, project.key.integer_id())
        actions = Action.query(ancestor=project_key)

        # Start with the project
        to_delete = [project.key]

        # No find all its actions
        for action in actions:

          # Add those to the list
          to_delete.append(action.key)

          # Now get all the action details
          action_detail_key = ndb.Key(
            Project, project.key.integer_id(),
            Action, action.key.integer_id()
          )

          action_details = ActionDetail.query(ancestor=action_detail_key)

          for action_detail in action_details:
            to_delete.append(action_detail.key)

        ndb.delete_multi(to_delete)

      else:
        delete_message = 'Permission denied.'

    template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json')
    self.response.write(template.render({
      "message": delete_message
    }))
Beispiel #12
0
    def post(self):

        if UserManager.get_current_user() == None:
            self.redirect('/user-not-found')
            return

        delete_message = 'ok'

        project_key_string = self.request.get('project-key')

        if (project_key_string == '' or project_key_string == None):
            delete_message = 'No project key provided'
        else:

            project = Project.get_by_id(int(project_key_string))

            if UserManager.get_user_has_privilege_for_operation(project):

                project_key = ndb.Key(Project, project.key.integer_id())
                actions = Action.query(ancestor=project_key)

                # Start with the project
                to_delete = [project.key]

                # No find all its actions
                for action in actions:

                    # Add those to the list
                    to_delete.append(action.key)

                    # Now get all the action details
                    action_detail_key = ndb.Key(Project,
                                                project.key.integer_id(),
                                                Action,
                                                action.key.integer_id())

                    action_details = ActionDetail.query(
                        ancestor=action_detail_key)

                    for action_detail in action_details:
                        to_delete.append(action_detail.key)

                ndb.delete_multi(to_delete)

            else:
                delete_message = 'Permission denied.'

        template = JINJA_ENVIRONMENT.get_template(
            'templates/_endpoints/action-update.json')
        self.response.write(template.render({"message": delete_message}))
Beispiel #13
0
  def post(self):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    save_message = 'ok'

    project_key_string = self.request.get('project-key')
    action_key_string = self.request.get('action-key')
    action_name = self.request.get('action-name')
    action_label = self.request.get('action-label')
    action_type = self.request.get('action-type')

    if (action_type != 'Load' and
        action_type != 'Response' and
        action_type != 'Animation'):
      action_type = 'Load'

    if (project_key_string == '' or project_key_string == None):
      save_message = 'No project key provided'
    elif (action_key_string == '' or action_key_string == None):
      save_message = 'No project key provided'
    else:

      project_key = ndb.Key(
        Project, int(project_key_string),
      )

      project = project_key.get()

      if UserManager.get_user_has_privilege_for_operation(project):

        action = Action.get_by_id(int(action_key_string),
          parent=project_key)

        action.name = action_name
        action.type = action_type
        action.label = action_label

        action.put()

      else:
        save_message = 'Permission denied.'

    template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json')
    self.response.write(template.render({
      "message": save_message
    }))
Beispiel #14
0
  def post(self):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    delete_message = 'ok'

    project_key_string = self.request.get('project-key')
    action_key_string = self.request.get('action-key')

    if (project_key_string == '' or project_key_string == None):
      delete_message = 'No project key provided'
    elif (action_key_string == '' or action_key_string == None):
      delete_message = 'No project key provided'
    else:

      project_key = ndb.Key(
        Project, int(project_key_string),
      )

      project = project_key.get()

      if UserManager.get_user_has_privilege_for_operation(project):

        action = Action.get_by_id(int(action_key_string),
          parent=project_key)

        action_detail_key = ndb.Key(
          Project, int(project_key_string),
          Action, int(action_key_string)
        )

        to_delete = [action.key]
        to_delete.extend(
          ndb.Query(
            ancestor=action_detail_key
          ).iter(keys_only=True)
        )

        ndb.delete_multi(to_delete)

      else:
        delete_message = 'Permission denied.'

    template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json')
    self.response.write(template.render({
      "message": delete_message
    }))
Beispiel #15
0
    def get(self):

        if UserManager.get_current_user() != None:
            self.redirect('/')

        template = JINJA_ENVIRONMENT.get_template(
            'templates/user-not-found.html')
        self.response.write(
            template.render({
                'sign_out_url': UserManager.get_signout_url(),
                'user_email': UserManager.get_email(),
                'sections': [{
                    "name": "User not found"
                }]
            }))
Beispiel #16
0
    def post(self):

        if UserManager.get_current_user() == None:
            self.redirect('/user-not-found')
            return

        save_message = 'ok'

        project_key_string = self.request.get('project-key')
        action_key_string = self.request.get('action-key')
        action_name = self.request.get('action-name')
        action_label = self.request.get('action-label')
        action_type = self.request.get('action-type')

        if (action_type != 'Load' and action_type != 'Response'
                and action_type != 'Animation'):
            action_type = 'Load'

        if (project_key_string == '' or project_key_string == None):
            save_message = 'No project key provided'
        elif (action_key_string == '' or action_key_string == None):
            save_message = 'No project key provided'
        else:

            project_key = ndb.Key(
                Project,
                int(project_key_string),
            )

            project = project_key.get()

            if UserManager.get_user_has_privilege_for_operation(project):

                action = Action.get_by_id(int(action_key_string),
                                          parent=project_key)

                action.name = action_name
                action.type = action_type
                action.label = action_label

                action.put()

            else:
                save_message = 'Permission denied.'

        template = JINJA_ENVIRONMENT.get_template(
            'templates/_endpoints/action-update.json')
        self.response.write(template.render({"message": save_message}))
Beispiel #17
0
    def get(self):

        if UserManager.get_current_user() == None:
            self.redirect('/user-not-found')
            return

        self.redirect('/projects/list')
Beispiel #18
0
  def get(self):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    self.redirect('/projects/list')
Beispiel #19
0
  def get(self):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    template = JINJA_ENVIRONMENT.get_template('templates/project/project.html')
    self.response.write(template.render({
      'projects': Project.query(),
      'sign_out_url': UserManager.get_signout_url(),
      'gravatar_url': UserManager.get_gravatar_url(),
      'user_email': UserManager.get_email(),
      'user_is_admin': UserManager.is_admin(),
      'sections': [{
        "name": "Projects"
      }]
    }))
Beispiel #20
0
    def post(self):

        if UserManager.get_current_user() == None:
            self.redirect('/user-not-found')
            return

        save_message = 'ok'

        project_key_string = self.request.get('project-key')
        action_key_string = self.request.get('action-key')
        action_x_axis = self.request.get('action-x-axis')
        action_y_axis = self.request.get('action-y-axis')

        if (project_key_string == '' or project_key_string == None):
            save_message = 'No project key provided'
        elif (action_key_string == '' or action_key_string == None):
            save_message = 'No project key provided'
        else:

            project_key = ndb.Key(
                Project,
                int(project_key_string),
            )

            project = project_key.get()

            if UserManager.get_user_has_privilege_for_operation(project):

                action = Action.get_by_id(int(action_key_string),
                                          parent=project_key)

                if (re.search('^\d+$', action_x_axis)):
                    action.x_axis = int(action_x_axis)

                if (re.search('^\d+$', action_y_axis)):
                    action.y_axis = int(action_y_axis)

                action.put()
            else:
                save_message = 'Permission denied.'

        template = JINJA_ENVIRONMENT.get_template(
            'templates/_endpoints/action-update.json')
        self.response.write(template.render({"message": save_message}))
Beispiel #21
0
    def post(self):

        if UserManager.get_current_user() == None:
            self.redirect('/user-not-found')
            return

        delete_message = 'ok'

        project_key_string = self.request.get('project-key')
        action_key_string = self.request.get('action-key')

        if (project_key_string == '' or project_key_string == None):
            delete_message = 'No project key provided'
        elif (action_key_string == '' or action_key_string == None):
            delete_message = 'No project key provided'
        else:

            project_key = ndb.Key(
                Project,
                int(project_key_string),
            )

            project = project_key.get()

            if UserManager.get_user_has_privilege_for_operation(project):

                action = Action.get_by_id(int(action_key_string),
                                          parent=project_key)

                action_detail_key = ndb.Key(Project, int(project_key_string),
                                            Action, int(action_key_string))

                to_delete = [action.key]
                to_delete.extend(
                    ndb.Query(ancestor=action_detail_key).iter(keys_only=True))

                ndb.delete_multi(to_delete)

            else:
                delete_message = 'Permission denied.'

        template = JINJA_ENVIRONMENT.get_template(
            'templates/_endpoints/action-update.json')
        self.response.write(template.render({"message": delete_message}))
Beispiel #22
0
  def post(self):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    save_message = 'ok'

    project_key_string = self.request.get('project-key')
    action_key_string = self.request.get('action-key')
    action_x_axis = self.request.get('action-x-axis')
    action_y_axis = self.request.get('action-y-axis')

    if (project_key_string == '' or project_key_string == None):
      save_message = 'No project key provided'
    elif (action_key_string == '' or action_key_string == None):
      save_message = 'No project key provided'
    else:

      project_key = ndb.Key(
        Project, int(project_key_string),
      )

      project = project_key.get()

      if UserManager.get_user_has_privilege_for_operation(project):

        action = Action.get_by_id(int(action_key_string),
          parent=project_key)

        if (re.search('^\d+$', action_x_axis)):
          action.x_axis = int(action_x_axis)

        if (re.search('^\d+$', action_y_axis)):
          action.y_axis = int(action_y_axis)

        action.put()
      else:
        save_message = 'Permission denied.'

    template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json')
    self.response.write(template.render({
      "message": save_message
    }))
Beispiel #23
0
    def get(self):

        if UserManager.get_current_user() == None:
            self.redirect('/user-not-found')
            return

        template = JINJA_ENVIRONMENT.get_template(
            'templates/project/project.html')
        self.response.write(
            template.render({
                'projects': Project.query(),
                'sign_out_url': UserManager.get_signout_url(),
                'gravatar_url': UserManager.get_gravatar_url(),
                'user_email': UserManager.get_email(),
                'user_is_admin': UserManager.is_admin(),
                'sections': [{
                    "name": "Projects"
                }]
            }))
Beispiel #24
0
  def post (self):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    save_message = 'ok'
    user_email = self.request.get('user-email')

    if (user_email == '' or user_email == None):
      save_message = 'No email address provided.'
    elif (UserManager.get_user_by_email_address(user_email) != None):
      save_message = 'User already exists.'
    else:
      user = User(email=user_email)
      user.put()

    template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json')
    self.response.write(template.render({
      "message": save_message
    }))
Beispiel #25
0
  def get (self):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    if not UserManager.is_admin():
      self.redirect('/')
      return

    template = JINJA_ENVIRONMENT.get_template('templates/users/users.html')

    def is_user_admin(user):

      values = sorted(values, key=lambda r: r.value, reverse=True)
      remapped_values = itertools.groupby(values, key=lambda v: v.type)

      return remapped_values

    JINJA_ENVIRONMENT.filters['is_user_admin'] = is_user_admin

    self.response.write(template.render({
      'users': User.query(),
      'sign_out_url': UserManager.get_signout_url(),
      'gravatar_url': UserManager.get_gravatar_url(),
      'user_email': UserManager.get_email(),
      'user_is_admin': UserManager.is_admin(),
      'sections': [{
        "name": "Users"
      }]
    }))
Beispiel #26
0
  def post(self):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    delete_message = 'ok'

    action_detail_key_string = self.request.get('action-detail-key')
    project_key_string = self.request.get('project-key')
    action_key_string = self.request.get('action-key')

    if (project_key_string == '' or project_key_string == None):
      delete_message = 'No project key provided'
    elif (action_key_string == '' or action_key_string == None):
      delete_message = 'No action key provided'
    elif (action_detail_key_string == '' or action_detail_key_string == None):
      delete_message = 'No action detail key provided'
    else:

      project_key = ndb.Key(Project, int(project_key_string))
      project = project_key.get()

      if UserManager.get_user_has_privilege_for_operation(project):

        action_detail_key = ndb.Key(
          Project, int(project_key_string),
          Action, int(action_key_string),
          ActionDetail, int(action_detail_key_string)
        )

        ndb.delete_multi([action_detail_key])
      else:
        delete_message = 'Permission denied.'

    template = JINJA_ENVIRONMENT.get_template('templates/_endpoints/action-update.json')
    self.response.write(template.render({
      "message": delete_message
    }))
Beispiel #27
0
    def post(self):

        if UserManager.get_current_user() == None:
            self.redirect('/user-not-found')
            return

        delete_message = 'ok'

        action_detail_key_string = self.request.get('action-detail-key')
        project_key_string = self.request.get('project-key')
        action_key_string = self.request.get('action-key')

        if (project_key_string == '' or project_key_string == None):
            delete_message = 'No project key provided'
        elif (action_key_string == '' or action_key_string == None):
            delete_message = 'No action key provided'
        elif (action_detail_key_string == ''
              or action_detail_key_string == None):
            delete_message = 'No action detail key provided'
        else:

            project_key = ndb.Key(Project, int(project_key_string))
            project = project_key.get()

            if UserManager.get_user_has_privilege_for_operation(project):

                action_detail_key = ndb.Key(Project, int(project_key_string),
                                            Action, int(action_key_string),
                                            ActionDetail,
                                            int(action_detail_key_string))

                ndb.delete_multi([action_detail_key])
            else:
                delete_message = 'Permission denied.'

        template = JINJA_ENVIRONMENT.get_template(
            'templates/_endpoints/action-update.json')
        self.response.write(template.render({"message": delete_message}))
Beispiel #28
0
    def get(self, url):

        if UserManager.get_current_user() == None:
            self.redirect('/user-not-found')
            return

        if (url == '' or os.path.isdir('help/%s' % url)):
            url += 'index.md'

        template = JINJA_ENVIRONMENT.get_template('templates/help/help.html')
        help_file_path = 'help/%s' % re.sub('html$', 'md', url)

        if not os.path.exists(help_file_path):
            print help_file_path
            return

        with codecs.open(help_file_path, 'r', 'utf-8') as md_file:
            help_file = md_file.read()

        self.response.write(
            template.render({
                'sign_out_url':
                UserManager.get_signout_url(),
                'gravatar_url':
                UserManager.get_gravatar_url(),
                'user_email':
                UserManager.get_email(),
                'user_is_admin':
                UserManager.is_admin(),
                'sections': [{
                    "name": "Help"
                }],
                'help':
                markdown.markdown(
                    help_file, extensions=['markdown.extensions.fenced_code'])
            }))
Beispiel #29
0
    def get(self, key):

        if UserManager.get_current_user() == None:
            self.redirect('/user-not-found')
            return

        project = Project.get_by_id(int(key))

        if project == None:
            self.redirect('/')
            return

        if not UserManager.get_user_has_privilege_for_operation(project):
            self.redirect('/')
            return

        project_key = ndb.Key(Project, int(key))
        template_path = 'templates/project/action.html'
        data = {
            'project_key':
            key,
            'project_secret':
            project.secret,
            'logs':
            Log.query(ancestor=project_key).order(-Log.date).fetch(5),
            'actions':
            Action.query(ancestor=project_key).order(Action.name),
            'action_upload_url':
            blobstore.create_upload_url('/action/import'),
            'sign_out_url':
            UserManager.get_signout_url(),
            'gravatar_url':
            UserManager.get_gravatar_url(),
            'user_email':
            UserManager.get_email(),
            'user_is_admin':
            UserManager.is_admin(),
            'sections': [{
                "name": "Projects",
                "url": "/project/list"
            }, {
                "name": project.name
            }]
        }

        template = JINJA_ENVIRONMENT.get_template(template_path)
        self.response.write(template.render(data))
Beispiel #30
0
  def get(self, key):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    project = Project.get_by_id(int(key))

    if project == None:
      self.redirect('/')
      return

    if not UserManager.get_user_has_privilege_for_operation(project):
      self.redirect('/')
      return

    project_key = ndb.Key(Project, int(key))
    template_path = 'templates/project/action.html'
    data = {
      'project_key': key,
      'project_secret': project.secret,
      'logs': Log.query(ancestor=project_key).order(-Log.date).fetch(5),
      'actions': Action.query(ancestor=project_key).order(Action.name),
      'action_upload_url': blobstore.create_upload_url('/action/import'),
      'sign_out_url': UserManager.get_signout_url(),
      'gravatar_url': UserManager.get_gravatar_url(),
      'user_email': UserManager.get_email(),
      'user_is_admin': UserManager.is_admin(),
      'sections': [{
        "name": "Projects",
        "url": "/project/list"
      },{
        "name": project.name
      }]
    }

    template = JINJA_ENVIRONMENT.get_template(template_path)
    self.response.write(template.render(data))
Beispiel #31
0
  def get (self, url):

    if UserManager.get_current_user() == None:
      self.redirect('/user-not-found')
      return

    search = re.search('^([0-9A-Za-z\-]+)/([0-9A-Za-z\-]+)/(json)?', url)
    project_key_string = search.group(1)
    action_key_string = search.group(2)
    is_json = (search.group(3) == 'json')

    action_key = ndb.Key(
      Project, int(project_key_string),
    )
    action_detail_key = ndb.Key(
      Project, int(project_key_string),
      Action, int(action_key_string)
    )

    project = Project.get_by_id(int(project_key_string))

    if not UserManager.get_user_has_privilege_for_operation(project):
      self.redirect('/')
      return

    action = Action.get_by_id(int(action_key_string),
      parent=action_key)

    if (action == None):
      self.redirect('/project/%s/' % project_key_string)
      return

    template_path = 'templates/project/action-detail.html'

    if (is_json):
      template_path = 'templates/_endpoints/chart-data.json'

    actions = ActionDetail.query(ancestor=action_detail_key).order(
        -ActionDetail.date)

    data = {
      'action_name': action.name,
      'action_type': action.type,
      'action_label': action.label,
      'action_x_axis': action.x_axis,
      'action_y_axis': action.y_axis,
      'action_y_axis_max': action.y_axis_max,
      'action_upload_url': blobstore.create_upload_url('/action/import'),
      'action_key': action_key_string,
      'project_key': project_key_string,
      'project_secret': project.secret,
      'actions': actions,
      'can_use_speed_index': all(a.speed_index > -1 for a in actions),
      'sign_out_url': UserManager.get_signout_url(),
      'gravatar_url': UserManager.get_gravatar_url(),
      'user_email': UserManager.get_email(),
      'user_is_admin': UserManager.is_admin(),
      'data_url': '/project/' + url + 'json',
      'sections': [{
        "name": "Projects",
        "url": "/project/list"
      },{
        "name": project.name,
        "url": "/project/%s/" % project_key_string
      }, {
        "name": action.name
      }]
    }

    def remap_extended_info(values):

      remapped_values = {}

      for v in values:

        if v.type not in remapped_values:
          remapped_values[v.type] = []

        try:

          value = {
            'name': v.name,
            'type': v.type,
            'value': float(v.value)
          }

        except Exception, e:

          if value == None:
            value = 0.0

        # print v
        remapped_values[v.type].append(value)

      if 'JavaScript' in remapped_values:
        remapped_values['JavaScript'] = (
          sorted(remapped_values['JavaScript'],
                key=lambda r: float(r['value']),
                reverse=True)
        )

      return remapped_values
Beispiel #32
0
    def get(self, url):

        if UserManager.get_current_user() == None:
            self.redirect('/user-not-found')
            return

        search = re.search('^([0-9A-Za-z\-]+)/([0-9A-Za-z\-]+)/(json)?', url)
        project_key_string = search.group(1)
        action_key_string = search.group(2)
        is_json = (search.group(3) == 'json')

        action_key = ndb.Key(
            Project,
            int(project_key_string),
        )
        action_detail_key = ndb.Key(Project, int(project_key_string), Action,
                                    int(action_key_string))

        project = Project.get_by_id(int(project_key_string))

        if not UserManager.get_user_has_privilege_for_operation(project):
            self.redirect('/')
            return

        action = Action.get_by_id(int(action_key_string), parent=action_key)

        if (action == None):
            self.redirect('/project/%s/' % project_key_string)
            return

        template_path = 'templates/project/action-detail.html'

        if (is_json):
            template_path = 'templates/_endpoints/chart-data.json'

        actions = ActionDetail.query(
            ancestor=action_detail_key).order(-ActionDetail.date)

        data = {
            'action_name':
            action.name,
            'action_type':
            action.type,
            'action_label':
            action.label,
            'action_x_axis':
            action.x_axis,
            'action_y_axis':
            action.y_axis,
            'action_y_axis_max':
            action.y_axis_max,
            'action_upload_url':
            blobstore.create_upload_url('/action/import'),
            'action_key':
            action_key_string,
            'project_key':
            project_key_string,
            'project_secret':
            project.secret,
            'actions':
            actions,
            'can_use_speed_index':
            all(a.speed_index > -1 for a in actions),
            'sign_out_url':
            UserManager.get_signout_url(),
            'gravatar_url':
            UserManager.get_gravatar_url(),
            'user_email':
            UserManager.get_email(),
            'user_is_admin':
            UserManager.is_admin(),
            'data_url':
            '/project/' + url + 'json',
            'sections': [{
                "name": "Projects",
                "url": "/project/list"
            }, {
                "name": project.name,
                "url": "/project/%s/" % project_key_string
            }, {
                "name": action.name
            }]
        }

        def remap_extended_info(values):

            remapped_values = {}

            for v in values:

                if v.type not in remapped_values:
                    remapped_values[v.type] = []

                try:

                    value = {
                        'name': v.name,
                        'type': v.type,
                        'value': float(v.value)
                    }

                except Exception, e:

                    if value == None:
                        value = 0.0

                # print v
                remapped_values[v.type].append(value)

            if 'JavaScript' in remapped_values:
                remapped_values['JavaScript'] = (sorted(
                    remapped_values['JavaScript'],
                    key=lambda r: float(r['value']),
                    reverse=True))

            return remapped_values