def updateUserInfo(self, user, set_id, set_info): if set_id is not None: raise NotImplementedError, "Cannot currently rename the user id of a user" users_table = self.getProperty('users_table') users_col_username = self.getProperty('users_col_username') realFields = self.remapKeys(set_info, reverse=True) sql = 'UPDATE %s SET ' % users_table for key, value in realFields.items(): _type = 'string' if type(value) == types.FloatType: _type = 'float' elif type(value) == types.IntType: _type = 'int' sql += ('%s' % WRAPCHAR) + key + '%s=<dtml-sqlvar %s type=%s>,' % (WRAPCHAR, key, _type) sql = sql[:-1] sql += " WHERE %s='%s'" % (users_col_username, user.getUserName()) params = ' '.join(realFields.keys()) sqlMethod = SQL('query', 'Update user info', self._connection, params, sql) sqlMethod = sqlMethod.__of__(self) data = dict(realFields) data[users_col_username] = user.getUserName() sqlMethod(**data) view_name = createViewName('getPropertiesForUser', user.getUserName()) cached_info = self.ZCacheable_invalidate(view_name=view_name)
def _createZODBClone(self): """Create a ZODB (editable) equivalent of this object.""" # I guess it's bad to 'reach inside' ourselves like this, # but Z SQL Methods don't have accessor methdods ;-) s = SQL(self.id, self.title, self.connection_id, self.arguments_src, self.src) s.manage_advanced(self.max_rows_, self.max_cache_, self.cache_time_, '', '') return s
def _createZODBClone(self): """Create a ZODB (editable) equivalent of this object.""" # I guess it's bad to 'reach inside' ourselves like this, # but Z SQL Methods don't have accessor methdods ;-) s = SQL(self.id, self.title, self.connection_id, self.arguments_src, self.src) s.manage_advanced(self.max_rows_, self.max_cache_, self.cache_time_, self.class_name_, self.class_file_, connection_hook=self.connection_hook, direct=self.allow_simple_one_argument_traversal) return s
def _createZODBClone(self): """Create a ZODB (editable) equivalent of this object.""" # I guess it's bad to 'reach inside' ourselves like this, # but Z SQL Methods don't have accessor methdods ;-) s = SQL(self.id, self.title, self.connection_id, self.arguments_src, self.src) s.manage_advanced( self.max_rows_, self.max_cache_, self.cache_time_, self.class_name_, self.class_file_, connection_hook=self.connection_hook, direct=self.allow_simple_one_argument_traversal, ) return s
def __init__(self, id, title='', connection_id = '', arguments = '', template = '' ): """ Assign attributes to this class and override ZSQL init method to have consistency with manage_edit(as ZSQL init also creates manage_edit) """ # Add the properties as the attributes for the SQL Method objects # Useful while migrating data from ZSQLMethods to ERP5 SQLMethod objects self.id = id # Initializing ZSQL class object is important as this will call manage_edit # which will change database method properties ZSQL.__init__(self, id, title, connection_id, arguments, template)
def _set_sql_method(self): self._v_cached_parameters = parameters = self.get_parameters_form().get_field_ids() arguments = '\n'.join(parameters) self._sql_method = SQL( self._sql_method_id, '', self._connection_id, arguments.encode('ascii'), self._statement.encode('UTF-8')) self._p_changed = 1
def getSQLData(self, context, template, parameters={}): """ Generic table data retrieval """ parameters = self._escapeParameters(parameters) statement = template % parameters assert type(statement) == type(u'') statement = statement.encode(self.encoding) sql_method = SQL('sqlmethod', 'sqlmethod', self.connection, None, statement).__of__(context) # XXX: We're materializing all data in the resultset here which # hurts performance for large sets. Brains 'normally' lazily # retrieve the data, but then we need to decode to unicode in # the wrong - i.e. in the ZPT's - layer... # # We need a better way. # data_dicts = sql_method().dictionaries() return self._unicodeHelper(data_dicts)
parameters[pair[0].strip().lower()]=pair[1].strip() # check for required an optional parameters try: title = parameters.get('title','') connection_id = parameters.get('connection id',parameters['connection_id']) arguments = parameters.get('arguments','') max_rows = parameters.get('max_rows',1000) max_cache = parameters.get('max_cache',100) cache_time = parameters.get('cache_time',0) except KeyError,e: raise ValueError,"The '%s' parameter is required but was not supplied" % e s = SQL(id, title, connection_id, arguments, data) s.manage_advanced(max_rows, max_cache, cache_time, '', '') obj._setObject(id, s) return getattr(obj,id) class SQLUsers: def __init__(self,folder): self.folder = folder
class ClasseModel(SimpleItem.SimpleItem): """minimal2.""" def __init__(self, id): """minimal2.""" self.id = id def pagina(self, artigo): """Acessa banco e retorna os valores encontrados.""" conteudo = self.banco(artigo=artigo) for i in conteudo: tit = i.titulo pag = i.titulopag par = i.p1 aut = i.autor return self.fill_index(tit=tit, pag=pag, par=par, aut=aut) def edit(self, artigo): """Edita a pagina.""" conteudo = self.banco(artigo=artigo) for i in conteudo: titulo = i.titulo titulopag = i.titulopag p1 = i.p1 autor = i.autor dbid = i.dbid return self.select_edit(titulo=titulo, titulopag=titulopag, p1=p1, autor=autor, dbid=dbid) def chama(self, titulos, autorform, areatexto, titulo, titulopag): """Chama pagina do banco para alterar.""" teste = self.altera_pagina(titulos=titulos, autorform=autorform, areatexto=areatexto, titulo=titulo, titulopag=titulopag) for i in teste: titulo = i.titulo return self.msg_altera(titulo=titulo) def delete(self, artigo): """Funcao para excluir uma pagina.""" delet = self.manage_del_page(artigo=artigo) for i in delet: pass return self.msg_del(artigo=artigo) def adiciona(self, titulo_geral, titulo_pagina, area_texto, autor_pagina): """Adiciona uma pagina ao minimal2, criando uma linha na tabela Sql.""" add = self.add_page(titulo_geral=titulo_geral, titulo_pagina=titulo_pagina, area_texto=area_texto, autor_pagina=autor_pagina) for i in add: titulo_geral = i.titulo_geral return self.msg_add(titulo_geral=titulo_geral) altera_pagina = SQL(id='altera_pagina', title='', connection_id='conexaoBanco', arguments='titulos autorform areatexto titulo\ titulopag', template=open(product_path + 'sql/altera_pagina.sql').read()) banco = SQL(id='banco', title='', connection_id='conexaoBanco', arguments='artigo', template=open(product_path + 'sql/banco.sql').read()) manage_del_page = SQL(id='manage_del_page', title='', connection_id='conexaoBanco', arguments='artigo', template=open(product_path + 'sql/manage_del_page.sql').read()) add_page = SQL(id='add_page', title='', connection_id='conexaoBanco', arguments='titulo_geral titulo_pagina area_texto\ autor_pagina', template=open(product_path + 'sql/add_page.sql').read())
class ClasseControll(SimpleItem.SimpleItem): """minimal2.""" def __init__(self, id): """minimal2.""" self.id = id self.model = ClasseModel('model') def pagina_artigos(self, artigo): """Retorna o conteudo de exibicao vinda de models.""" return self.model.pagina(artigo=artigo) def edit_sql(self, artigo): """Retorna o conteudo vindo de models para modificar a pagina.""" return self.model.edit(artigo=artigo) def chama_pagina(self, titulos, autorform, areatexto, titulo, titulopag): """Retorna o conteudo editado pela pagina de selecao de edicao. Contida em models. """ return self.model.chama(titulos=titulos, autorform=autorform, areatexto=areatexto, titulo=titulo, titulopag=titulopag) def del_page(self, artigo): """Remove uma pagina(linha da tabela do banco).""" return self.model.delete(artigo=artigo) def adiciona_pag(self, titulo_geral, titulo_pagina, area_texto, autor_pagina): """Adiciona uma pagina ao site(uma linha na tabela sql).""" return self.model.adiciona(titulo_geral=titulo_geral, titulo_pagina=titulo_pagina, area_texto=area_texto, autor_pagina=autor_pagina) index_html = PageTemplateFile('zpt/index_html', globals()) fill_index = PageTemplateFile('zpt/fill_index', globals()) manage_edit_page = PageTemplateFile('zpt/manage_edit_page', globals()) select_edit = PageTemplateFile('zpt/select_edit', globals()) msg_altera = PageTemplateFile('zpt/msg_altera', globals()) manage_select_del_page = PageTemplateFile('zpt/manage_select_del_page', globals()) msg_del = PageTemplateFile('zpt/msg_del', globals()) manage_add_page = PageTemplateFile('zpt/manage_add_page', globals()) msg_add = PageTemplateFile('zpt/msg_add', globals()) manage_site = PageTemplateFile('zpt/manage_site', globals()) style_css = PageTemplateFile('zpt/style_css', globals()) menuZ = SQL(id='menuZ', title='', connection_id='conexaoBanco', arguments='', template=open(product_path + 'sql/menuZ.sql').read() )