hello dear bro thanks for replaying to me just in short what i want to do
is there is a model
db.define_table(
'Office',
Field('Office_level'),
Field('Office_building'),
Field('Office_number'),
Field('Maximum_load'),
Field('Free_space'),
Field('Office_discription', 'text'),
Field('status','boolean',readable=False, writable= False, default=True),
format = '%(name)s')
db.define_table(
'Request',
Field('Requester',db.auth_user, default=auth.user_id),
Field('Requested_office','reference Office'),
Field('Request_information', 'text'),
format = '%(name)s')
db.Request.Requested_office.requires = IS_IN_DB(db,db.Office.Office_number,
'%(Office_number)s')
db.Request.Requester.readable = db.Request.Requester.writable = False
db.Request.Requester.requires = IS_NOT_EMPTY()
db.Request.Request_information.requires = IS_NOT_EMPTY()
db.define_table(
'Response',
Field('Respondant', default='ADMINISTRATOR', writable=False),
Field('Office_Assigned_To', db.auth_user, readable=False),
Field('Assigned_Office_Number', 'reference Office'),
Field('Response_information', 'text'),
format = '%(name)s')
db.Response.Assigned_Office_Number.requires =
IS_IN_DB(db,db.Office.Office_number, '%(Office_number)s')
db.Response.Office_Assigned_To.requires =
IS_IN_DB(db,db.auth_user.id,'%(username)s')
db.Response.Respondant.requires = IS_NOT_EMPTY()
db.Response.Response_information.requires = IS_NOT_EMPTY()
db.Office.Office_level.requires = IS_NOT_EMPTY()
db.Office.Office_building.requires = IS_NOT_EMPTY()
db.Office.Office_number.requires = IS_NOT_EMPTY()
db.Office.Maximum_load.requires = IS_NOT_EMPTY()
db.Office.Free_space.requires = IS_NOT_EMPTY()
db.Office.Office_discription.requires = IS_NOT_EMPTY()
db.define_table('message',
Field('fromid', db.auth_user, default=auth.user_id, readable=False,
writable=False),
Field('toid', db.auth_user, readable=False),
Field('timesent', 'datetime', default=request.now, readable=False,
writable=False),
Field('subject','string', length=255),
Field('messages', 'text'),
Field('opened', 'boolean', writable=False, readable=False,
default=False),
Field('timeopened', 'datetime', readable=False, writable=False)
)
db.message.toid.requires=IS_IN_DB(db, db.auth_user.id,'%(username)s')
i have inserted data in the database using SQlFORM
first i will register office information in the office table (lets register
office with office id 1, office number 123, capacity 12, free space 12
initially )then users will request to the office using the office id as
reference by office number field (let request office id 1 referencing
office number 123 ) and send the request and what i want is that in the
response to the request controller when office manager give response to the
request the( office id 1, office number 123 will be given to the user )
after this the office table information for office id 1, office number 123,
capacity 12 and free space has to be just like this office id 1, office
number 123, capacity 12, free space 11(because we have given one free space
for one user) this is what i want to do. 10q for your help.
and this is my controller
# -*- coding: utf-8 -*-
# this file is released under public domain and you can use without
limitations
#########################################################################
## This is a samples controller
## - index is the default action of any application
## - user is required for authentication and authorization
## - download is for downloading files uploaded in the db (does streaming)
## - call exposes all registered services (none by default)
#########################################################################
response.menu = [['Register office', False, URL('create')],
['Request office', False, URL('create_Request')],
['Respond to Request', False, URL('create_Response')],
['Office information', False, URL('Officeinfo')],
['Search for office', False, URL('search_office')],
['office gread', False, URL('office_gread')],
['respondrequest', False, URL('respondrequest')],
['Compose', False, URL('compose')],
['Inbox', False, URL('inbox')]]
@auth.requires_login()
def index():
"""
example action using the internationalization operator T and flash
rendered by views/default/index.html or views/generic.html
"""
response.flash = "Welcome to web2py!"
return dict(message=T('Hello World'))
def user():
"""
exposes:
http://..../[app]/default/user/login
http://..../[app]/default/user/logout
http://..../[app]/default/user/register
http://..../[app]/default/user/profile
http://..../[app]/default/user/retrieve_password
http://..../[app]/default/user/change_password
use @auth.requires_login()
@auth.requires_membership('group name')
@auth.requires_permission('read','table name',record_id)
to decorate functions that need access control
"""
return dict(form=auth())
def download():
"""
allows downloading of uploaded files
http://..../[app]/default/download/[filename]
"""
return response.download(request,db)
def call():
"""
exposes services. for example:
http://..../[app]/default/call/jsonrpc
decorate with @services.jsonrpc the functions to expose
supports xml, json, xmlrpc, jsonrpc, amfrpc, rss, csv
"""
return service()
@auth.requires_signature()
def data():
"""
http://..../[app]/default/data/tables
http://..../[app]/default/data/create/[table]
http://..../[app]/default/data/read/[table]/[id]
http://..../[app]/default/data/update/[table]/[id]
http://..../[app]/default/data/delete/[table]/[id]
http://..../[app]/default/data/select/[table]
http://..../[app]/default/data/search/[table]
but URLs must be signed, i.e. linked with
A('table',_href=URL('data/tables',user_signature=True))
or with the signed load operator
LOAD('default','data.load',args='tables',ajax=True,user_signature=True)
"""
return dict(form=crud())
@auth.requires_login()
def create():
form=SQLFORM(db.Office).process()
if form.accepted:
response.flash="you have fully registered the office"
return dict(form=form)
@auth.requires_login()
def create_Response():
form=SQLFORM(db.Response).process()
ama=db.Response.Assigned_Office_Number.active=True
rows=db(db.Office.Office_number==ama).select()
if form.accepted:
response.flash="you have sucessfully reponded to the request" +
str(rows)
return dict(form=form)
@auth.requires_login()
def create_Request():
form=SQLFORM(db.Request).process()
##counting rows goes as follows
if form.accepted:
response.flash="you have sucessfully reponded to the request"
return dict(form=form)
@auth.requires_login()
def inbox():
##messages=db().select(db.message.ALL)
#messages=db().select(db.users.fullname, db.addresses.email_address,
left=db.addresses.on(db.addresses.user_id==db.users.id))
messages=db(db.message.toid == auth.user.id).select(db.message.ALL)
return dict(messages=messages)
@auth.requires_login()
def outbox():
messages=db(db.message.fromid == auth.user.id).select(db.message.ALL)
return dict(messages=messages)
@auth.requires_login()
def compose():
form=crud.create(db.message)
if form.accepts(request.vars, session):
session.flash='Record inserted'
redirect(URL(r=request,f='inbox'))
elif form.errors:
response.flash='There error'
return dict(form=form)
#def create():
# return dict(form=crud.create(db.message))
def truncate():
return db.message.truncate()
@auth.requires_login()
def read():
return dict(form=crud.read(db.message, request.args(0)))
def Officeinfo():
record =
SQLTABLE(db().select(db.Office.ALL),headers='fieldname:capitalize')
return dict(record=record)
def search_office():
form, rows=crud.search(db.Office,query=db.Office.status==True)
return dict(form=form, rows=rows)
def office_gread():
record = SQLFORM.grid(db.Office, user_signature=True)
rows=db().select(db.Office.ALL)
ala= len(rows) + 1
return dict(record=record, ala=ala)
def respondrequest():
records =
SQLTABLE(db().select(db.Request.ALL),headers='fieldname:capitalize')
return dict(records=records)
On Sunday, October 21, 2012 12:04:17 AM UTC-7, alazar baharu wrote:
>
> On Friday, October 19, 2012 11:50:20 PM UTC-7, alazar baharu wrote:
>>
>> hello every on e am developing a simple office space management
>> information system using web 2py and i get in trouble doing some tasks.
>> i have a table called office where office information will be saved there
>> including office capacity and there is also a table which helps in giving
>> office to users
>> and what i want is when submitting a data in the office giving table i
>> want to decrease one space in the office table record ? but i cant do this
>> is there any one who can help me doing this please ?
>>
>> my controller looks like this
>>
> hello again sorry for posting again my controlers looks like this
> def create_Response():
> form=SQLFORM(db.Response).process()
> rows=db().select(db.Office.Office_number= Assigned_Office_Number,
> Active=True)
> ala= len(rows) - 1
> update=crud.update(db.Office, Free_space=ala)
>
> if form.accepted:
> response.flash="you have sucessfully reponded to the request"
> return dict(form=form, update=update)
> hope you will get my ideas and provide me a solution soon
> 10Q.
>
--