Skip to content
baseresource.py 720 B
Newer Older
Davide Ricci's avatar
Davide Ricci committed
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'''Estension of flask_restx Resource to pass the device in the constructor'''

# System modules
from datetime import datetime

Davide Ricci's avatar
Davide Ricci committed
# Third-party modules
from flask_restx import Resource

Davide Ricci's avatar
Davide Ricci committed

Davide Ricci's avatar
Davide Ricci committed
class ResourceDev(Resource):
Davide Ricci's avatar
Davide Ricci committed
    '''Add the device to the constructor of the Resource class.
Davide Ricci's avatar
Davide Ricci committed
    So other resources will inherit from this,
    without always passing it to the constructor'''

    def __init__(self, *args, **kwargs):
        '''Constructor.'''
        super().__init__(self, *args, **kwargs)
        self.dev = kwargs["dev"]

    @property
    def timestamp(self):
        """Generate a iso timestamp"""
        clock = datetime.utcnow().isoformat()
        return clock