Exemple #1
0
    def post(self):
        header = request.headers["Authorization"]
        json_data = request.get_json(force=True)

        if not header:
            return {"Messege" : "No api key!"}, 400
        else:
            user = User.query.filter_by(api_key=header).first()
            if user:
                task = Task(
                    title = json_data['title'],
                    user_id = user.id,
                    note = json_data['note'],
                    completed = json_data['completed'],
                    repeats = json_data['repeats'],
                    deadline = json_data['deadline'],
                    reminders = json_data['reminders'],
                )
                db.session.add(task)
                db.session.commit()

                result = Task.serialize(task)
                return {"status": 'success', 'data': result}, 201
            else:
                return {"Messege" : "No user with that api key"}, 402
Exemple #2
0
 def post(self, projectName):
     try:
         task = Task(
             name=self.request.get("name"),
             estimate=self.request.get("estimate"),
             story=Story.get(self.request.get("storyKey")),
         )
         task.put()
         result = {"success": True, "message": "Task created", "task_key": str(task.key())}
     except:
         result = {"success": False, "message": sys.exc_info()[0]}
     self.response.out.write(simplejson.dumps(result))
Exemple #3
0
 def post(self):
     try:
         task = Task.get(self.request.get("key"))
         task.status = self.request.get("status")
         task.put()
         result = {"success": True, "message": "Task's status changed"}
     except:
         result = {"success": False, "message": sys.exc_info()[0]}
     self.response.out.write(simplejson.dumps(result))
Exemple #4
0
    def get(self):
        result = []
        # json_data = request.get_json(force=True)
        header = request.headers["Authorization"]

        if not header:
            return {"Messege": "No API key!"}, 400
        else:
            user = User.query.filter_by(api_key=header).first()
            if user:
                tasks = Task.query.filter_by(user_id=user.id).all()
                for task in tasks:
                    result.append(Task.serialize(task))

            return {"status": 'success', 'data': result}, 201
Exemple #5
0
    def post(self):
        json_data = request.get_json(force=True)

        if not json_data or not 'task_name' in json_data or not 'start_date' in json_data or not 'end_date' in json_data or not 'priority' in json_data or not 'user_id' in json_data or not 'project_id' in json_data or not 'parent_id' in json_data:
            return {"error": "Input data missing"}, 400

        task = Task.query.filter_by(task_name=json_data['task_name']).first()

        if task:
            return {'message': 'Task already exists'}, 400

        user = User.query.filter_by(id=json_data['user_id']).first()

        if not user:
            return {'message': 'User doest not exist'}, 400

        project = Project.query.filter_by(id=json_data['project_id']).first()

        if not project:
            return {'message': 'Project doest not exist'}, 400

        parentTask = ParentTask.query.filter_by(
            id=json_data['parent_id']).first()

        if not parentTask:
            return {'message': 'Parent task doest not exist'}, 400

        task = Task(
            task_name=json_data['task_name'],
            start_date=HelperUtil.stringToDate(self, json_data['start_date']),
            end_date=HelperUtil.stringToDate(self, json_data['end_date']),
            priority=json_data['priority'],
            status=constant.OPEN,
            user_id=json_data['user_id'],
            parent_id=json_data['parent_id'],
            project_id=json_data['project_id'])

        db.session.add(task)
        db.session.commit()

        result = task_schema.dump(task)

        return {"message": "Saved successfully!", "data": result}, 201