matiasmenares/Nissboard

View on GitHub
dashboard/api/settings/channels/consult.py

Summary

Maintainability
D
2 days
Test Coverage
Similar blocks of code found in 2 locations. Consider refactoring.
from flask_restful import Resource
Similar blocks of code found in 2 locations. Consider refactoring.
from flask import request, jsonify
Similar blocks of code found in 2 locations. Consider refactoring.
from model.models import db, Consult, ConsultSchema , NissanInput, NissanInputSchema, ChannelInput
Similar blocks of code found in 2 locations. Consider refactoring.
 
Similar blocks of code found in 2 locations. Consider refactoring.
class ConsultChannel(Resource):
Similar blocks of code found in 2 locations. Consider refactoring.
Similar blocks of code found in 2 locations. Consider refactoring.
def get(self):
Similar blocks of code found in 2 locations. Consider refactoring.
consult = Consult.query.all()
Similar blocks of code found in 2 locations. Consider refactoring.
consult_schema = ConsultSchema(many=True)
Similar blocks of code found in 2 locations. Consider refactoring.
return {'consults': consult_schema.dump(consult)}
Similar blocks of code found in 2 locations. Consider refactoring.
 
Similar blocks of code found in 2 locations. Consider refactoring.
def post(self):
Similar blocks of code found in 2 locations. Consider refactoring.
try:
Similar blocks of code found in 2 locations. Consider refactoring.
params = request.json['consult']
Similar blocks of code found in 2 locations. Consider refactoring.
consult_input = NissanInput(name=params['name'], consult=Consult.query.get(params['consult_id']))
Similar blocks of code found in 2 locations. Consider refactoring.
channel_input = ChannelInput(nissan_input=consult_input)
Similar blocks of code found in 2 locations. Consider refactoring.
db.session.add(consult_input)
Similar blocks of code found in 2 locations. Consider refactoring.
db.session.add(channel_input)
Similar blocks of code found in 2 locations. Consider refactoring.
db.session.commit()
Similar blocks of code found in 2 locations. Consider refactoring.
return {'response': True}
Similar blocks of code found in 2 locations. Consider refactoring.
except:
Similar blocks of code found in 2 locations. Consider refactoring.
return {'response': False}, 500
Similar blocks of code found in 2 locations. Consider refactoring.
 
Similar blocks of code found in 2 locations. Consider refactoring.
def patch(self):
Similar blocks of code found in 2 locations. Consider refactoring.
try:
Similar blocks of code found in 2 locations. Consider refactoring.
analog = request.json['analog']
Similar blocks of code found in 2 locations. Consider refactoring.
cursor = self.database.con.cursor()
Similar blocks of code found in 2 locations. Consider refactoring.
input = 1 if analog["input"] == "Voltage" else 0
Similar blocks of code found in 2 locations. Consider refactoring.
cursor.execute("UPDATE analog_channels SET name = ?, pin = ?, voltage_resistance = ? WHERE id = ? ", (analog["name"], analog["pin"], input, str(analog["id"])))
Similar blocks of code found in 2 locations. Consider refactoring.
self.database.con.commit()
Similar blocks of code found in 2 locations. Consider refactoring.
return {'response': True}
Similar blocks of code found in 2 locations. Consider refactoring.
except:
Similar blocks of code found in 2 locations. Consider refactoring.
return {'response': False}