*controller*
@auth.requires_login()
def view_searches():
form = SQLFORM(Post)
if form.process().accepted:
#pass
response.flash = 'done'
if request.vars.message:
db.post.insert(message = request.vars.message)
db.commit()
quiz = db(db.post.author == auth.user.id).select(db.post.ALL,
limitby=(1,0))
return dict(form =form, quiz=quiz)
N/B
The several functions that will need to use 'quiz' string to process data.
I was posting it to html to view if latest string matches the one on db as
previously described. Otherwise, the functions will pick the string from
the updated db with the latest string as follows:
def Search_name():
db = current.db
auth = Auth(db, hmac_key=Auth.get_or_create_key())
auth.define_tables()
name = [r.message for r in db(db.post.author == auth.user.id
).select(db.post.ALL)][-1]
return name
*the view.html*
See www.sololearn.com from where i borrowed this html code.
{{extend "layout.html"}}
https://code.jquery.com/jquery-3.1.1.js";>
Page Title
Chat Bot
Original
SEND
* {
margin: 0px;
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
}
body {
margin: 0px;
height:400px;
bottom:0;
}
#user {
width: 100vw;
position: fixed;
left: 0px;
bottom: 0px;
display: block;
background-color: #EEE;
white-space: nowrap;
height:105px;
}
#msgbox {
width: calc(80% - 12px);
min-height: 25px;
max-height: 35px;
padding: 5px;
outline: none;
border: solid 1px #AAA;
display: inline-block;
vertical-align: center;
float: left;
background-color: #FFF;
border-radius: 25px;
resize: none;
margin: 0px;
word-wrap:break-all;
}
#send {
width: 20vw;
height: 35px;
display: inline-block
outline: none;
border: none;
color: #FFF;
background-color: #00F;
float: left;
border-radius: 25px;
padding: 0px;
cursor: pointer;
margin: 0px;
}
#send:active {
background-color: #00A;
outline: none;
}
#header {
display: flex;
justify-content: left;
align-items: center;
width: calc(100% - 30px);
height: 20px;
padding: 15px;
color: #FFF;
font-size: 200%;
font-weight: bolder;
background-color: #00F;
position: fixed;
font-family: arial;
}
#messages {
display: block;
width: 100vw;
height: calc(100% - 87px);
background-color: #EEE;
position: fixed;
top: 50px;
left: 0px;
overflow: auto;
overflow-x: hidden;
overflow-y: auto;
}
.left {
text-align: left;
/*
display: block;
*/
}
.right {
text-align: right;
/*
display: block;
*/
}
.incoming {
background-color: #FFF;
color: #000;
border: solid 1px #AAA;
}
.outgoing {
background-color: #00F;
color: #FFF;
}
.section {
display: block;
width: calc(100% - 30px);
padding-left: 15px;
padding-right: 15px;
margin-top: 7.5px;
margin-bottom: 7.5px;
}
.message {
display: inline-flex;
justify-content: left;
align-items: center;
border-radius: 25px;
padding: 10px;
font-size: 10pt;
}
input:first {
color: #F00;
}
.incoming:active {
background-color: #EEE;
}
.outgoing:active {
background-color: #00A;
}
* {
outline: none;
tap-highlight: none;
-webkit-tap-highlight: none;
-webkit-tap-highlight-color: none;
-moz-tap-highlight: none;
-moz-tap-highlight-color: none;
-khtml-tap-highlight: none;
-khtml-tap-highlight-color: none;
}
a {
display: block;
text-align: center;
}
$(function(){
var commands = {
"random":"var rand = (Math.floor(Math.random() * 10));
incoming(rand);",
"commands":"var objstr = JSON.stringify(commands); objstr =
JSON.stringify(commands, null, 4); incoming(objstr)"
}
var responseSys = {
"hi":"Hello There!",
"bye":"GoodBye!"
};
function cmd(name, action){
commands[name] = action;
}
function outgoing(text){
var newMsg = "";
$("#messages").append(newMsg);
}
function incoming(text){
var newMsg = "" +
About db refresh,
when i go to the database administration page in the app, and open the
post.db page, i have to manually refresh the page to see the latest
inserted value which does not match with the returned value as explained.
That's why i was thinking of a way to refresh the db after the input and
insert to the Field, perhaps to get the last inserted record.
Regards
On Wed, Nov 15, 2017 at 5:46 PM, Maurice Waka wrote:
> *controller*
> @auth.requires_login()
> def view_searches():
> form = SQLFORM(Post)
> if form.process().accepted:
> #pass
> response.flash = 'done'
> if request.vars.message:
> db.post.insert(message = request.vars.message)
> db.commit()
> quiz = db(db.post.author == auth.user.id).select(db.post.ALL,
> limitby=(1,0))
> return dict(form =form, quiz=quiz)
>
> N/B
> The several functions that will need to use 'quiz' string to process data.
> I was posting it to html to view if latest string matches the one on db as
> previously described. Otherwise, the functions will pick the string from
> the updated db with the latest string as follows:
>
> def Search_name():
> db = current.db
> auth = Auth(db, hmac_key=Auth.get_or_create_key())
> auth.define_tables()
> name = [r.message for r in db(db.post.author == auth.user.id
> ).select(db.post.ALL)][-1]
> return name
>
>
> *the view.html*
> See www.sololearn.com from where i borrowed this html code.
>
> {{extend "layout.html"}}
>
>
>
>
> https://code.jquery.com/jquery-3.1.1.js";>
>
> Page Title
>
>
> Chat Bot
>
>
> Original
>
>
> placeholder="Type a message..." />
> SEND
>
>
>
>
>
> * {
>margin: 0px;
>user-select: none;
>-webkit-user-select: none;
>-moz-user-select: none;
> }
> body {
> margin: 0px;
> height:400px;
> bottom:0;
> }
> #user {
> width: 100vw;
> position: fixed;
> left: 0px;
> bottom: 0px;
> display: block;
> background-color: #EEE;
> white-space: nowrap;
> height:105px;
> }
> #msgbox {
>width: calc(80% - 12px);
>min-height: 25px;
>max-height: 35px;
>padding: 5px;
>outline: none;
>border: solid 1px #AAA;
>display: inline-block;
>vertical-align: center;
>float: left;
>background-color: #FFF;
>border-radius: 25px;
>resize: none;
>margin: 0px;
>word-wrap:break-all;
> }
> #send {
>width: 20vw;
>height: 35px;
>display: inline-block
>outline: none;
>border: none;
>color: #FFF;
>background-color: #00F;
>float: left;
>border-radius: 25px;
>padding: 0px;
>cursor: pointer;
>margin: 0px;
> }
> #send:active {
>background-color: #00A;
>outline: none;
> }
> #header {
>display: flex;
>justify-content: left;
>align-items: center;
>width: calc(100% - 30px);
>height: 20px;
>padding: 15px;
>color: #FFF;
>font-size: 200%;
>font-weight: bolder;
>background-color: #00F;
>position: fixed;
>font-family: arial;
> }
> #messages {
>display: block;
>width: 100vw;
>height: calc(100% - 87px);
>background-color: #EEE;
>position: fixed;
>top: 50px;
>left: 0px;
>overflow: auto;
>overflow-x: hidden;
>overflow-y: auto;
> }
> .left {
>text-align: left;
>/*
>display: block;
>*/
> }
> .right {
>text-align: right;
>/*
>display: block;
>*/
> }
> .incoming {
>background-color: #FFF;
>color: #000;
>border: solid 1px #AAA;
> }
> .outgoing {
>background-color: #00F;
>color: #FFF;
> }
> .section {
>display: block;
>width: calc(100% - 30px);
>padding-left: 15px;
>padding-right: 15px;
>margin-top: 7.5px;
>margin-bottom: 7.5px;
> }
> .message {
>display: inline-flex;
>justify-content: left;
>align-items: center;
>border-radius: 25px;
>padding: 10px;
>font-size: 10pt;
> }
> input:first {
>color: #F00;
> }
> .incoming:active {
>background-color: #EEE;
> }
> .outgoing:active {
>background-color: #00A;
> }
> * {
>outline: none;
>tap-highlight: none;
>-webkit-tap-highlight: none;
>-webkit-tap-highlight-color: none;
>-moz-tap-highlight: none;
>-moz-tap-highlight-color: none;
>-khtml-tap-highlight: none;
>-khtml-tap-highlight-color: none;
> }
> a {
>
The oncreate function is pointless because the only thing it does is
conditionally alter the form errors and vars, but then it redirects -- so
nothing happens with the altered form errors and vars (the redirect results
in a new request, so nothing from the current request is preserved).
You onvalidation function should be getting called as expected. If you are
not seeing the validations you are expecting, likely there are some errors
in the code.
Also, in the conditional block near the end of your code, you set
session.flash, but the code then does a return rather than a redirect.
session.flash is typically set right before a redirect because it doesn't
get displayed until the next request (when a new request comes in, it
checks for session.flash and transfers it to response.flash).
Anthony
On Wednesday, November 15, 2017 at 6:55:47 AM UTC-5, Yebach wrote:
>
> Hello
>
> I have a custom form from SQLFORM.grid. After clicking the submit button
> onvalidation or oncreate funciton are not triggered - although some fields
> are validated, but that is even before the my_processing_form function
> there is no redirect after submit and the record is not inserted/updated in
> the database. I used the same principle with some other functions and views
> and there it works fine, but I have no idea why at this one the on validate
> is not triggered.
> If anyone sees the error please let me know
>
> Here is my function
>
> def shifts():
> user = auth.user_id
> org = db(db.auth_user.id ==
> user).select(db.auth_user.organization)[0]["organization"]
>
> db.workers.w_user.default = user
> db.workers.w_organization.default = org
> #Naredimo še grid za šifrant turnusov
> db.shifts.sh_organization.default = org
>
> query_shifts = ((db.shifts.sh_organization == org) & (db.shifts.sh_status
> == 1))
> query_inactive = db((db.shifts.sh_organization == org) &
> (db.shifts.sh_status == 100)).select().as_list()
> # print query_inactive
>
> ###V kolikor uporabnik naredi turnus ki je že ampak je
> arhiviran/deaktiviran ga je potrebno na to opozorit
> ##Določimo da ne more bit za istga userja dvakrat isti turnus
>
> # db.shifts.sh_code.requires=IS_NOT_IN_DB(db(db.shifts.sh_organization ==
> org),'shifts.sh_code')
>
> # najprej popravmo definicijo tabele
>
> fields_shifts = (
> db.shifts.sh_code,
> db.shifts.sh_name,
> db.shifts.sh_color,
> db.shifts.sh_category,
> db.shifts.sh_start1,
> db.shifts.sh_end1,
> db.shifts.sh_length1,
> db.shifts.sh_start2,
> db.shifts.sh_end2,
> db.shifts.sh_length2,
> db.shifts.sh_duration1,
> # db.shifts.sh_start3,
> # db.shifts.sh_end3,
> # db.shifts.sh_start4,
> # db.shifts.sh_end4,
> # db.shifts.sh_start5,
> # db.shifts.sh_end5,
> db.shifts.sh_note)
>
> db.shifts.sh_organization.readable = False
> db.shifts.sh_organization.writable = False
> db.shifts.sh_organization.editable = False
>
> # db.shifts.sh_code.editable = db.shifts.sh_code.writable = False
>
> # db.shifts.sh_duration.writable = False
>
> db.shifts.sh_duration1.readable = db.shifts.sh_duration1.writable = False
> db.shifts.sh_start3.readable = db.shifts.sh_start3.writable = False
> db.shifts.sh_end3.readable = db.shifts.sh_end3.writable = False
> db.shifts.sh_length3.readable = db.shifts.sh_length3.writable = False
> db.shifts.sh_start4.readable = db.shifts.sh_start4.writable = False
> db.shifts.sh_length4.readable = db.shifts.sh_length4.writable = False
> db.shifts.sh_end4.readable = db.shifts.sh_end4.writable = False
> db.shifts.sh_start5.readable = db.shifts.sh_start5.writable = False
> db.shifts.sh_length5.readable = db.shifts.sh_length5.writable = False
> db.shifts.sh_end5.readable = db.shifts.sh_end5.writable = False
>
>
> db.shifts.sh_code.widget = SQLFORM.widgets.string.widget
> db.shifts.sh_name.widget = SQLFORM.widgets.string.widget
> db.shifts.sh_note.widget = SQLFORM.widgets.string.widget
> db.shifts.partner_id.widget = SQLFORM.widgets.integer.widget
> #db.shifts.sh_category.widget = SQLFORM.widgets.integer.widget
> #db.shifts.sh_start1 = SQLFORM.widgets.time.widget
> #db.shifts.sh_start1 = SQLFORM.widgets.timewidget.widget
>
> db.shifts.sh_code.requires = [IS_NOT_IN_DB(db((db.shifts.sh_organization
> == org)&(db.shifts.sh_status != 250)), 'shifts.sh_code',
>error_message=T('Shift with
> this code already exist. Follow the link in upper right corner'))]
>
> db.shifts.sh_name.requires = [IS_NOT_EMPTY(error_message=T('Missing shift
> name'))]
> db.shifts.sh_color.requires = [IS_NOT_EMPTY(error_message=T('Missing
> shift color'))]
> db.shifts.sh_start1.requires = [IS_NOT_EMPTY(error_message=T('Missing
> start time of the shift')
addendum:
Post = db.define_table('post',
Field('author', 'reference auth_user',
default=auth.user_id, writable=False, readable=False),
Field('message', 'text', requires=IS_NOT_EMPTY(),
default ='', notnull=False),
auth.signature
)
On Wed, Nov 15, 2017 at 5:51 PM, Maurice Waka wrote:
> About db refresh,
> when i go to the database administration page in the app, and open the
> post.db page, i have to manually refresh the page to see the latest
> inserted value which does not match with the returned value as explained.
> That's why i was thinking of a way to refresh the db after the input and
> insert to the Field, perhaps to get the last inserted record.
> Regards
>
> On Wed, Nov 15, 2017 at 5:46 PM, Maurice Waka
> wrote:
>
>> *controller*
>> @auth.requires_login()
>> def view_searches():
>> form = SQLFORM(Post)
>> if form.process().accepted:
>> #pass
>> response.flash = 'done'
>> if request.vars.message:
>> db.post.insert(message = request.vars.message)
>> db.commit()
>> quiz = db(db.post.author == auth.user.id).select(db.post.ALL,
>> limitby=(1,0))
>> return dict(form =form, quiz=quiz)
>>
>> N/B
>> The several functions that will need to use 'quiz' string to process
>> data. I was posting it to html to view if latest string matches the one on
>> db as previously described. Otherwise, the functions will pick the string
>> from the updated db with the latest string as follows:
>>
>> def Search_name():
>> db = current.db
>> auth = Auth(db, hmac_key=Auth.get_or_create_key())
>> auth.define_tables()
>> name = [r.message for r in db(db.post.author == auth.user.id
>> ).select(db.post.ALL)][-1]
>> return name
>>
>>
>> *the view.html*
>> See www.sololearn.com from where i borrowed this html code.
>>
>> {{extend "layout.html"}}
>>
>>
>>
>>
>> https://code.jquery.com/jquery-3.1.1.js";>
>>
>> Page Title
>>
>>
>> Chat Bot
>>
>> Orig
>> inal
>>
>>
>> > placeholder="Type a message..." />
>> SEND
>>
>>
>>
>>
>>
>> * {
>>margin: 0px;
>>user-select: none;
>>-webkit-user-select: none;
>>-moz-user-select: none;
>> }
>> body {
>> margin: 0px;
>> height:400px;
>> bottom:0;
>> }
>> #user {
>> width: 100vw;
>> position: fixed;
>> left: 0px;
>> bottom: 0px;
>> display: block;
>> background-color: #EEE;
>> white-space: nowrap;
>> height:105px;
>> }
>> #msgbox {
>>width: calc(80% - 12px);
>>min-height: 25px;
>>max-height: 35px;
>>padding: 5px;
>>outline: none;
>>border: solid 1px #AAA;
>>display: inline-block;
>>vertical-align: center;
>>float: left;
>>background-color: #FFF;
>>border-radius: 25px;
>>resize: none;
>>margin: 0px;
>>word-wrap:break-all;
>> }
>> #send {
>>width: 20vw;
>>height: 35px;
>>display: inline-block
>>outline: none;
>>border: none;
>>color: #FFF;
>>background-color: #00F;
>>float: left;
>>border-radius: 25px;
>>padding: 0px;
>>cursor: pointer;
>>margin: 0px;
>> }
>> #send:active {
>>background-color: #00A;
>>outline: none;
>> }
>> #header {
>>display: flex;
>>justify-content: left;
>>align-items: center;
>>width: calc(100% - 30px);
>>height: 20px;
>>padding: 15px;
>>color: #FFF;
>>font-size: 200%;
>>font-weight: bolder;
>>background-color: #00F;
>>position: fixed;
>>font-family: arial;
>> }
>> #messages {
>>display: block;
>>width: 100vw;
>>height: calc(100% - 87px);
>>background-color: #EEE;
>>position: fixed;
>>top: 50px;
>>left: 0px;
>>overflow: auto;
>>overflow-x: hidden;
>>overflow-y: auto;
>> }
>> .left {
>>text-align: left;
>>/*
>>display: block;
>>*/
>> }
>> .right {
>>text-align: right;
>>/*
>>display: block;
>>*/
>> }
>> .incoming {
>>background-color: #FFF;
>>color: #000;
>>border: solid 1px #AAA;
>> }
>> .outgoing {
>>background-color: #00F;
>>color: #FFF;
>> }
>> .section {
>>display: block;
>>width: calc(100% - 30px);
>>padding-left: 15px;
>>padding-right: 15px;
>>margin-top: 7.5px;
>>margin-bottom: 7.5px;
>> }
>> .message {
>>display: inline-flex;
>>justify-content: left;
>>align-items: center;
>>border-radius: 25px
How are you starting the scheduler workers? Typically the scheduler is run
in the context of a web2py app environment, so the database and tasks are
defined in a web2py app.
To run the scheduler outside of the web2py context, see
https://github.com/web2py/web2py/blob/c9fd0fd71e770c1a367b45ad5def5bd2c6fd7115/gluon/scheduler.py#L1637.
You'll need to specify the DB URI, a folder where the DAL model definition
metadata files will be stored, and a file where the tasks are defined.
Anthony
On Wednesday, November 15, 2017 at 4:04:15 AM UTC-5, yytry...@gmail.com
wrote:
>
> i write a scripy to get some information and use scheduler to auto ,but
> scheduler is display FAILED,this is my script
>
> def redhat():
> bug_num =''
> try:
> try:
> url = 'https://access.redhat.com/security/vulnerabilities'
> rea = requests.get(url)
> rea.encoding = 'utf-8'
> html = BeautifulSoup(rea.text,"html.parser")
> a= html.find("tbody").find_all("tr")
> try:
> indatabase = db(db.get_data.get_from == "redhat").select()
> if indatabase:
> indatabase=db(db.get_data.get_from == "redhat").select
> (
> db.get_data.title,orderby=~db.get_data.get_time,
> limitby=(0,5))
> else:
> indatabase=['1']
> except BaseException as e:
> print e
> for i in range(len(a)):
> for j in indatabase:
> break_flag ='no'
> if a[i].find("a").get_text() != j.title:
> geturl = 'https://access.redhat.com'+ str(a[i].
> find("a")).split('"')[1]
> bug_level = a[i].find("div","field-type-list-text"
> ).get_text().strip()
> if re.findall(u'CVE\-[0-9]{4,}\-[0-9]{4,}',str(a[i
> ].find("a").get_text())):
> bug_num = re.findall(u
> 'CVE\-[0-9]{4,}\-[0-9]{4,}',str(a[i].find("a").get_text()))[0]
> if bug_level=="Critical":
> bug_level="High"
> elif bug_level=="Important":
> bug_level=" Medium"
> elif bug_level=="Moderate":
> bug_level="Low"
> db.get_data.insert(title=a[i].find("a").get_text
> (),get_from='redhat',get_url=geturl,get_time=now,
> body='',data_condition=condition[0],bug_num=
> bug_num,bug_level=bug_level)
> print a[i].find("a").get_text()
> break
> else:
> break_flag = "yes"
> print "redhat no new isuse"
> break
> if break_flag == "yes":
> break
>
>
> except Exception as e:
> print e
>
> except Exception as e:
> pass
> print "redhat finish in " +str(datetime.datetime.now()) +"\n"
>
>
> from datetime import timedelta as timed
> from gluon.scheduler import Scheduler
> scheduler = Scheduler(db, dict(
> mission5=redhat
> )
> )
> scheduler.queue_task('mission5',
> start_time=request.now, # datetime
> stop_time=None,#request.now+timed(seconds=30), # datetime
> timeout = 90, # seconds
> period=60, # seconds
> immediate=True,
> repeats=1
> )
> my script can normal run in controllers,but in scheduler can't
> and i want to control the quantity of scheduler_task,but it without stop
> create new task ,please help me
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi José,
I'm not in a hurry, but I will appreciate so much your help.
Thank you!
P.S. Your recipe with the Webpack proxyTable is working like a charm in my
dev server. 😅
> lso, in webpack.config.babel.js configuration file , if you add
>
>
> devServer: {
> host: '127.0.0.1',
> port: 8001,
> historyApiFallback: false,
> noInfo: true,
> proxy: {
> '/yourapp/api/*': {
> target: 'http://127.0.0.1:8080',
> secure: false
> // changeOrigin: true,
> // pathRewrite: { '^/api': '' }
> }
> },
> },
>
On Tue, Nov 14, 2017 at 12:58 PM, José Luis Redrejo
wrote:
> Carlos, by the way, if you are not in a hurry I can prepare a proof of
> concept this weekend. I just can tell it really works because I am using it
> in a system in production.
>
> Of course, that's the develop setup, once develop is done in production we
> use nginx-uwsgi only, but in that case there's no cors problem as
> everything runs in the same server.
>
>
> The only thing I miss in web2py (waving Massimo ;) ) is having something
> like http://pyramid-webpack.readthedocs.io/en/latest/
>
> It would allow us to write in the view controller/function.html something
> like
>
>
>
>
>
> {{
> average=0for report in form:
> perc=(float(report.marks)/float(report.total))*float(100)if perc>=75:
> grade='A'elif perc>=65:
> grade='B'elif perc>=55:
> grade='C'elif perc>=45:
> grade='D'
>
> This is where I'm attempting to calculate the average
>
> average+=perc
> average2=int(average/7)}}
> {{pass}}
>
>
Looks like the {{pass}} immediately above closes the if/elif block, which
means the two lines of code dealing with average and average2 only get
executed in the "elif perc >= 45" block. That means average2 wouldn't even
be defined otherwise, so I would expect you would be getting errors later
in the code whenever there isn't at least one D in the list of grades.
Also, there is no reason to calculate average2 inside the for loop -- you
only need to calculate it once after looping over all the records.
Finall, why not name the variables something like "total" and "average"
instead of "average" (which is not really an average) and "average2"?
Anthony
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
If anyone is using web2py's Janrain integration, it looks like Janrain
recently made a change that breaks the web2py code. I submitted a pull
request to fix it, but in the meantime, a temporary workaround is to add
the following in the user() function (before the call to auth()):
if request.post_vars.token:
del request.get_vars.token
The problem is that Janrain is now passing the token to the web2py URL via
both a POST variable and the query string. One of those two must be deleted
before calling auth() for the current web2py code to work.
Anthony
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
U were right man, i calculated my average right below the {{pass}} and now
it is able to increment and do the average of course i changed the
variables to total and average.
Thanks alot Tony
On Wednesday, November 15, 2017 at 5:36:19 PM UTC+2, Anthony wrote:
>
> {{
>> average=0for report in form:
>> perc=(float(report.marks)/float(report.total))*float(100)if perc>=75:
>> grade='A'elif perc>=65:
>> grade='B'elif perc>=55:
>> grade='C'elif perc>=45:
>> grade='D'
>>
>> This is where I'm attempting to calculate the average
>>
>> average+=perc
>> average2=int(average/7)}}
>> {{pass}}
>>
>>
> Looks like the {{pass}} immediately above closes the if/elif block, which
> means the two lines of code dealing with average and average2 only get
> executed in the "elif perc >= 45" block. That means average2 wouldn't even
> be defined otherwise, so I would expect you would be getting errors later
> in the code whenever there isn't at least one D in the list of grades.
>
> Also, there is no reason to calculate average2 inside the for loop -- you
> only need to calculate it once after looping over all the records.
>
> Finall, why not name the variables something like "total" and "average"
> instead of "average" (which is not really an average) and "average2"?
>
> Anthony
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
17 matches
Mail list logo