Skip to content

Error using Requests to PUT task status #20

@clebio

Description

@clebio

So, trying to follow along with Chapter 6, I hit the API via requests:

import requests
import datetime
response = requests.get('http://localhost:9000/api/tasks', auth=('admin', 'admin'))
tasks = response.json()
t0 = tasks['results'][0]
t0['assigned'] = 'admin'
t0['status'] = 2
today = datetime.date.today()
t0['started'] = today
response = requests.put(t0['links']['self'], data=t0, auth=('admin', 'admin'))

But when I PUT the task back, I'm met with a 400 response:

In [21]: response = requests.put(t0['links']['self'], data=t0, auth=('admin', 'admin'))
In [22]: response.text
Out[22]: u'{"non_field_errors":["Backlog tasks must have \\"Not Started\\" status."]}'

I'm also a bit confused, and perhaps this is related, about the statuses as defined in the models versus in the Backbone UI:

In [27]: from board import models
In [28]: models.Task.STATUS_TODO
Out[28]: 1

Whereas when I hit up http://localhost:9000/#sprint/1, I see five statuses:
Backlog, Not Started, In Development, In Testing, Completed

I haven't dug too far down yet, but it seems like there's a conflict in the STATUS codes:
https://github.com/lightweightdjango/examples/blob/chapter-6/scrum/board/static/board/js/views.js#L307

            this.statuses = {
                unassigned: new StatusView({
                    sprint: null, status: 1, title: 'Backlog'}),
                todo: new StatusView({
                    sprint: this.sprintId, status: 1, title: 'Not Started'}),
                active: new StatusView({
                    sprint: this.sprintId, status: 2, title: 'In Development'}),
                testing: new StatusView({
                    sprint: this.sprintId, status: 3, title: 'In Testing'}),
                done: new StatusView({
                    sprint: this.sprintId, status: 4, title: 'Completed'})
            };

versus
https://github.com/lightweightdjango/examples/blob/chapter-6/scrum/board/models.py#L20

    STATUS_TODO = 1
    STATUS_IN_PROGRESS = 2
    STATUS_TESTING = 3
    STATUS_DONE = 4

    STATUS_CHOICES = (
        (STATUS_TODO, _('Not Started')),
        (STATUS_IN_PROGRESS, _('In Progress')),
        (STATUS_TESTING, _('Testing')),
        (STATUS_DONE, _('Done')),
    )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions