def post_delete(self, obj_key): obj = Product.get_by_key_name(obj_key) # For some reason, obj.user.key.name doesn't work here, so we just figure out what the user key is using the email address. # This is a hack which WILL NOT work if we change how user keys work. Need to figure out the right way to do this. obj_user_key = obj.user.email.split('@')[0] if obj_user_key == self.session['user_key']: Crud.post_delete(self, obj_key) self.redirect('/user/r/'+self.session['user_key']) else: self.redirect('/error/not_owner')
def main(): c = Crud() print(c.insert(nome='Bruno', idade=26)) print(c.insert(nome='Suane', idade=21)) print(c.insert(nome='Teste', idade=99)) print(c.get_by_name('Bruno')) print(c.get_by_name('Suane')) print(c.get_all()) print(c.delete('Teste')) print(c.insert(nome='Teste', idade=99)) print(c.put('Teste', 'Teste Nome Modificado', 30)) print(c.get_all())
idiom_owner: str sale_place: str price_from_expert: Optional[int] price_from_led: Optional[int] price_from_led_em: Optional[int] price_from_committee: Optional[int] class Type(TypeCreate): id: int class Config: orm_mode = True crud = Crud(database, model) def query_all(whereClause=None, ): return crud.query_all(whereClause) def query_by_id(id): return crud.query_by_id(id) def insert_record(record): return crud.insert_record(record) def update_record(id, record):
def run(): db = Crud() while True: fa.limpa_tela() fa.menu_principal() opcao = int(input('Opção: ')) if opcao == 1: fa.menu_cadastro() db.insert() elif opcao == 2: colunas = ['nome', 'descricao', 'carga', 'totaulas', 'ano'] fa.menu_atualizar() idcurso = int( input('\nDigite o ID do curso que deseja atualizar: ')) fa.menu_update() campo = str(input('Escolha um campo para alteração: ')) if campo in '345': novo_valor = int(input('Novo valor: ')) else: novo_valor = str(input('Novo valor: ')).capitalize().strip() campo = int(campo) - 1 db.update(campo=colunas[campo], dado=novo_valor, idcurso=idcurso) elif opcao == 3: fa.menu_excluir() idcurso = int(input('\nDigite o ID do curso que deseja deletar: ')) db.delete(idcurso) elif opcao == 4: while True: fa.menu_consulta() opcao_de_consulta = int(input('Opção: ')) if opcao_de_consulta > 5 or opcao_de_consulta < 1: print('Opção incorreta!') input('Aperte ENTER para tentar novamente...') continue db.select(opcao_de_consulta) break elif opcao == 5: break db.close()
#!/usr/bin/env python import datetime from crud import Crud purge_before_time = datetime.datetime.now() - datetime.timedelta(2) date_str = purge_before_time.strftime("%Y-%m-%d") print "Purgeing routeinfo older than " + date_str crud = Crud("blart") crud.purge_routeinfo(older_than_date_str=date_str)
import csv from crud import Crud import dblib conn = dblib.connectDb("ini/database.ini", "postgresql") from_led = Crud(conn, 'from_led') from_led.clear() with open('all_data.csv', 'r', encoding='utf-8') as f: reader = csv.reader(f) next(reader) #skip first row for row in reader: try: row = [None if 'ไม่มี' in i else i for i in row] id = from_led.insert(row) print("add ", id, "success") except: print("can't add ...") print(from_led.get(1)) print(from_led.get(2)) # print(row) # cur.execute( # "INSERT INTO users VALUES (%s, %s, %s, %s)", # row # )
def add(self, sysNam, grpNam): return Crud.add(self, sysNam, {'name': grpNam, 'path': grpNam})
def __init__(self): Crud.__init__(self, 'groups')
def post_update(self, obj_key): self.session['name'] = self.request.get('name') Crud.post_update(self, self.session['user_key'])
def add(self, sysNam, login, fullName, email, **opts): return Crud.add(self, sysNam, dict( [('name', fullName), ('username', login), ('email', email)] + ('password' in opts and [] or [('password', self.rand_pass())]) + opts.items()))
def __init__(self): Crud.__init__(self, 'users', lambda x: x['username'])
#!/usr/bin/env python3 from crud import Crud table = Crud(user='******', password='******', host='127.0.0.1', port='5432', dbname='postgres', table='cities', primarykey='city') table.connect() table.insert(city='fayoum', address='south of cairo') table.insert_many(columns=('city', 'address'), rows=[['matrooh', 'north'], ['luxor', 'south']]) table.commit() table.select_all() table.select_all(primaryKey_value='luxor') table.select(columns=['address'], primaryKey_value='luxor') table.select(columns=['address']) table.update(column='address', column_value='50 KM south of cairo', primaryKey_value='fayoum')
def __init__(self): Crud.__init__(self, 'projects', lambda x: x['path_with_namespace'])
def add(self, sysNam, prjNam, **opts): return Crud.add(self, sysNam, dict([('name', prjNam)] + opts.items()))
from tkinter import mainloop from crud import Crud poo = Crud() mainloop()
import jwt import datetime from flask import request, jsonify from functools import wraps from crud import Crud from flask_cors import CORS app = flask.Flask(__name__) app.config["DEBUG"] = True app.config[ "SECRET_KEY"] = "7d18c9ad36175d474d6c00cc0d4657a3523875a67e4160f4dda809ba97394a6bf4c712cb72b9b53c26d993a0aad3c9fea880b44542b96253bacce910b0410749" CORS(app) dbo = Crud() responses = { 'no_exception': 'success', 'exception_raised': 'failure', 'success': 'OV1111', 'else_raised': 'OV0000', 'wrong_arguments': 'OV0011', 'no_token': 'OV0022', 'wrong_token': 'OV2200' } # Checks if valid token present in header def req_totoken(f): @wraps(f)
from shapely.geometry import Point, LineString from shapely.ops import nearest_points import csv from crud import Crud import dblib conn = dblib.connectDb( "database.ini" , "postgresql") from_led = Crud( conn , 'from_led') #read Database province = Bangkok and Type = "ที่เปล่า" update_template = select_by_province_template = select * from customer where province = %s #find and list nearest facility #re_data inform of array def appraisal_land_1(re_data): #a = array of similar prop prop_in_bkk = gets_BKK(): factor = [] similar_prop = find_similar(re_data,factors) #factor is array of factor that effect property price estimate_price = find_estimate(similar_prop) # return estimate_price def gets_BKK(): return from_led.gets("province = กรุงเทพฯ") def read_BTS():
from crud import Crud import threading c = Crud() t1 = threading.Thread(target=c.delete, args=(1, )) t2 = threading.Thread(target=c.read, args=(1, )) t3 = threading.Thread(target=c.create, args=( 5, 6, )) t1.start() t2.start() t3.start()
from crud import Crud conn = dblib.connectDb("ini/database.ini", "postgresql") person = Crud(conn, 'person') customer = Crud(conn, 'customer')