def guardar(self): formulario = FieldStorage() productos = formulario['producto_id'] cantidades = formulario['cantidad'] cliente = formulario['cliente'].value self.model.estado = 1 self.model.fecha = strftime("%Y-%m-%d") self.model.cliente = cliente self.model.insert() self.model.producto_collection = [] if not isinstance(productos, list): productos = [productos] cantidades = [cantidades] for i, elemento in enumerate(productos): pr = Producto() pr.producto_id = elemento.value pr.select() self.model.producto_collection.append(pr) pr.fm = cantidades[i].value cl = LogicalConnector(self.model, 'Producto') cl.insert() redirect("pedido/ver", self.model.pedido_id)
def eliminar(self): self.model.pedido_id = int(ARG) self.model.select() cliente = Factory().make('Cliente', self.model.cliente) self.model.delete() redirect("cliente/ver", cliente.cliente_id)
def actualizar(self): formulario = FieldStorage() cliente_id = formulario['cliente_id'].value nif = formulario['nif'].value denominacion = formulario['denominacion'].value domicilio.calle = formulario['calle'].value domicilio.numero = formulario['numero'].value domicilio.planta = formulario['planta'].value domicilio.puerta = formulario['puerta'].value domicilio.ciudad = formulario['ciudad'].value self.model.cliente_id = cliente_id self.model.select() self.model.nif = nif self.model.denominacion = denominacion self.model.domicilio.calle = calle self.model.domicilio.numero = numero self.model.domicilio.planta = planta self.model.domicilio.puerta = puerta self.model.domicilio.ciudad = ciudad self.model.domicilio.update() self.model.update() redirect("cliente/ver", self.model.cliente_id)
def guardar(self): denominacion = POST['denominacion'].value precio = POST['precio'].value self.model.denominacion = denominacion self.model.precio = precio self.model.insert() redirect("producto/ver/{}".format(self.model.producto_id))
def guardar(self): #calle = Sanitizer.filter_string(POST['calle'].value) #ciudad = Sanitizer.filter_string(POST['ciudad'].value) #denominacion = Sanitizer.filter_string(POST['denominacion'].value) #numero = Sanitizer.convert_to_int(POST['numero'].value) #planta = Sanitizer.convert_to_int(POST['planta'].value) #puerta = Sanitizer.purge_alnum(POST['puerta'].value).upper() #nif = POST['nif'].value calle = POST['calle'].value ciudad = POST['ciudad'].value denominacion = POST['denominacion'].value numero = POST['numero'].value planta = POST['planta'].value puerta = POST['puerta'].value.upper() nif = POST['nif'].value errores = [] if not (numero >= 1 and numero <= 15000): errores.append(ERR_NUMERO_NO_VALIDO) if not (planta >= 0 and planta <= 200): errores.append(ERR_PLANTA_NO_VALIDA) if not (len(puerta) >= 1 and len(puerta) <= 2): errores.append(ERR_PUERTA_NO_VALIDA) if not (len(calle) >= 1 and len(calle) <= 50): errores.append(ERR_CALLE_NO_VALIDA) if not (len(ciudad) >= 4 and len(calle) <= 30): errores.append(ERR_CIUDAD_NO_VALIDA) if errores: variables = locals() for k in POST.keys(): if k in variables: POST[k].value = locals()[k] self.view.agregar(errores, POST) exit() self.model.domicilio = Domicilio() self.model.domicilio.calle = calle self.model.domicilio.numero = numero self.model.domicilio.planta = planta self.model.domicilio.puerta = puerta self.model.domicilio.ciudad = ciudad self.model.domicilio.insert() self.model.denominacion = denominacion self.model.nif = nif self.model.insert() dc = DatoDeContactoController() dc.guardar(POST, self.model.cliente_id) redirect("cliente/ver/{}".format(self.model.cliente_id))
def Cancel(account_id, id, *args, **kwargs): id = int(id) # Cancel sync task if not Sync.cancel(id): # Unable to cancel task return redirect('/sync', account_id=account_id, title='Error', message='Unable to cancel current sync') # Success return redirect('/sync', account_id=account_id)
def actualizar(self): producto_id = get_form_value('producto_id') denominacion = get_form_value('denominacion') precio = get_form_value('precio') self.model.producto_id = producto_id self.model.denominacion = denominacion self.model.precio = precio self.model.update() redirect("producto/ver/{}".format(self.model.producto_id))
class Trigger(object): triggered = {} @classmethod def callback(cls, func, account, section=None): if section: return Callback(func, account_id=account.id, section=section.key, t=timestamp()) return Callback(func, account_id=account.id, t=timestamp()) @classmethod def run(cls, account_id, mode, t, **kwargs): # Check for duplicate trigger key = (account_id, mode, t) if key in cls.triggered: log.info('Ignored duplicate sync trigger action') return redirect('/sync', account_id=account_id) # Mark triggered cls.triggered[key] = True # Trigger sync try: Sync.queue(account_id, mode, **kwargs) except QueueError, ex: return redirect('/sync', account_id=account_id, title=ex.title, message=ex.message) return redirect('/sync', account_id=account_id)
def run(cls, account_id, mode, t, **kwargs): # Check for duplicate trigger key = (account_id, mode, t) if key in cls.triggered: log.info('Ignored duplicate sync trigger action') return redirect('/sync', account_id=account_id) # Mark triggered cls.triggered[key] = True # Trigger sync try: Sync.queue(account_id, mode, **kwargs) except QueueError as ex: return redirect('/sync', account_id=account_id, title=ex.title, message=ex.message) return redirect('/sync', account_id=account_id)
def run(cls, account_id, mode, t, **kwargs): # Check for duplicate trigger key = (account_id, mode, t) if key in cls.triggered: log.info('Ignored duplicate sync trigger action') return redirect('/sync', account_id=account_id) # Mark triggered cls.triggered[key] = True # Trigger sync try: Sync.queue(account_id, mode, **kwargs) except QueueError, ex: return redirect('/sync', account_id=account_id, title=ex.title, message=ex.message)
def guardar(self, formulario={}, cliente_id=0): if not formulario: formulario = FieldStorage() if not cliente_id: cliente_id = formulario['cliente'].value self.model.cliente = cliente_id if formulario['telefono'].value: self.model.denominacion = "Teléfono" self.model.valor = formulario['telefono'].value self.model.insert() self.model.denominacion = "Móvil" self.model.valor = formulario['movil'].value self.model.insert() self.model.denominacion = "Email" self.model.valor = formulario['email'].value self.model.insert() if MODULE == "datodecontacto": redirect("cliente/ver/{}".format(cliente_id))
def DismissMessages(days=14, version='latest', *args, **kwargs): # Retrieve messages that match the specified criteria messages = List(days=days, version=version, viewed=False) # Mark all messages as viewed for message in messages: # Update `last_viewed_at` field message.last_viewed_at = datetime.utcnow() message.save() # Redirect back to the messages view return redirect('/messages/list', days=days, version=version)
def validar(self): user_hash = get_hash("sha256", get_form_value("username")) pass_hash = get_hash("sha512", get_form_value("password")) user_id = get_hash("sha384", get_form_value("username")) user_id = get_hash("md5", user_id) salt_username = get_form_value("username")[0:2] salt_password = get_form_value("password")[1:] salt = get_hash("sha224", "{}{}".format(salt_username, salt_password)) credential = get_hash("sha1", "{}{}{}".format(salt, user_hash, pass_hash)) filename = "{}/.{}".format(CREDENTIAL_PATH, credential) #print(HTTP_HTML, "\n") #print(filename); exit() if isfile(filename): #sess_file = Sessions.get_all() variable = Sessions.create() print(HTTP_HTML, "\n") print(variable); exit() Sessions.set("USER_ID", user_id) redirect("cliente/listar") else: redirect("user/login")
def DismissMessages(days=14, version='latest', *args, **kwargs): # Retrieve messages that match the specified criteria messages = List( days=days, version=version, viewed=False ) # Mark all messages as viewed for message in messages: # Update `last_viewed_at` field message.last_viewed_at = datetime.utcnow() message.save() # Redirect back to the messages view return redirect( '/messages/list', days=days, version=version )
def ControlsMenu(account_id=1, title=None, message=None, refresh=None, message_only=False, *args, **kwargs): account = AccountManager.get(Account.id == account_id) # Build sync controls menu oc = ObjectContainer(title2=_("Sync (%s)") % account.name, no_cache=True, art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts)) # Start result message if title and message: oc.add( DirectoryObject(key=Callback(ControlsMenu, account_id=account.id, refresh=timestamp()), title=pad_title(title), summary=message)) if message_only: return oc # Active sync status Active.create(oc, callback=Callback(ControlsMenu, account_id=account.id, refresh=timestamp()), account=account) # # Full # oc.add( DirectoryObject(key=Trigger.callback(Synchronize, account), title=pad_title(SyncMode.title(SyncMode.Full)), summary=Status.build(account, SyncMode.Full), thumb=R("icon-sync.png"), art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts))) # # Pull # oc.add( DirectoryObject(key=Trigger.callback(Pull, account), title=pad_title( _('%s from Trakt.tv') % SyncMode.title(SyncMode.Pull)), summary=Status.build(account, SyncMode.Pull), thumb=R("icon-sync_down.png"), art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts))) oc.add( DirectoryObject(key=Trigger.callback(FastPull, account), title=pad_title( _('%s from Trakt.tv') % SyncMode.title(SyncMode.FastPull)), summary=Status.build(account, SyncMode.FastPull), thumb=R("icon-sync_down.png"), art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts))) # # Push # p_account = account.plex try: # Retrieve account libraries/sections with p_account.authorization(): sections = Plex['library'].sections() except Exception as ex: # Build message if p_account is None: message = _("Plex account hasn't been authenticated") else: message = str(ex.message or ex) # Redirect to error message log.warn('Unable to retrieve account libraries/sections: %s', message, exc_info=True) return redirect('/sync', account_id=account_id, title=_('Error'), message=message, message_only=True) section_keys = [] f_allow, f_deny = Filters.get('filter_sections') for section in sections.filter(['show', 'movie'], titles=f_allow): oc.add( DirectoryObject( key=Trigger.callback(Push, account, section), title=pad_title( _('%s "%s" to Trakt.tv') % (SyncMode.title(SyncMode.Push), section.title)), summary=Status.build(account, SyncMode.Push, section.key), thumb=R("icon-sync_up.png"), art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts))) section_keys.append(section.key) if len(section_keys) > 1: oc.add( DirectoryObject(key=Trigger.callback(Push, account), title=pad_title( _('%s all to Trakt.tv') % SyncMode.title(SyncMode.Push)), summary=Status.build(account, SyncMode.Push), thumb=R("icon-sync_up.png"), art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts))) return oc
def ControlsMenu(account_id=1, title=None, message=None, refresh=None, message_only=False, *args, **kwargs): account = AccountManager.get(Account.id == account_id) # Build sync controls menu oc = ObjectContainer( title2=_("Sync (%s)") % account.name, no_cache=True, art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts) ) # Start result message if title and message: oc.add(DirectoryObject( key=Callback(ControlsMenu, account_id=account.id, refresh=timestamp()), title=pad_title(title), summary=message )) if message_only: return oc # Active sync status Active.create( oc, callback=Callback(ControlsMenu, account_id=account.id, refresh=timestamp()), account=account ) # # Full # oc.add(DirectoryObject( key=Trigger.callback(Synchronize, account), title=pad_title(SyncMode.title(SyncMode.Full)), summary=Status.build(account, SyncMode.Full), thumb=R("icon-sync.png"), art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts) )) # # Pull # oc.add(DirectoryObject( key=Trigger.callback(Pull, account), title=pad_title(_('%s from Trakt.tv') % SyncMode.title(SyncMode.Pull)), summary=Status.build(account, SyncMode.Pull), thumb=R("icon-sync_down.png"), art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts) )) oc.add(DirectoryObject( key=Trigger.callback(FastPull, account), title=pad_title(_('%s from Trakt.tv') % SyncMode.title(SyncMode.FastPull)), summary=Status.build(account, SyncMode.FastPull), thumb=R("icon-sync_down.png"), art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts) )) # # Push # p_account = account.plex try: # Retrieve account libraries/sections with p_account.authorization(): sections = Plex['library'].sections() except Exception as ex: # Build message if p_account is None: message = _("Plex account hasn't been authenticated") else: message = str(ex.message or ex) # Redirect to error message log.warn('Unable to retrieve account libraries/sections: %s', message, exc_info=True) return redirect('/sync', account_id=account_id, title=_('Error'), message=message, message_only=True ) section_keys = [] f_allow, f_deny = Filters.get('filter_sections') for section in sections.filter(['show', 'movie'], titles=f_allow): oc.add(DirectoryObject( key=Trigger.callback(Push, account, section), title=pad_title(_('%s "%s" to Trakt.tv') % (SyncMode.title(SyncMode.Push), section.title)), summary=Status.build(account, SyncMode.Push, section.key), thumb=R("icon-sync_up.png"), art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts) )) section_keys.append(section.key) if len(section_keys) > 1: oc.add(DirectoryObject( key=Trigger.callback(Push, account), title=pad_title(_('%s all to Trakt.tv') % SyncMode.title(SyncMode.Push)), summary=Status.build(account, SyncMode.Push), thumb=R("icon-sync_up.png"), art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts) )) return oc
def Push(account_id=1, section=None, refresh=None): return Trigger(int(account_id), SyncMode.Push, section=section) @route(PLUGIN_PREFIX + '/sync/pull') def Pull(account_id=1, refresh=None): return Trigger(int(account_id), SyncMode.Pull) def Trigger(account_id, mode, **kwargs): try: Sync.queue(account_id, mode, **kwargs) except QueueError, ex: return redirect('/sync', account_id=account_id, title=ex.title, message=ex.message) return redirect('/sync', account_id=account_id) @route(PLUGIN_PREFIX + '/sync/cancel') def Cancel(account_id, id): id = int(id) # Cancel sync task if not Sync.cancel(id): # Unable to cancel task return redirect('/sync', account_id=account_id, title='Error', message='Unable to cancel current sync') # Success return redirect('/sync', account_id=account_id)
def Trigger(account_id, mode, **kwargs): try: Sync.queue(account_id, mode, **kwargs) except QueueError, ex: return redirect('/sync', account_id=account_id, title=ex.title, message=ex.message)
def ControlsMenu(account_id=1, title=None, message=None, refresh=None, message_only=False): account = AccountManager.get(Account.id == account_id) # Build sync controls menu oc = ObjectContainer( title2=LF('controls:title', account.name), no_cache=True, art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts) ) # Start result message if title and message: oc.add(DirectoryObject( key=Callback(ControlsMenu, account_id=account.id, refresh=timestamp()), title=pad_title(title), summary=message )) if message_only: return oc # Active sync status Active.create( oc, callback=Callback(ControlsMenu, account_id=account.id, refresh=timestamp()), account=account ) # # Full # oc.add(DirectoryObject( key=Callback(Synchronize, account_id=account.id, refresh=timestamp()), title=pad_title(SyncMode.title(SyncMode.Full)), summary=Status.build(account, SyncMode.Full), thumb=R("icon-sync.png"), art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts) )) # # Pull # oc.add(DirectoryObject( key=Callback(Pull, account_id=account.id, refresh=timestamp()), title=pad_title('%s from trakt' % SyncMode.title(SyncMode.Pull)), summary=Status.build(account, SyncMode.Pull), thumb=R("icon-sync_down.png"), art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts) )) oc.add(DirectoryObject( key=Callback(FastPull, account_id=account.id, refresh=timestamp()), title=pad_title('%s from trakt' % SyncMode.title(SyncMode.FastPull)), summary=Status.build(account, SyncMode.FastPull), thumb=R("icon-sync_down.png"), art=function_path('Cover.png', account_id=account.id, refresh=account.refreshed_ts) )) # # Push # p_account = account.plex try: # Retrieve account libraries/sections with p_account.authorization(): sections = Plex['library'].sections() except Exception, ex: # Build message if p_account is None: message = "Plex account hasn't been authenticated" else: message = str(ex.message or ex) # Redirect to error message log.warn('Unable to retrieve account libraries/sections: %s', message, exc_info=True) return redirect('/sync', account_id=account_id, title='Error', message=message, message_only=True )
def eliminar(self): self.model.cliente_id = int(ARG) self.model.delete() redirect("cliente/listar")
def eliminar(self): self.model.producto_id = ARG self.model.delete() redirect("producto/listar")
def logout(self): Sessions.destroy() redirect("user/login")