Skip to content

Commit

Permalink
style: add article query validate form, common utils
Browse files Browse the repository at this point in the history
  • Loading branch information
FesonX committed Jul 12, 2020
1 parent 95a5319 commit 0f68036
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding:utf-8 _*-
"""
@file: enums.py
@time: 2020-07-12 16:41
@author:FesonX
@contact: fesonx@foxmail.com
@site: github.com/FesonX
@software: PyCharm
"""


class HttpMethod:
POST = 'POST'
GET = 'GET'
PUT = 'PUT'
PATCH = 'PATCH'
DELETE = 'DELETE'
OPTIONS = 'OPTIONS'
12 changes: 11 additions & 1 deletion src/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@software: PyCharm
"""

from wtforms import StringField, Form
from wtforms import StringField, Form, IntegerField
from wtforms.validators import DataRequired


Expand All @@ -19,3 +19,13 @@ class ArticleForm(Form):
body = StringField(label='body', validators=[DataRequired(message='Article body is required')])
summary = StringField(label='summary')
tags = StringField(label='tags')


class QueryForm(Form):
author = StringField(label='author')
title = StringField(label='article')
column = StringField(label='column')
page = IntegerField(label='page', default=1)
per_page = IntegerField(label='per_page', default=20)
tags = StringField(label='tags')
create_time = IntegerField(label='create_time')
26 changes: 26 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding:utf-8 _*-
"""
@file: utils.py
@time: 2020-07-12 16:54
@author:FesonX
@contact: fesonx@foxmail.com
@site: github.com/FesonX
@software: PyCharm
"""
from flask import request


def dispatch_request(fn_mapping: dict):
fn = fn_mapping[request.method]
return fn()


def row2dict(instance, *args, **kwargs):
"""
convert SQLAlchemy instance to dict
:param instance:
:param args:
:param kwargs:
:rtype: dict
"""
return {c.name: getattr(instance, c.name, None) for c in instance.__table__.columns}

0 comments on commit 0f68036

Please sign in to comment.