List Info

Thread: pass varaibles between 2 pages




pass varaibles between 2 pages
country flaguser name
Italy
2007-09-19 19:19:31
i'm a bit in troubel whit the following situation.
in mysql i have table users defined as 

CREATE TABLE users (
id INT NOT NULL AUTO_INCREMENT,
username VARCHAR(30) NOT NULL,
gruppo INT NOT NULL ,  -- this is a value from table groups
PRIMARY KEY ( id )
) ENGINE = MYISAM ;

and then i have the table groups
CREATE TABLE groups (
id INT NOT NULL AUTO_INCREMENT,
groupname VARCHAR(30) NOT NULL,
[....]
PRIMARY KEY ( id )
) ENGINE = MYISAM ;

in python i have one document for handling all records in
the table
groups and that is working fine.

my problem:
creating the document for handling the table users i need
to
call a searchfunction on tabel groups and as the result i
need the
groups.id which will be saved into the filed users.group
haw can this be solved ?

here the example of the default page for users. the page
form groups is
identical.
what and how can i change the page webuser.py to get a new
window for
searching the group and then pass the id back to the primary
(webuser)
page without loosing other data already inserted ?
thx mike

webuser.py
=====================================
#-*- coding: utf-8 -*-

import cherrypy
from Cheetah.Template import Template
from mytables import Webuser
from sqlobject import *

class WebuserManager:
	
	def index(self):
		# default function is a search form
		mywebusers = Webuser.select()
		
		template = Template('''
               <table width="100%">
                <tr>
                    <td valign="top">
                        #include "menu.html"
                    </td>
                    <td align="left"> 
                        <h2>Ricerca utenti</h2>
                        <p>[<a
href="./edit">Nuovo
utente</a>]</p>
                        <form action="./lista"
method="POST">
                            User Name: <input
name="username" value=""
/><br/>
                            Gruppo: <input
name="gruppo" value="" /><br/>
                            <input
type="submit" value="Cerca" />
                        </form>
                    </td>
                </tr>
            </table>
			''', [locals(), globals()])
		return template.respond()
	index.exposed = True

	def lista(self, **kwargs):
		# search function returns a table
		if len(kwargs) > 0:
			evalList = []
			valcount = 0
			mykeysort = ""
			for kw in kwargs.items():
				# creat SQL
				key, val = kw
				if val == "":
					continue;
				mykeysort = key
				valcount = valcount + 1
				if key == "username":
					evalList.append('Webuser.q.%s.contains("%s")'
% (key, val))
				else:
					evalList.append('Webuser.q.%s=="%s"' % (key,
val))
			
			if valcount == 0:
				evalString =
'Webuser.select().orderBy(["username"])'
			elif valcount == 1:
				critString = ''.join(evalList)
				evalString =
'Webuser.select(%s).orderBy(["%s"])' %
(critString, mykeysort)
			else:
				critString = ' , '.join(evalList)
				evalString =
'Webuser.select(AND(%s)).orderBy(["username"])' %
(critString)
		else:
			evalString =
Webuser.select().orderBy(["username"])
			
		mywebusers = eval(evalString)
		#print result
		template = Template('''
           <table width="100%">
                <tr>
                    <td valign="top">
                        #include "menu.html"
                    </td>
                    <td>
                        <h2>Risultato ricerca
utenti</h2>
                        <p>[<a
href="./">Nuova Ricerca</a>] [<a
href="./edit">Nuovo
Utente</a>]</p>
                        <table border="1"
cellspacing="0">
                            <tr>
                                <td>Utente</td>
                                <td>Gruppo</td>
                                <td>Operazioni
disponibili</td>
                            </tr>
                            #for $mywebuser in $mywebusers
                                <tr>
                                   
<td>$mywebuser.username</td>
                                   
<td>$mywebuser.gruppo</td>
                                    <td>[<a
href="./edit?id=$mywebuser.id">Modifica</a&g
t;]
                                        [<a
href="./delete?id=$mywebuser.id">Cancella</a
>]</td>
                                </tr>
                            #end for			
                        </table>
                    </td>
                </tr>
            </table>
			''', [locals(), globals()])
		return template.respond()
	lista.exposed = True
	
	def edit(self, id = 0):
		# id String - number Konvertierung
		id = int(id)
		
		if id > 0:
			# rufe Edit auf
			mywebuser = Webuser.get(id)
			title = "Modifica utenti"
		else:
			# rufe Insert auf
			mywebuser = None
			title = "Inserisci utente"

		# Template code
		template = Template('''
           <table width="100%">
                <tr>
                    <td valign="top">
                        #include "menu.html"
                    </td>
                    <td>
                        <h2>$title</h2>
                        <form action="./store"
method="POST">
                            <input
type="hidden" name="id"
value="$id" />
                            User Name: <input
name="username"
value="$getVar('mywebuser.username', '')"
/><br/>
                            Gruppo: <input
name="gruppo"
value="$getVar('mywebuser.gruppo', '')"
/><br/>
				<!--i think $getVar('mywebuser.gruppo', '') should be
replace with something that calls the other file search 
					function and as result recive an id -->
                            <input
type="submit" value="Store" />
                        </form>
                    </td>
                </tr>
            </table>
		''', [locals(), globals()])
		return template.respond()
	edit.exposed = True
	
	def delete(self, id):
		# Loeschen
		mywebuser = Webuser.get(int(id))
		mywebuser.destroySelf()
		return 'Deleted. <a href="./">Return to
Index</a>'
	delete.exposed = True
	
	def store(self, username, gruppo, id = None):
		if id and int(id) > 0:
			# id >0 => edit 
			mywebuser = Webuser.get(int(id))
			
			mywebuser.set(
				username = username,
				gruppo = int(gruppo))
		else:
			# id unknows => insert
			mywebuser = Webuser(
				username = username,
				gruppo = int(gruppo))
		
		return 'Salvato con successo. <form
action="./lista"
method="POST"><input type="hidden"
name="id" value=%s /> <input
type="submit" value="Ritorna" />
</form>' % id
	store.exposed = True
	

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )