Ejemplo n.º 1
0
Archivo: tasks.py Proyecto: omps/beaker
    def default(self, *args, **kw):
        try:
            using_task_id = False
            if len(args) == 1:
                try:
                    task_id = int(args[0])
                    using_task_id = True
                except ValueError:
                    pass
            if using_task_id:
                task = Task.by_id(task_id)
            else:
                task = Task.by_name("/%s" % "/".join(args))
                #Would rather not redirect but do_search expects task_id in URL
                #This is the simplest way of dealing with it
                redirect("/tasks/%s" % task.id)
        except DatabaseLookupError as e:
            flash(unicode(e))
            redirect("/tasks")

        return dict(task=task,
                    form = self.task_form,
                    value = dict(task_id = task.id),
                    options = dict(hidden=dict(task = 1)),
                    action = './do_search')
Ejemplo n.º 2
0
    def default(self, *args, **kw):
        try:
            using_task_id = False
            if len(args) == 1:
                try:
                    task_id = int(args[0])
                    using_task_id = True
                except ValueError:
                    pass
            if using_task_id:
                task = Task.by_id(task_id)
            else:
                task = Task.by_name("/%s" % "/".join(args))
                #Would rather not redirect but do_search expects task_id in URL
                #This is the simplest way of dealing with it
                redirect("/tasks/%s" % task.id)
        except DatabaseLookupError as e:
            flash(unicode(e))
            redirect("/tasks")

        return dict(task=task,
                    form=self.task_form,
                    value=dict(task_id=task.id),
                    options=dict(hidden=dict(task=1)),
                    action='./do_search')
Ejemplo n.º 3
0
def update_task(task_id):
    """
    Updates a task - only handles disabling at this time.

    :param task_id: The task id to update/disable
    :jsonparam bool disabled: Whether the task should be disabled.
    :status 200: Task was successfully updated/disabled
    :status 404: Task was not found (to be disabled)
    """
    try:
        task = Task.by_id(task_id)
    except DatabaseLookupError as e:
        # This should be NotFound404 but due to still using cherrypy
        # 404's are handled there which then will then do a GET /tasks/id
        # which will resolve correctly, which isn't desired
        raise NotFound404('Task %s does not exist' % task_id)

    data = read_json_request(request)

    if data:
        with convert_internal_errors():
            if data.get('disabled', False) and task.valid:
                task.disable()

    response = jsonify(task.to_dict())

    return response
Ejemplo n.º 4
0
    def default(self, *args, **kw):
        # to handle the case one of the flask methods
        # have raised a 404 but the intention isn't to redirect
        # back to cherrypy, but legitimately 404
        if cherrypy.request.method != 'GET':
            raise cherrypy.HTTPError(404)
        try:
            using_task_id = False
            if len(args) == 1:
                try:
                    task_id = int(args[0])
                    using_task_id = True
                except ValueError:
                    pass
            if using_task_id:
                task = Task.by_id(task_id)
            else:
                task = Task.by_name("/%s" % "/".join(args))
                #Would rather not redirect but do_search expects task_id in URL
                #This is the simplest way of dealing with it
                redirect("/tasks/%s" % task.id)
        except DatabaseLookupError as e:
            flash(unicode(e))
            redirect("/tasks")

        attributes = task.to_dict()
        attributes['can_disable'] = bool(identity.current.user
                                         and identity.current.user.is_admin())

        return dict(attributes=attributes,
                    url="/tasks/%s" % task.id,
                    form=self.task_form,
                    value=dict(task_id=task.id),
                    options=dict(hidden=dict(task=1)),
                    action='./do_search')
Ejemplo n.º 5
0
 def default(self, *args, **kw):
     try:
         using_task_id = False
         if len(args) == 1:
             try:
                 task_id = int(args[0])
                 using_task_id = True
             except ValueError:
                 pass
         if using_task_id:
             task = Task.by_id(task_id)
         else:
             task = Task.by_name("/%s" % "/".join(args))
             #Would rather not redirect but do_search expects task_id in URL
             #This is the simplest way of dealing with it
             redirect("/tasks/%s" % task.id)
     except InvalidRequestError:
         if using_task_id:
             err_msg = u'Invalid task_id %s' % args[0]
         else:
             err_msg =  u'Invalid task /%s' % '/'.join(args)
         flash(_(err_msg))
         redirect("/tasks")
     return dict(task=task,
                 form = self.task_form,
                 value = dict(task_id = task.id),
                 options = dict(hidden=dict(task = 1)),
                 action = './do_search')
Ejemplo n.º 6
0
 def _disable(self, t_id, *args, **kw):
     """
     disable task
      task.valid=False
      remove task rpms from filesystem
     """
     task = Task.by_id(t_id)
     return task.disable()
Ejemplo n.º 7
0
Archivo: tasks.py Proyecto: omps/beaker
 def _disable(self, t_id, *args, **kw):
     """
     disable task
      task.valid=False
      remove task rpms from filesystem
     """
     task = Task.by_id(t_id)
     return task.disable()