<reponame>juananpe/forum40<filename>backend/db/db_models.py
from flask_restplus import reqparse, inputs

group_by_model = reqparse.RequestParser()
group_by_model.add_argument('granularity', type=str, choices=['day', 'month', 'year'], default='month')
group_by_model.add_argument('label', type=int, default=None)
group_by_model.add_argument('keyword', action='append', default=lambda: [])
group_by_model.add_argument('source_id', type=int, required=True)

comments_parser_sl = reqparse.RequestParser()
comments_parser_sl.add_argument('label', action='append', type=int, default=lambda: [])
comments_parser_sl.add_argument('keyword', action='append', default=lambda: [])
comments_parser_sl.add_argument('source_id', type=int, required=True)
comments_parser_sl.add_argument('order', type=int, default=2)
comments_parser_sl.add_argument('label_sort_id', type=int, default=None)
comments_parser_sl.add_argument('skip', type=int, default=0, required=True)
comments_parser_sl.add_argument('limit', type=int, default=50, required=True)
comments_parser_sl.add_argument('category', type=str, default=None)

comment_parser = reqparse.RequestParser()
comment_parser.add_argument('label', action='append', default=lambda: [])

source_parser = reqparse.RequestParser()
source_parser.add_argument('name', required=True)
source_parser.add_argument('domain', required=True)

document_list_parser = reqparse.RequestParser()
document_list_parser.add_argument('source_id', required=True, type=int)
document_list_parser.add_argument('limit', type=int, default=50, required=True)
document_list_parser.add_argument('skip', type=int, default=0, required=True)

document_parser = reqparse.RequestParser()
document_parser.add_argument('url', required=True)
document_parser.add_argument('title', required=True)
document_parser.add_argument('text', required=True)
document_parser.add_argument('timestamp', required=True, type=inputs.datetime_from_iso8601)
document_parser.add_argument('metadata', default="")
document_parser.add_argument('source_id', required=True, type=int)
document_parser.add_argument('external_id', required=True)
document_parser.add_argument('category')

comment_parser_post = reqparse.RequestParser()
comment_parser_post.add_argument('doc_id', default=None, type=int)
comment_parser_post.add_argument('source_id', required=True, type=int)
comment_parser_post.add_argument('user_id', default=None, type=int)
comment_parser_post.add_argument('parent_comment_id', default=None, type=int)
comment_parser_post.add_argument('status', default=None)
comment_parser_post.add_argument('title', required=True)
comment_parser_post.add_argument('text', required=True)
comment_parser_post.add_argument('embedding', default=None)
comment_parser_post.add_argument('timestamp', required=None, type=inputs.datetime_from_iso8601)
comment_parser_post.add_argument('external_id', required=None)


default_comment = '''
[{
    "source_id" : "999",
    "title": "...",
    "text": "...",
    "timestamp" : "2020-02-11T23:42:00+01:00",
    "external_id" : "42"
},
{
    "source_id" : "999",
    "title": "...",
    "text": "...",
    "timestamp" : "2020-02-11T23:42:00+01:00",
    "external_id" : "43"
}]
'''

comments_list_parser = reqparse.RequestParser()
comments_list_parser.add_argument('comments', type=str, default=default_comment, location='json')


label_parser_post = reqparse.RequestParser()
label_parser_post.add_argument('description', required=True, default="")

from flask_restplus import reqparse, inputs

group_by_model = reqparse.RequestParser()
group_by_model.add_argument('granularity', type=str, choices=['day', 'month', 'year'], default='month')
group_by_model.add_argument('label', type=int, default=None)
group_by_model.add_argument('keyword', action='append', default=lambda: [])
group_by_model.add_argument('source_id', type=int, required=True)

comments_parser_sl = reqparse.RequestParser()
comments_parser_sl.add_argument('label', action='append', type=int, default=lambda: [])
comments_parser_sl.add_argument('keyword', action='append', default=lambda: [])
comments_parser_sl.add_argument('source_id', type=int, required=True)
comments_parser_sl.add_argument('order', type=int, default=2)
comments_parser_sl.add_argument('label_sort_id', type=int, default=None)
comments_parser_sl.add_argument('skip', type=int, default=0, required=True)
comments_parser_sl.add_argument('limit', type=int, default=50, required=True)
comments_parser_sl.add_argument('category', type=str, default=None)

comment_parser = reqparse.RequestParser()
comment_parser.add_argument('label', action='append', default=lambda: [])

source_parser = reqparse.RequestParser()
source_parser.add_argument('name', required=True)
source_parser.add_argument('domain', required=True)

document_list_parser = reqparse.RequestParser()
document_list_parser.add_argument('source_id', required=True, type=int)
document_list_parser.add_argument('limit', type=int, default=50, required=True)
document_list_parser.add_argument('skip', type=int, default=0, required=True)

document_parser = reqparse.RequestParser()
document_parser.add_argument('url', required=True)
document_parser.add_argument('title', required=True)
document_parser.add_argument('text', required=True)
document_parser.add_argument('timestamp', required=True, type=inputs.datetime_from_iso8601)
document_parser.add_argument('metadata', default="")
document_parser.add_argument('source_id', required=True, type=int)
document_parser.add_argument('external_id', required=True)
document_parser.add_argument('category')

comment_parser_post = reqparse.RequestParser()
comment_parser_post.add_argument('doc_id', default=None, type=int)
comment_parser_post.add_argument('source_id', required=True, type=int)
comment_parser_post.add_argument('user_id', default=None, type=int)
comment_parser_post.add_argument('parent_comment_id', default=None, type=int)
comment_parser_post.add_argument('status', default=None)
comment_parser_post.add_argument('title', required=True)
comment_parser_post.add_argument('text', required=True)
comment_parser_post.add_argument('embedding', default=None)
comment_parser_post.add_argument('timestamp', required=None, type=inputs.datetime_from_iso8601)
comment_parser_post.add_argument('external_id', required=None)


default_comment = '''
[{
    "source_id" : "999",
    "title": "...",
    "text": "...",
    "timestamp" : "2020-02-11T23:42:00+01:00",
    "external_id" : "42"
},
{
    "source_id" : "999",
    "title": "...",
    "text": "...",
    "timestamp" : "2020-02-11T23:42:00+01:00",
    "external_id" : "43"
}]
'''

comments_list_parser = reqparse.RequestParser()
comments_list_parser.add_argument('comments', type=str, default=default_comment, location='json')


label_parser_post = reqparse.RequestParser()
label_parser_post.add_argument('description', required=True, default="")
[{     "source_id" : "999",     "title": "...",     "text": "...",     "timestamp" : "2020-02-11T23:42:00+01:00",     "external_id" : "42" }, {     "source_id" : "999",     "title": "...",     "text": "...",     "timestamp" : "2020-02-11T23:42:00+01:00",     "external_id" : "43" }]