Skip to content

Commit bd75128

Browse files
committed
Make some changes
1 parent 485ba8d commit bd75128

File tree

118 files changed

+3377
-7506
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+3377
-7506
lines changed

.DS_Store

8 KB
Binary file not shown.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ venv/
44
__pycache__/
55
*.swp
66
.env
7+
.python-versionn

Pipfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
faker = "==0.9.0"
8+
flake8 = "==3.6.0"
9+
isort = "==4.3.4"
10+
11+
[packages]
12+
bleach = "==2.1.4"
13+
flask = "==1.0.2"
14+
flask-migrate = "==2.2.1"
15+
flask-sqlalchemy = "==2.3.2"
16+
Flask-Login = "==0.4.1"
17+
flask-babel = "==0.12.2"
18+
Flask-Login = "==0.4.1"
19+
flask-babel = "0.12.2"
20+
flask-wtf = "==0.14.2"
21+
pymysql = "==0.9.2"
22+
redis = "==2.10.6"
23+
celery = "==4.2.1"
24+
flask-webpack = "*"
25+
26+
[requires]
27+
python_version = "3.7"

app/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,19 @@
77

88

99
def register_blueprints(app):
10-
from .blueprints.home import main_bp
10+
from .blueprints.home import home_bp
1111
from .blueprints.auth import auth_bp
1212
from .blueprints.user import user_bp
13-
from .blueprints.api import api_bp
13+
from .blueprints.ajax import ajax_bp
1414
from .blueprints.admin import admin_bp
1515
from .blueprints.blog import blog_bp
16-
from .blueprints.post import post_bp
1716

18-
app.register_blueprint(main_bp)
17+
app.register_blueprint(home_bp)
1918
app.register_blueprint(auth_bp, url_prefix='/auth')
2019
app.register_blueprint(user_bp, url_prefix='/user/<username>')
21-
app.register_blueprint(api_bp, url_prefix='/api')
20+
app.register_blueprint(ajax_bp, url_prefix='/ajax')
2221
app.register_blueprint(admin_bp, url_prefix='/admin')
2322
app.register_blueprint(blog_bp, url_prefix='/blog')
24-
app.register_blueprint(post_bp, url_prefix='/post')
2523

2624

2725
def register_shell_context(app):

app/blueprints/ajax/__init__.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import re
2+
3+
from flask import Blueprint, current_app
4+
5+
ajax_bp = Blueprint('ajax', __name__)
6+
7+
8+
@ajax_bp.after_request
9+
def after_request(response):
10+
if current_app.config['ENV'] == 'development':
11+
response.headers['Access-Control-Allow-Origin'] = '*'
12+
response.headers['Access-Control-Allow-Methods'] = 'GET,POST,DELETE,OPTIONS,PUT'
13+
response.headers['Access-Control-Allow-Headers'] = 'Content-Type'
14+
return response
15+
16+
17+
@ajax_bp.route('/notifications/<int:notification_id>/read')
18+
def set_notification_read(notification_id):
19+
pass
20+
21+
22+
# from flask._compat import with_metaclass
23+
#
24+
# from flask.views import View, MethodView
25+
# MODULE_NAME_REGEX = re.compile(r'app\.api\.')
26+
# class ApiViewType(type):
27+
# def __new__(mcls, name, *bases, **attrs):
28+
# return type.__new__(mcls, name, *bases, **attrs)
29+
#
30+
# def __init__(cls, name, *bases, **attrs):
31+
# super(ApiViewType, cls).__init__(name, *bases, **attrs)
32+
#
33+
#
34+
# class ApiView(with_metaclass(ApiViewType, View)):
35+
# def dispatch_request(self, *args, **kwargs):
36+
# pass
37+
#
38+
#
39+
# def api_route(rule=None, **options):
40+
# def decorator(func):
41+
# nonlocal rule
42+
# rule_prefix = get_rule_prefix(func.__module__)
43+
# if not rule:
44+
# rule = '/%s/%s' % (rule_prefix, func.__name__)
45+
# else:
46+
# assert rule.startswith('/') is True, 'The rule should start with \'/\'.'
47+
# rule = '/%s%s' % (rule_prefix, rule)
48+
# endpoint = options.pop("endpoint", func.__name__)
49+
# add_url_rule(rule, endpoint, func, **options)
50+
# return func
51+
#
52+
# def get_rule_prefix(func_module):
53+
# name = MODULE_NAME_REGEX.split(func_module)[-1]
54+
# return name.replace('.', '/') if '.' in name else name
55+
#
56+
# def add_url_rule(rule, endpoint, func, **options):
57+
# ajax_bp.add_url_rule(rule, endpoint, func, **options)
58+
#
59+
# return decorator
60+
#
61+
62+
from . import notificaton

app/blueprints/ajax/notificaton.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from flask import jsonify
2+
from flask_login import login_required, current_user
3+
4+
from app.models import Notification
5+
from . import ajax_bp
6+
7+
8+
@ajax_bp.route('/notifications')
9+
@login_required
10+
def notifications():
11+
notifications = current_user.notifications.filter_by(is_read=False).order_by(Notification.timestamp.desc()).all()
12+
notifications = [item.content for item in notifications]
13+
14+
return jsonify(notifications)

app/blueprints/api/__init__.py

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +0,0 @@
1-
import re
2-
3-
from flask import Blueprint, current_app
4-
from flask._compat import with_metaclass
5-
6-
from flask.views import View, MethodView
7-
8-
MODULE_NAME_REGEX = re.compile(r'app\.api\.')
9-
10-
api_bp = Blueprint('api', __name__)
11-
12-
13-
@api_bp.after_request
14-
def after_request(response):
15-
if current_app.config['ENV'] == 'development':
16-
response.headers['Access-Control-Allow-Origin'] = '*'
17-
response.headers['Access-Control-Allow-Methods'] = 'GET,POST,DELETE,OPTIONS,PUT'
18-
response.headers['Access-Control-Allow-Headers'] = 'Content-Type'
19-
return response
20-
21-
22-
class ApiViewType(type):
23-
def __new__(mcls, name, *bases, **attrs):
24-
return type.__new__(mcls, name, *bases, **attrs)
25-
26-
def __init__(cls, name, *bases, **attrs):
27-
super(ApiViewType, cls).__init__(name, *bases, **attrs)
28-
29-
30-
class ApiView(with_metaclass(ApiViewType, View)):
31-
def dispatch_request(self, *args, **kwargs):
32-
pass
33-
34-
35-
def api_route(rule=None, **options):
36-
def decorator(func):
37-
nonlocal rule
38-
rule_prefix = get_rule_prefix(func.__module__)
39-
if not rule:
40-
rule = '/%s/%s' % (rule_prefix, func.__name__)
41-
else:
42-
assert rule.startswith('/') is True, 'The rule should start with \'/\'.'
43-
rule = '/%s%s' % (rule_prefix, rule)
44-
endpoint = options.pop("endpoint", func.__name__)
45-
add_url_rule(rule, endpoint, func, **options)
46-
return func
47-
48-
def get_rule_prefix(func_module):
49-
name = MODULE_NAME_REGEX.split(func_module)[-1]
50-
return name.replace('.', '/') if '.' in name else name
51-
52-
def add_url_rule(rule, endpoint, func, **options):
53-
api_bp.add_url_rule(rule, endpoint, func, **options)
54-
55-
return decorator
56-
57-
58-
from . import auth, image, post, user, tag, category

app/blueprints/api/auth.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/blueprints/api/category.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

app/blueprints/api/error.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)