def get_all_projects(): response_object = {'status': status_msg_success} try: all_projects = Project.get_all() all_projects_json = projects_schema.dump(all_projects) response_object['projects'] = all_projects_json response_object['message'] = 'Projects queried succesfully!' json_response = jsonify(response_object) return make_response(json_response, 200) except Exception as e: response_object['status'] = status_msg_fail response_object[ 'message'] = 'Something went wrong when trying to fetch projects' json_response = jsonify(response_object) return make_response(json_response, 400)
def get(self): """ Get all Project :param None: :return: Project object """ # user = get_jwt_identity() schema = ProjectSchema(many=True) projects = Project.get_all() if projects is None: raise ValidationError({'message': 'No Project Found'}) projects_list = schema.dump(projects).data return response('success', success_messages['retrieved'].format('Projects'), projects_list)
def projects(): if request.method == "POST": title = str(request.data.get('title', '')) email = str(request.data.get('email', '')) short_description = str(request.data.get('short_description','')) description = str(request.data.get('description', '')) url = str(request.data.get('url', '')) creator_name = str(request.data.get('description', '')) twitter = str(request.data.get('description', '')) instagram = str(request.data.get('description', '')) facebook = str(request.data.get('description', '')) portfolio = str(request.data.get('description', '')) image_url = str(request.data.get('image_url', '')) slug = str(request.data.get('slug', '')) if title and email and short_description and url: project = Project(title=title, email=email, short_description=short_description, description=description, url=url, creator_name=creator_name, twitter=twitter, instagram=instagram, facebook=facebook, portfolio=portfolio, slug=slug) project.save() response = jsonify({ 'id': project.id, 'url': '/' + project.slug, 'date_created': project.date_created, 'date_modified': project.date_modified }) response.status_code = 201 return response else: response = jsonify({'error': 'Missing required fields'}) response.status_code = 401 return response else: #GET projects = Project.get_all() results = [] for project in projects: results.append(project.to_dict()) response = jsonify(results) response.status_code = 200 return response