def update(project_id): auth_header = request.headers.get('Authorization') if not auth_header: return jsonify(status="failed", message="No authorization header found.") else: token = auth_header.split(" ")[1] user_id = decode_auth_token(token) user = User.get(User.id == int(user_id)) put_data = request.get_json() project = Project.get_by_id(project_id) ## if key exists in JSON, then iterate (currently not working): # for k, v in put_data.items(): # project.k = v project.name = put_data['name'] project.client_id = put_data['clientID'] project.project_type = put_data['projectType'] project.date = put_data['date'] project.currency = put_data['currency'] project.total = put_data['total'] if project.save(): return jsonify(status="success", message="Project details updated.") else: return jsonify(status="failed", message="Unable to update project details.")
def show(project_id): auth_header = request.headers.get('Authorization') if not auth_header: return jsonify(status="failed", message="No authorization header found.") else: token = auth_header.split(" ")[1] user_id = decode_auth_token(token) user = User.get(User.id == int(user_id)) project = Project.get_by_id(project_id) project_data = { "id": project.id, "name": project.name, "project_type": project.project_type, "client_id": str(project.client_id), "client_name": Client.get_by_id(project.client_id).name, "date": str(project.date), "currency": project.currency, "total": str(project.total) } if user: return jsonify(project_data) else: return jsonify(status="failed", message="Authentication failed.")
def post(self): user = users.get_current_user() if not user or user.email() != '*****@*****.**': return recordId = self.request.POST["id"] project = None if recordId is not None and recordId.isdigit(): #logging.info(recordId) #logging.info(long(recordId)) project = Project.get_by_id(long(recordId)) if project is None: project = Project() project.title = self.request.POST["title"] project.description = self.request.POST["description"] project.link = self.request.POST["link"] newKey = project.put() self.response.out.write(newKey.id())
def read(project_id): result = Project.get_by_id(int(project_id)) return result