GithubHelp home page GithubHelp logo

squadran2003 / todo-api-with-flask Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 56 KB

an API for a frontend TODO app built in Angular JS

License: MIT License

Python 67.33% Shell 7.69% JavaScript 11.94% CSS 4.00% HTML 9.03%

todo-api-with-flask's Introduction

TODO-api-with-flask

Flask restful api for a todo app, this app is part of the 10th project as part of teamtreehouse techdegree.

The frontend was built in angularjs

Code Example

    from flask import Blueprint, abort, g
    from flask.ext.restful import (Resource, Api, reqparse,
                                    marshal,marshal_with, fields, url_for)

    import models

    from auth import auth

    todo_fields = {
        'id':fields.Integer,
        'name':fields.String,
    }

    def todo_or_404(todo_id):
        try:
            todo = models.Todo.get(models.Todo.id==todo_id)
        except models.Todo.DoesNotExist:
            abort(404)
        else:
            return todo


    def get_users_todos():
        """this method gets all the todos belonging to the logged in user"""
        todos = models.Todo.select().where(models.Todo.user==g.user)
        return todos


    class TodoList(Resource):
        def __init__(self):
            self.reqparse = reqparse.RequestParser()
            self.reqparse.add_argument(
                'name',
                required = True,
                help = 'No todos title provided',
                location = ['form','json']


            )
            super().__init__()


        @auth.login_required
        @marshal_with(todo_fields)
        def get(self):
            print(g.user.id)
            todos = [marshal(todo,todo_fields) for todo in get_users_todos()]
            return (todos,200,{'Location':url_for('resources.todos.todos')})

Installation

clone the repo, create a virtualenv using python3 and run the commands below

   pip install -r requirements.txt
   python app.py

Tests

To run the tests, follow the commands below

   coverage run tests.py
   coverage report --omit="lib/*"

todo-api-with-flask's People

Contributors

squadran2003 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.