def connects(): try: attempt = DanSQL() attempt.off() return True except: return False
def Mastersales(): user = Usuarium() user.set() grab_data = deletings() msg = 'Dan' list = [] if request.method == 'GET': list = DanSQL().get( ' SELECT s.date, c.company_name, s.amount FROM sales s JOIN client c ON s.client_id=c.id;' ) if request.method == 'POST': action = grab_data.action.data selection = grab_data.selection.data msg = f'Not Dan, POST{action}, {selection}' if int(action) == 1: list = DanSQL().get( f"SELECT * from sales WHERE date='{selection}';") msg = f'Not Dan, POST{action}, {selection}' return render_template('mastersales.html', title='HR edit', form=grab_data, list=list, user=user, message=msg) elif int(action) == 2: DanSQL().write(f"DELETE from sales WHERE date='{selection}';") msg = 'Enty deleted successfully' return render_template('mastersales.html', title='HR edit', form=grab_data, list=list, user=user, message=msg)
def what(): user = Usuarium() user.set() grab_data = deleting() msg = 'Dan' list = [] if request.method == 'GET': list = DanSQL().get( 'SELECT hr.date, hr.details, e.nature, hr.manager, hr.amount FROM HR hr JOIN expenses e ON hr.expense_id=e.id;' ) if request.method == 'POST': action = grab_data.action.data selection = grab_data.selection.data msg = '' if int(action) == 1: list = DanSQL().get(f"SELECT * from HR WHERE date='{selection}';") msg = 'This is what you selected' return render_template('masterhr.html', title='HR edit', form=grab_data, list=list, user=user, message=msg) elif int(action) == 2: DanSQL().write(f"DELETE from HR WHERE date='{selection}';") msg = 'Entry deleted' return render_template('masterhr.html', title='HR edit', form=grab_data, list=list, user=user, message=msg)
def navigating_client(editing): msg='' edit = editing.edit.data option_selected=editing.narrow.data chosen_client = editing.select.data if option_selected != None : DanSQL().write(f"UPDATE client SET {option_selected}='{edit}' Where id={chosen_client};") msg= f"{option_selected} updated successfully" return editing, msg
class deletings(FlaskForm): many=[] pairing=dict() for i in DanSQL().get("SELECT date, amount FROM sales;"): fname='£'+str(i[1])+' | '+str(i[0]) pairing[i[0]]=fname while (len(pairing)>0): many.append(pairing.popitem()) action = SelectField('Action ', choices=[(1, 'View'), (2, 'Delete')]) selection = SelectField('select ', choices = many) confirm = SubmitField('Confirm')
def creates(value): DanSQL().write('CREATE DATABASE IF NOT EXISTS testbase;') DanSQL().write('USE testbase;') DanSQL().write('CREATE TABLE IF NOT EXISTS Test(column1 VARCHAR(10));') DanSQL().write(f'INSERT INTO Test(column1) values({str(value)});') var = DanSQL().get('SELECT * FROM Test;') DanSQL().write('DROP DATABASE testbase;') return str(var)
class new_expense(FlaskForm): pairing=dict() for i in DanSQL().get("select * from expenses;"): nature=i[1]+'-'+i[2] pairing[i[0]]=nature many=[] while (len(pairing)>0): many.append(pairing.popitem()) date = StringField('Date ') amount = FloatField('How much ') nature = SelectField('Nature of the expense', choices=many) details = StringField('Reason of the expense') manager= StringField('Manager') add_expense = SubmitField('Add expense')
def employee_logic(grab_data, user): emp_name = grab_data.emp_name.data emp_surname= grab_data.emp_surname.data role = grab_data.role.data team = grab_data.team.data department= user.department() # Department defined automatically if len(emp_name)*len(emp_surname)*len(role)*len(team) != 0 : DanSQL().write(f"INSERT INTO employee(name, surname, position, team, department) VALUES('{emp_name}','{emp_surname}','{role}','{team}','{department}');") grab_data.emp_name.data = grab_data.emp_surname.data = grab_data.role.data = grab_data.team.data = '' msg = 'new employee added' else: msg = 'Please fill in the required fields' return grab_data, msg
class updating(FlaskForm): many=[] pairing=dict() for i in DanSQL().get("SELECT company_name, contact_name, id FROM client;"): fname=str(i[0])+' | '+str(i[1]) pairing[i[2]]=fname while (len(pairing)>0): many.append(pairing.popitem()) listing=[('company_name', 'Company'), ('contact_name', 'Contact'), ('contact_surname', 'Surname'), ('phone', 'Phone'), ('details', 'Details')] edit = StringField('Edit ') select = SelectField('What Client ', choices=many) narrow= SelectField('What field', choices=listing) press = SubmitField('Confirm')
def fexpenses(grab_data, user): amount = grab_data.amount.data details = str(grab_data.details.data) expense_id = int(grab_data.nature.data) manager = user.name() if type(amount)==float and len(details) > 0: DanSQL().write(f"INSERT INTO HR(date, expense_id, amount, details, manager) values (now(), {expense_id}, {amount}, '{details}', '{manager}');") grab_data.details.data = '' msg = 'New expense added' else: msg = 'Please fill in the required fields with valid information' return grab_data, msg
def process_client(grab_data): company_name = grab_data.company_name.data # Assigning value contact_name = grab_data.contact_name.data # to the variables contact_surname = grab_data.contact_surname.data # internally phone = grab_data.phone.data # so we can details= grab_data.details.data # manipulate them # with posterior logic if len(contact_name)*len(company_name)*len(phone) != 0: DanSQL().injects(f"INSERT INTO client(company_name, contact_name, contact_surname, phone, details) VALUES('{company_name}','{contact_name}','{contact_surname}','{phone}','{details}');") grab_data.company_name.data = grab_data.contact_name.data = grab_data.contact_surname.data = '' grab_data.phone.data = grab_data.details.data = '' msg = 'New client added' else: msg='Please, fill in all required fields' return grab_data, msg
def dealfunct(grab_data): try: amount = float(grab_data.amount.data) except: amount = 0 client_id = int(grab_data.client_id.data) employee_id = int(grab_data.employee_id.data) msg='' if amount >0 : DanSQL().write(f"insert into sales(date, client_id, employee_id, amount) values(now(), {client_id}, {employee_id}, {amount});") grab_data.amount.data = '' msg = 'Deal added' else: msg = 'Please fill in the required fields with valid information' return grab_data, msg
app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:[email protected]/main' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SECRET_KEY'] = 'dAnIel52' db = SQLAlchemy(app) """ Now some logic for the app and its routes """ user = Usuarium() # We create an object to control the user login MySQL = DanSQL() @app.route('/home') @app.route('/') def home(): return render_template('home.html') @app.route('/login', methods=['GET', 'POST']) def login(): user = Usuarium() template = 'login.html'