Beispiel #1
0
Datei: api.py Projekt: Pike/todo
def update(request, obj, obj_id):
    """Update various properties of a todo object.

    This method expects all the values to be in the `request.POST`. More 
    specifically, `todo.forms.UpdateTodoForm` defines which properties
    are accepted and which are required.

    Arguments:
    obj -- the model of the todo object to be changed
    obj_id -- the ID of the todo object to be changed

    """
    if not request.user.has_perm('todo.change_%s' % obj):
        return _status_response('error', "You don't have permissions to "
                                "update this %s." % obj)
    model = Task if obj == 'task' else Tracker
    form = UpdateTodoForm(request.POST)
    if not form.is_valid():
        message = 'There were problems with the following fields:\n'
        for field, errorlist in form.errors.iteritems():
            message += '%s: %s' % (field, errorlist.as_text())
        return _status_response('error', message)
    todo = get_object_or_404(model, pk=obj_id)
    for prop, new_value in form.cleaned_data.iteritems():
        setattr(todo, prop, new_value)
    todo.save()
    todo_updated.send(sender=todo, user=request.user, action=UPDATED)
    changed_objs = serialize('python', (todo,))
    return _status_response('ok', '%s updated.' % obj, changed_objs)
Beispiel #2
0
Datei: api.py Projekt: Pike/todo
def update_snapshot(request, task_id):
    "Specifically update the snapshot timestamp."

    if not request.user.has_perm('todo.change_task'):
        return _status_response('error', "You don't have permissions to "
                                "update the snapshot timestamp.")
    new_snapshot_ts = datetime.strptime(request.POST.get('snapshot_ts'),
                                        BzAPI.time_format)
    if not new_snapshot_ts:
        return _status_response('error', 'Unknown timestamp (%s)' %
                                request.POST.get('snapshot_ts'))
    task = get_object_or_404(Task, pk=task_id)
    task.snapshot_ts = new_snapshot_ts
    task.save()
    todo_updated.send(sender=task, user=request.user, action=SNAPSHOT_UPDATED)
    return _status_response('ok', 'Timestamp updated (%s)' %
                            task.snapshot_ts_iso())
Beispiel #3
0
    def update(self, user, properties, send_signal=True, flag=UPDATED):
        """Update properties of the todo object.

        Arguments:
            user -- the author of the change
            properties -- a dict with new values for the properties
            send_signal -- a boolean defining whether to send a `todo_updated`
                           signal or not (default is True)
            flag -- a flag to be sent in the signal (default is UPDATED)

        """
        for prop, new_value in properties.iteritems():
            setattr(self, prop, new_value)
        # if any of these properties change, we need to force the update of all 
        # cached representation strings stored on the todo object
        force_needed = ('summary', 'locale', 'prototype')
        if any(prop in force_needed for prop in properties.keys()):
            self.save(force=True)
        else:
            self.save()
        if send_signal:
            todo_updated.send(sender=self, user=user, flag=flag)
Beispiel #4
0
Datei: api.py Projekt: Pike/todo
    new_snapshot_ts = datetime.strptime(request.POST.get('snapshot_ts'),
                                        BzAPI.time_format)
    if not new_snapshot_ts:
        return _status_response('error', 'Unknown timestamp (%s)' %
                                request.POST.get('snapshot_ts'))
    task = get_object_or_404(Task, pk=task_id)
    task.snapshot_ts = new_snapshot_ts
    task.save()
    todo_updated.send(sender=task, user=request.user, action=SNAPSHOT_UPDATED)
    return _status_response('ok', 'Timestamp updated (%s)' %
                            task.snapshot_ts_iso())

@require_POST
def update_bugid(request, task_id):
    "Specifically update the bug ID."

    if not request.user.has_perm('todo.change_task'):
        return _status_response('error', "You don't have permissions to "
                                "update the bug ID of this task.")
    new_bugid = request.POST.get('bugid', None)
    try:
        new_bugid = int(new_bugid)
    except ValueError, TypeError:
        return _status_response('error', 'Incorrect value of the bug ID (%s)' %
                                request.POST.get('bugid'))
    task = get_object_or_404(Task, pk=task_id)
    task.bug = new_bugid
    task.save()
    todo_updated.send(sender=task, user=request.user, action=BUGID_UPDATED)
    return _status_response('ok', 'Bug ID updated (%s)' % task.bugid)