本文整理匯總了Python中config.DB類的典型用法代碼示例。如果您正苦於以下問題:Python DB類的具體用法?Python DB怎麽用?Python DB使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了DB類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: GET
def GET(self):
i = web.input(id=None)
try:
DB.update('eventos', where='id=$i.id', user_state='t', vars=locals())
except:
print "Error Inesperado /user/updateevent:", sys.exc_info()
raise web.seeother('/eventos')
示例2: GET
def GET(self):
i = web.input(id=None)
try:
DB.delete('usuarios', where="id=" + i.id)
except:
print "Error Inesperado /deleteuser:", sys.exc_info()
raise web.seeother('/listuser')
示例3: setUp
def setUp(self):
DB.delete('articles', where='1=1')
self.a = article.Article()
self.a.url = test_url1
self.a.title = 'Test title'
self.a.description = 'Test description'
self.a.save()
示例4: set_record
def set_record(self):
try:
high_score = DB.store_get('high_score')
except KeyError:
high_score = 0
if high_score < self.score:
DB.store_put('high_score', self.score)
DB.store_sync()
示例5: GET
def GET(self):
i = web.input(id=None)
#print "****************************** Update Event:", i.id
try:
DB.update('eventos', where='id=$i.id', admin_state='t', vars=locals())
except:
print "Error Inesperado /updateevent:", sys.exc_info()
#return updateevent
raise web.seeother('/managevents')
示例6: save
def save(model):
for item in model:
DB.insert(
'galleries',
name=item['name'],
num_collections=item['num_collections'],
num_images=item['num_images'],
cover_thumb=item['cover_thumb'],
last_update=item['last_update']
)
示例7: change_sound
def change_sound(self, *args):
global SOUND
button = args[0]
SOUND = not SOUND
button.image.source = 'assets/images/sound_%s.png' % (
SOUND and 'on' or 'off')
DB.store_put('sound', SOUND)
DB.store_sync()
if not SOUND:
self.sound.stop()
示例8: setUp
def setUp(self):
DB.delete('user_articles', where='1=1')
DB.delete('user_sources', where='1=1')
DB.delete('sources', where='1=1')
DB.delete('users', where='1=1')
DB.insert('users', id=user_id, name='Guest')
self.s = source.Source(type='feed', url=test_url1)
self.us = source.UserSource(user_id=user_id, source_id=self.s.id)
示例9: update_session
def update_session(session_id):
'''Increments the evaluation pair for a session'''
result = DB.select(SESSION_DB_NAME, where='session_id=%d' % session_id, \
what='num_eval')
num_eval = result[0]['num_eval'] + 1
DB.update(SESSION_DB_NAME, where='session_id=%d' % session_id,
num_eval=num_eval)
return num_eval
示例10: set_theme
def set_theme(self, theme=None, *args):
if not theme:
theme = DB.store_get('theme')
self.theme = theme
self.background = THEME.get(theme).get('background')
self.labels = THEME.get(theme).get('labels')
self.free_place_notifier = THEME[self.theme]['labels']
self.change_board_color(self.labels)
Window.clearcolor = self.background
DB.store_put('theme', theme)
DB.store_sync()
示例11: get_videos
def get_videos(session_id, pair_number):
'''Gets the pair id for the round of the given user (session id)'''
result = DB.select(SESSION_DB_NAME,
where='session_id=%d' % session_id, what='round_rbn')
round_num = result[0]['round_rbn']
result = DB.select(PAIRS_DB_NAME,
where='pair_num=%d AND round_rbn=%d' % (pair_number, round_num),
what='video_id1,video_id2')
row = result[0]
return row['video_id1'], row['video_id2']
示例12: add_id
def add_id(session_id):
'''Adds new id to the session database'''
round_select = DB.select(ROUND_ROBIN_DB_NAME)[0]
curr_round = round_select['current_round']
total_rounds = round_select['total_rounds']
DB.insert(SESSION_DB_NAME, session_id=session_id, round_rbn=curr_round,
num_eval=0)
next_round = (curr_round + 1) % total_rounds
return DB.update(ROUND_ROBIN_DB_NAME,
where='current_round=%d' % curr_round, current_round=next_round)
示例13: num_pairs
def num_pairs(session_id):
'''
Simply counts the number of rows in the pairs for the round of the
given user.
'''
result = DB.select(SESSION_DB_NAME,
where='session_id=%d' % session_id, what='round_rbn')
round_num = result[0]['round_rbn']
count = 0
for _ in DB.select(PAIRS_DB_NAME, where='round_rbn=%d' % round_num):
count += 1
return count
示例14: POST
def POST(self):
from appForm import formClient
f = formClient()
if f.validates():
try:
telefonos = {'fijo':f.d.fijo, 'celular':f.d.celular, 'pbx':f.d.pbx, 'fax':f.d.fax}
try:
nombres = f.d.nombres.split(' ')
apellidos = f.d.apellidos.split(' ')
nombres.append('')
apellidos.append('')
except:
print "Error Inesperado1 /addclient:", sys.exc_info()
return renderbase_admin.addclient(web.ctx.session, f, msgerr='Los Nombre o Apellidos no son validos.')
sequence_id = DB.insert('clientes', documento=f.d.documento, tipo_docu=f.d.tipo_docu, fecha_naci=f.d.fecha_naci,
direccion=f.d.direccion.lower(), ciudad=f.d.ciudad, sexo_id=f.d.sexo_id, email=f.d.email.lower(),
nombre1=nombres[0].lower(), nombre2=nombres[1].lower() or None,
apellido1=apellidos[0].lower(), apellido2=apellidos[1].lower() or None)
from db import insertPhone
insertPhone(telefonos, client_id=sequence_id)
except:
print "Error Inesperado2 /addclient:", sys.exc_info()
return renderbase_admin.addclient(web.ctx.session, f, msgerr='El Cliente: %s %s, ya existe' % (f.d.nombres, f.d.apellidos))
return renderbase_admin.addclient(web.ctx.session, f, u'El Cliente: %s %s, se ha creado con éxito!' % (f.d.nombres, f.d.apellidos))
else:
return renderbase_admin.addclient(web.ctx.session, f, msgerr=u'Los datos no son válidos.')
示例15: POST
def POST(self, name):
user = web.input('user')['user']
desc = web.input(desc=None)['desc']
machine = load_machine(name)
if machine.locked:
raise web.Forbidden()
if machine.type == 'vps':
curkey = machine.sshpubkey
else:
curkey, getstatus = get_sshkey(name)
if getstatus != 0:
curkey = machine.sshpubkey
if machine.sshpubkey != curkey:
newkey = curkey
else:
newkey = machine.sshpubkey
res = DB.update('machine', where='name = $name AND locked = false',
vars=dict(name=name),
locked=True,
description=desc,
sshpubkey=newkey,
locked_by=user,
locked_since=web.db.SQLLiteral('NOW()'))
assert res == 1, 'Failed to lock machine {name}'.format(name=name)
print user, 'locked single machine', name, 'desc', desc