summaryrefslogtreecommitdiff
path: root/archivist/server.py
blob: 8500af0e5fc2908a83cbd15b14814937398b9bb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import click
from flask.cli import FlaskGroup, ScriptInfo
from flask import Flask
from flask_restful import Api, Resource, marshal_with, marshal_with_field, fields

from . import model as m

class Tag(Resource):
    tag_fields = {
            'name' : fields.String,
            'prefix' : fields.String
            }

class TagList(Resource):
    tag_list = { fields.List(fields.Nested(Tag.tag_fields)) }

    @marshal_with_field(fields.List(fields.Nested(Tag.tag_fields)))
    def get(self):
        res = list(m.Tag.select().where(~m.Tag.default).dicts().iterator())
        print(res)
        return res

def create_app(info):
    app = Flask('archivist')
    api = Api(app)
    api.add_resource(TagList, '/')
    return app

server_group = FlaskGroup(
        name='server',
        context_settings = {'obj' : ScriptInfo(create_app=create_app)})