<commit_before>from flask_restful import Resource, reqparse
from flask import jsonify
from sunpower import db
from agents.models import Agent
parser = reqparse.RequestParser()


class AgentDetail(Resource):
    @staticmethod
    def get(_id):
        agent = Agent.query.filter_by(id=_id).first()

        if agent is None:
            return jsonify({})
        else:
            return jsonify(agent)

    @staticmethod
    def put(_id):
        data = parser.parse_args()
        agent = Agent.query.filter_by(id=_id).first()
        if agent is not None:
            agent.email = data.get('email', None)
            agent.phone_number = data.get('phone_number', None)
            agent.username = data.get('username', None)

            db.commit()

        return jsonify(agent)

    @staticmethod
    def delete(_id):
        Agent.query.filter_by(id=_id).delete()
        return jsonify({'OK': 'Deleted'})


class AgentList(Resource):
    @staticmethod
    def get():
        agents = Agent.query.filter_by().all()
        return jsonify(agents)

    @staticmethod
    def post():
        data = parser.parse_args()
        agent = Agent(email=data.email, username=data.name, phone_number=data.phone_nubmer)
        with agent:
            db.session.add(agent)
            db.commit()<commit_msg>- view post params<commit_after>from flask_restful import Resource, reqparse
from flask import jsonify
from sunpower import db
from agents.models import Agent
parser = reqparse.RequestParser()


class AgentDetail(Resource):
    @staticmethod
    def get(_id):
        agent = Agent.query.filter_by(id=_id).first()

        if agent is None:
            return jsonify({})
        else:
            return jsonify(agent)

    @staticmethod
    def put(_id):
        data = parser.parse_args()
        agent = Agent.query.filter_by(id=_id).first()
        if agent is not None:
            agent.email = data.get('email', None)
            agent.phone_number = data.get('phone_number', None)
            agent.username = data.get('username', None)

            db.commit()

        return jsonify(agent)

    @staticmethod
    def delete(_id):
        Agent.query.filter_by(id=_id).delete()
        return jsonify({'OK': 'Deleted'})


class AgentList(Resource):
    @staticmethod
    def get():
        agents = Agent.query.filter_by().all()
        return jsonify(agents)

    @staticmethod
    def post():
        data = parser.parse_args()
        agent = Agent(email=data.email, username=data.username, phone_number=data.phone_nubmer)
        with agent:
            db.session.add(agent)
            db.commit()
{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.0, 'mean_word_length': 2.389391979301423, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1494953', 'n_tokens_mistral': 766, 'n_tokens_neox': 750, 'n_words': 178}