get_parser.add_argument('name', type=str)
get_parser.add_argument('start_date', type=inputs.date)
get_parser.add_argument('end_date', type=inputs.date)
get_parser.add_argument('from', type=int, required=True)
get_parser.add_argument('to', type=int, required=True)

session_post_model = api.model(
    'session_post_model', {
        'pilot_id':
        fields.Integer(description='ID of Pilot', required=True),
        'session_date':
        fields.Date(required=True),
        'start_time':
        TimeFormat(description='Time in 24 hour HH:MM format',
                   required=True,
                   default='HH:MM'),
        'end_time':
        TimeFormat(description='Time in 24 hour HH:MM format',
                   default='HH:MM'),
        'is_leader':
        fields.Boolean(required=True),
        'guest_name':
        fields.String(),
        'guest_info':
        fields.String()
    })

session_put_model = api.model(
    'session_put_model', {
        'guest_name': fields.String(),
        'guest_info': fields.String(),
        'end_time': fields.DateTime(),
#   *** settings.py ***
#   - implementiert das Aktualisieren von settings.json
#   - Autor: Max Haufe
#   - Mail: [email protected]

import json

from flask_restx import Resource

from sync import sync_settings
from globals import api, get_connection, is_admin, auth_parser

settings_post_model = api.model('settings_post_model', {})


# POST /settings
# der body der request wird als settings.json gespeichert
# nur admins dürfen diese request ausführen
class Settings(Resource):
    @api.expect(settings_post_model, auth_parser)
    def post(self):
        '''post settings to server'''

        connection = get_connection("database_server.db")
        cursor = connection.cursor()

        if not is_admin(cursor):
            connection.close()
            return {}, 401

        file = open('settings.json', 'w')
#   - nach POST oder PUT werden Piloten mit Terminal synchronisiert
#   - Autor: Max Haufe
#   - Mail: [email protected]

from sync import sync_pilots
from flask_restx import Resource, inputs, fields
from globals import api, get_connection, auth_parser, is_admin

pilots_parser = api.parser()
pilots_parser.add_argument('id', type=int)
pilots_parser.add_argument('is_active', type=inputs.boolean)

pilot_post_model = api.model('pilot_post_model', {
    'pilot_name': fields.String(description='Vorname des Piloten', required=True),
    'pilot_surname': fields.String(description='Nachname des Piloten', required=True),
    'rfid': fields.String(description='RFID Tag des Piloten', required=True),
    'pilot_username': fields.String(description='Benutzername des Piloten', required=True),
    'is_admin': fields.Boolean(required=True)
})

pilot_put_model = api.model('pilot_put_model', {
    'pilot_id': fields.Integer(description='PilotID', required=True),
    'pilot_name': fields.String(description='Vorname des Piloten'),
    'pilot_surname': fields.String(description='Nachname des Piloten'),
    'rfid': fields.String(description='RFID Tag des Piloten'),
    'pilot_username': fields.String(description='Benutzername des Piloten'),
    'reset_password': fields.Boolean(description='Setzt das Passwort des Piloten auf NULL, wenn true'),
    'is_admin': fields.Boolean
})

Пример #4
0
#   *** rfid.py ***
#   - implementiert das hinzufügen von RFID Tags
#   - Autor: Max Haufe
#   - Mail: [email protected]

from flask_restx import Resource, fields
from sync import sync_rfids
from globals import api, get_connection, auth_parser, is_admin

rfid_post_model = api.model('rfid_post_model', {
    'rfid': fields.String()
})


# POST /rfid
# nur admins dürfen diese request ausführen
# der rfid tag ist als string (hex) im body enthalten
class Rfid(Resource):
    @api.expect(auth_parser, rfid_post_model)
    def post(self):
        '''add RFID Tags to DB'''
        connection = get_connection("database_server.db")
        cursor = connection.cursor()

        payload = api.payload

        if not is_admin(cursor):
            return {}, 401

        cursor.execute(
            'INSERT INTO RFID_Ausweis (RFID_Code, Synced) VALUES (?, FALSE)', [int(payload['rfid'], 16)]