Browse Source

api (#83): premier jet

api/admin/members
Louis Gatin 3 months ago
parent
commit
d2dbb53bdc
  1. 14
      app/models/user.py
  2. 1
      app/routes/__init__.py
  3. 23
      app/routes/api/admin/members.py
  4. 15
      app/routes/api/markdown.py

14
app/models/user.py

@ -17,6 +17,7 @@ import werkzeug.security
import math
import app
import os
import json
class User(UserMixin, db.Model):
@ -137,6 +138,19 @@ class Member(User):
self.signature = ""
self.birthday = None
def to_json(self, admin=False):
"""Returns the json-reprensentation of a user
admin <bool>: if all values may be returned or just public ones """
if admin:
fields = ["name", "norm", "email", "email_confirmed", "xp",
"theme", "bio", "signature", "birthday"]
else:
fields = ["name", "norm", "xp", "bio", "signature"]
output = {i: self.__getattribute__(i) for i in fields}
return json.dumps(output)
def generate_guest_name(self):
"""Generates a unique guest name to transfer contents to."""
count = 0

1
app/routes/__init__.py

@ -9,6 +9,7 @@ from app.routes.polls import vote, delete
from app.routes.posts import edit
from app.routes.programs import index
from app.routes.api import markdown
from app.routes.api.admin import members
try:
from app.routes import test

23
app/routes/api/admin/members.py

@ -0,0 +1,23 @@
from app import app, db
from flask import request, abort
from werkzeug.exceptions import BadRequestKeyError
from app.utils.priv_required import priv_required
from app.models.user import Member
@app.route("/api/admin/members", methods=["GET"])
# @priv_required('misc.admin-panel')
def api_admin_members():
# TODO: add some filtering
# fields = ["name", "points", "misc"]
# try:
# params = {name: request.get_json()[name] for name in fields}
# except BadRequestKeyError:
# abort(400)
members = Member.query.all()
json = "["
json += ",".join([m.to_json(True) for m in members])
json += "]"
return json

15
app/routes/api/markdown.py

@ -3,11 +3,10 @@ from app.utils.filters.markdown import md
from flask import request, abort
from werkzeug.exceptions import BadRequestKeyError
class API():
@app.route("/api/markdown", methods=["POST"])
def api_markdown():
try:
markdown = request.get_json()['text']
except BadRequestKeyError:
abort(400)
return str(md(markdown))
@app.route("/api/markdown", methods=["POST"])
def api_markdown():
try:
markdown = request.get_json()['text']
except BadRequestKeyError:
abort(400)
return str(md(markdown))
Loading…
Cancel
Save