def admin_load_photos(limit: Optional[str] = None, offset: Optional[str] = None): alias_ass = Assessment.alias('ass') subq = db.select([Assessment]).where(Assessment.photo_id == alias_ass.photo_id).as_scalar() query = db.select((Photo, subq)).select_from(Photo.outerjoin(alias_ass)) query = limit_query(query, limit, offset) return query.gino.load(Photo.load(assessments=subq))
def load_photos(user: User, limit: Optional[str] = None, offset: Optional[str] = None): alias_ass = Assessment.alias('ass') subq = db.select([Assessment.user_id]).where(Assessment.id == alias_ass.id).as_scalar() query = db.select([Photo]).select_from(Photo.outerjoin(alias_ass, or_( and_(alias_ass.user_id == user.id, alias_ass.photo_id == Photo.id), alias_ass.photo_id == None))). \ where(not_(tuple_(user.id).in_(subq))) photos = limit_query(query, limit, offset) return photos.gino
def Get_Menu(): rmenus = db.select('categories', where='parent_id = 0', order='order_id') menus = [] for menu in rmenus: menus += [Menu(menu.name, menu.slug)] return menus
def Get_Menu(): rmenus = db.select('categories',where='parent_id = 0',order='order_id') menus = [] for menu in rmenus: menus += [Menu(menu.name,menu.slug)] return menus
def query_register_block(call_back): user = call_back[1] call_back = call_back[0] while True: function_title(' REGISTER A NEW ESTAR BLOCK ') block = controller_block_card('Enter Estar block code') if not block: continue if block == -1: function_messages(((2, 'Operation canceled'), )) return call_back() block_existent = db.select(""" SELECT blococod FROM estar_bloco WHERE blococod = %d; """ % block) if not len(block_existent): card_ini = controller_block_card( 'Enter code of first Estar block card') if not card_ini: continue if card_ini == -1: function_messages(((2, 'Operation canceled'), )) return call_back() card_fin = controller_block_card( 'Enter code of last Estar block card') if not card_fin: continue if card_fin == -1: function_messages(((2, 'Operation canceled'), )) return call_back() if card_ini <= card_fin: messages = [] if (card_fin - card_ini) != 10: messages.append( (1, 'This block does not contain 10 cards'), ) db.alter(""" INSERT INTO estar_bloco (blococod) VALUES (%d); """ % block) for i in range(card_ini, card_fin + 1): db.alter(""" INSERT INTO estar_cartao (cartaocod, cartao_blococod) VALUES (%d, %d); """ % (i, block)) db.alter(""" INSERT INTO estar_cadastro (cadastrodata, cadastro_blococod, cadastro_codfuncionario) VALUES( datetime("now","localtime"), %d, %d ) """ % (block, user.login)) messages.append((2, 'Estar block successfully registered'), ) function_messages(messages) return call_back() else: function_messages((( 0, 'First card code must be less than or equal to last card code' ), )) else: function_messages( ((0, 'This Estar block has already been registered in the system' ), ))
def Get_Entities(cate_id, _limit): rentities = db.select('details', where='cate_id = %d' % int(cate_id, 10), limit=int(_limit, 10)) entities = [] for e in rentities: entities += [Details(e.id, e.title, e.content)] return entities
def query_employers(call_back): function_title(' EMPLOYERS LIST ') data = db.select(""" SELECT codfuncionario, nomefuncionario FROM funcionario ORDER BY nomefuncionario; """) headers = ('MATRÍCULA', 'NOME') function_table(data, headers) return call_back()
def getDateCountUnknown(): return db.select("SELECT d.date, count(se.id) FROM ( \ select to_char(date_trunc('day', (current_date - offs)), 'YYYY-MM-DD') \ AS date \ FROM generate_series(0, 14, 1) \ AS offs \ ) d \ LEFT OUTER JOIN (SELECT * FROM coincidencias as c WHERE c.propietario = 'Desconocido') se \ ON (d.date=to_char(date_trunc('day', se.created_at), 'YYYY-MM-DD')) \ GROUP BY d.date \ ORDER BY d.date asc;")
async def get_photos(request: Request, user: User): limit = request.args.get('limit') offset = request.args.get('offset', default=0) raise_if_empty(limit, offset) raise_if_not_int(limit, offset) subq = db.select([Assessment.photo_id ]).where(Assessment.user_id == user.id).as_scalar() query = Photo.query.where(not_(Photo.id.in_(subq))) photos = limit_query(query, limit, offset) photos = await photos.gino.all() photos = [{'id': str(photo.id), 'path': photo.path} for photo in photos] return json(photos)
def function_login(user): while True: function_title(' UPDATES ') updates = [{ 'date': '15/08/2019', 'title': 'Test', 'text': 'text.........' }] for update in updates: print(function_indent() + update['date'] + ' - ' + update['title'] + ': ' + update['text'] + ';') function_title(' LOGIN ') login = function_input_number('Login') if not login == -1: password = function_input_number('Password') if not password == -1: password = sha256(str.encode(str(password))).hexdigest() verify = db.select(''' SELECT nomefuncionario, nivel, funcionario_coddepartamento, beneficiario_cartao FROM funcionario WHERE codfuncionario = %d AND senha = "%s"; ''' % (login, password)) if len(verify): user.logged(login, verify[0][0], verify[0][1], verify[0][2], verify[0][3], True) function_messages(( (2, 'Successfully authenticated'), (2, 'Welcome %s' % user.name), )) return user else: function_messages(( (1, 'Invalid authentication'), (0, 'Invalid registration or password'), )) return user
def Get_Shows(): rshows = db.select('shows') shows = [] for s in rshows: shows += [Shows(s.img, s.content)] return shows
def Get_Shows(): rshows = db.select('shows') shows = [] for s in rshows: shows += [Shows(s.img,s.content)] return shows
def Get_Entities(cate_id,_limit): rentities = db.select('details',where='cate_id = %d' % int(cate_id,10),limit = int(_limit,10)) entities = [] for e in rentities: entities += [Details(e.id,e.title,e.content)] return entities
def getCountUnknown(): return db.select( "SELECT count(*) FROM coincidencias as c WHERE c.propietario != 'Desconocido';" )
def getCountUnknownByPlace(): return db.select("SELECT l.nombre, coalesce(count(c.id),0) \ FROM (SELECT DISTINCT lugar as nombre FROM coincidencias) l \ LEFT OUTER JOIN ( \ SELECT * FROM coincidencias WHERE propietario = 'Desconocido' ) c \ ON l.nombre = c.lugar GROUP BY l.nombre;")
def getCountByPlace(): return db.select( 'SELECT lugar, count(*) FROM coincidencias GROUP BY lugar;')