Example #1
0
    def get(self, year, month, day):
        if UserController.not_admin(current_identity):
            return {
                "message":
                "Only the priveleged can come here. Get out peasant."
            }, 400

        if safe_str_cmp(day, "all"):
            error_message, response = ThemeController.get_for_month(
                year, month)
        elif day.isdigit():
            error_message, response = ThemeController.get_for_day(
                year, month, int(day))
        else:
            return {"message": "Unsupported mode of get"}, 400

        if error_message:
            return {"message": error_message}, 500
        else:
            return {
                "response": list(map(lambda x: x.json()
                                     if x else "", response))
            }
Example #2
0
    def get(self, year, month, day):
        auth_header = request.headers.get('Authorization')
        if auth_header:
            access_token = auth_header.split(" ")[1]
        else:
            return {"message": "This method requires an authorization header."}, 400
        error, client_id = auth_by_token(access_token)
        if error:
            return {"message": error}, 401

        if UserController.not_admin(client_id):
            return {"message": "Only the priveleged can come here. Get out peasant."}, 401

        if safe_str_cmp(day, "all"):
            error_message, response = ThemeController.get_for_month(year, month)
        elif day.isdigit():
            error_message, response = ThemeController.get_for_day(year, month, int(day))
        else:
            return {"message": "Unsupported mode of get"}, 400

        if error_message:
            return {"message": error_message}, 500
        else:
            return {"response": list(map(lambda x: x.json() if x else "", response))}