summaryrefslogtreecommitdiff
path: root/archivist/server/prefix.py
blob: f2a747f316de7a53b81ef2a6ca5489a40f9e3e53 (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
from flask_restplus import Resource, fields, Namespace, marshal_with_field

from .. import model as m

api = Namespace('prefix', description = 'Operations on prefixes')

prefix = api.model('Prefix', {
    'name' : fields.String(required=True),
    'description' : fields.String,
    'virtual' : fields.Boolean
})

@api.route('/')
class PrefixList(Resource):
    @api.marshal_list_with(prefix)
    def get(self):
        """List all available non-virtual prefixes."""
        return list(m.Prefix.select().where(~m.Prefix.virtual).dicts().iterator())

@api.route('/all')
class PrefixListAll(Resource):
    @api.marshal_list_with(prefix)
    def get(self):
        """List all available prefixes, including virtual."""
        return list(m.Prefix.select().dicts().iterator())