mirror of
https://github.com/Michatec/MiniFaceBook.git
synced 2026-03-31 23:46:30 +02:00
API Events Moved
This commit is contained in:
14
main.py
14
main.py
@@ -15,7 +15,7 @@ from routes.user import user_bp
|
|||||||
from routes.friends import friends_bp
|
from routes.friends import friends_bp
|
||||||
from routes.notifications import noti_bp
|
from routes.notifications import noti_bp
|
||||||
from routes.credits import credits_bp
|
from routes.credits import credits_bp
|
||||||
from models import db, User, Reward, Event, UserShopItem, ShopItem, SHOPITEM_ID_PREMIUM, SHOPITEM_ID_GOLDRAHMEN, SHOPITEM_ID_EXTRA_TYPES, SHOPITEM_ID_EXTRA_UPLOAD
|
from models import db, User, Reward, UserShopItem, ShopItem, SHOPITEM_ID_PREMIUM, SHOPITEM_ID_GOLDRAHMEN, SHOPITEM_ID_EXTRA_TYPES, SHOPITEM_ID_EXTRA_UPLOAD
|
||||||
try:
|
try:
|
||||||
from routes.oauth import oauth
|
from routes.oauth import oauth
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -185,18 +185,6 @@ def setup():
|
|||||||
return redirect(url_for('log.login'))
|
return redirect(url_for('log.login'))
|
||||||
return render_template('setup.html')
|
return render_template('setup.html')
|
||||||
|
|
||||||
@app.route('/api/events')
|
|
||||||
@login_required
|
|
||||||
def api_events():
|
|
||||||
if not current_user.is_admin:
|
|
||||||
abort(403)
|
|
||||||
|
|
||||||
events = db.session.query(Event).order_by(Event.timestamp.desc()).limit(20).all()
|
|
||||||
return jsonify([
|
|
||||||
{"timestamp": e.timestamp.strftime('%Y-%m-%d %H:%M'), "message": e.message}
|
|
||||||
for e in events
|
|
||||||
])
|
|
||||||
|
|
||||||
@app.route('/shop', methods=['GET', 'POST'])
|
@app.route('/shop', methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def shop():
|
def shop():
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from flask import Blueprint, jsonify, redirect, request, url_for, flash, render_template
|
from flask import Blueprint, jsonify, redirect, request, url_for, flash, render_template, abort
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
from models import User, db, Notification
|
from models import User, db, Notification, Event
|
||||||
from flask_babel import gettext as _
|
from flask_babel import gettext as _
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ def notifications():
|
|||||||
notifications = db.session.query(Notification).filter_by(user_id=current_user.id).order_by(Notification.created_at.desc()).all()
|
notifications = db.session.query(Notification).filter_by(user_id=current_user.id).order_by(Notification.created_at.desc()).all()
|
||||||
return render_template('notifications.html', notifications=notifications)
|
return render_template('notifications.html', notifications=notifications)
|
||||||
|
|
||||||
@noti_bp.route('/notifications_api')
|
@noti_bp.route('/api/notifications')
|
||||||
@login_required
|
@login_required
|
||||||
def notifications_api():
|
def notifications_api():
|
||||||
expire_time = datetime.now() - timedelta(days=3)
|
expire_time = datetime.now() - timedelta(days=3)
|
||||||
@@ -48,3 +48,15 @@ def notifications_api():
|
|||||||
} for n in notifications
|
} for n in notifications
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@noti_bp.route('/api/events')
|
||||||
|
@login_required
|
||||||
|
def api_events():
|
||||||
|
if not current_user.is_admin:
|
||||||
|
abort(403)
|
||||||
|
|
||||||
|
events = db.session.query(Event).order_by(Event.timestamp.desc()).limit(20).all()
|
||||||
|
return jsonify([
|
||||||
|
{"timestamp": e.timestamp.strftime('%Y-%m-%d %H:%M'), "message": e.message}
|
||||||
|
for e in events
|
||||||
|
])
|
||||||
Reference in New Issue
Block a user