예제 #1
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
    }))
예제 #2
0
파일: action.py 프로젝트: majklovec/big-rig
    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}))
예제 #3
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}))
예제 #4
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
    }))
예제 #5
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
    }))
예제 #6
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
    }))
예제 #7
0
파일: action.py 프로젝트: majklovec/big-rig
    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}))
예제 #8
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))
예제 #9
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
    }))
예제 #10
0
파일: action.py 프로젝트: majklovec/big-rig
    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}))
예제 #11
0
파일: action.py 프로젝트: majklovec/big-rig
    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}))
예제 #12
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))
예제 #13
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
예제 #14
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