julia_v_iluhina

Untitled

Jul 24th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. с create у тебя не заладилось)
  2. ошибка при компиляции
  3. привела 2 рабочих варианта и линки полезные  
  4.  
  5. @app.route('/todo/api/v1.0/tasks', methods = ['POST'])
  6. @auth.login_required
  7. def create_task():
  8.     if not request.json or not 'title' in request.json:
  9.         abort(400)
  10.     id = 1
  11.     if len(tasks) != 0: id = tasks[-1]['id'] + 1
  12.     task = {
  13.         'id': id,
  14.         'title': request.json['title'],
  15.         'description': request.json.get('description', ""),
  16.         'done': False
  17.     }
  18.     tasks.append(task)
  19.     return jsonify( { 'task': make_public_task(task) } ), 201
  20.  
  21.      
  22. @app.route('/todo/api/v1.0/tasks', methods = ['POST'])
  23. @auth.login_required
  24. def create_task():
  25.     if not request.json or not 'title' in request.json:
  26.         abort(400)
  27.     task = {
  28.         'id': 1 if len(tasks) == 0 else tasks[-1]['id'] + 1,
  29.         'title': request.json['title'],
  30.         'description': request.json.get('description', ""),
  31.         'done': False
  32.     }
  33.     tasks.append(task)
  34.     return jsonify( { 'task': make_public_task(task) } ), 201  
  35.      
  36. https://lancelote.gitbooks.io/intermediate-python/content/book/ternary_operators.html
  37. https://lancelote.gitbooks.io/intermediate-python/content/book/comprehensions.html (dict абстракции)
  38. http://www.diveintopython.net/native_data_types/index.html#odbchelper.dict
  39.  
  40. *****************************************
  41.  
  42.  @Test
  43.     public void testCreate() {
  44.  
  45.         TasksApi.create(new Task("Give lesson", "Lesson description", false, TasksApi.uri + "/3"));
  46.         assertTasks(DEFAULT_TASKS[0], DEFAULT_TASKS[1], new Task("Give lesson", "Lesson description", false, TasksApi.uri + "/3"));
  47.     }
  48.  
  49. /*
  50.     вынеси new Task("Give lesson", "Lesson description", false, TasksApi.uri + "/3") - в переменную
  51.    
  52.     и дважды ее используй
  53.    
  54.     тут получится )
  55.    
  56.     и тут
  57.     testUpdate()
  58. */
Advertisement
Add Comment
Please, Sign In to add comment