def score_complete_votes(): # this will identify votes which are overdue based on being in progress # beyond due date and with resmethod of vote - probably shouldn't happen # but leave in for now for testing # There is currently no method to call this funcion from the menu but generally shouldn't be required votemethods = db(db.resolvemethod.method == 'Vote').select() votelist = [x.resolve_name for x in votemethods] query = (db.question.duedate > datetime.datetime.utcnow()) & (db.question.status == 'In Progress') quests = db(query).select() for x in quests: if x.resolvemethod in votelist: score_question(x.id,0,False, anon_resolve=PARAMS.anon_resolve) return True
def quickanswer(): """ This willl provide a quick method of approving an action or issue by means of approve disapprove buttons basically needs to create a userquestion record and remove the buttons from the relevant row which may be more challenging - it will never apply to questions and there is a question about how scope changes and geography changes should be handled - but for now we are going to implicitly answer that these stay where they are and retrieve them from the question """ questid = request.args(0, cast=int, default=0) answer = request.args(1, cast=int, default=-1) quest = db(db.question.id == questid).select().first() uq = db((db.userquestion.questionid == questid) & (db.userquestion.auth_userid == auth.user_id) & (db.userquestion.status == 'In Progress')).select() if quest and not uq: uqid = db.userquestion.insert(questionid=questid, auth_userid=auth.user_id, uq_level=quest.question_level, answer=answer, reject=False, urgency=quest.urgency, importance=quest.importance, category=quest.category, activescope=quest.activescope, continent=quest.continent, country=quest.country) status = score_question(questid, uqid) if status == 'Resolved': scheduler.queue_task('send_email_resolved', pvars=dict(questid=questid), period=600) messagetxt = 'Answer recorded for item:' + str(questid) intunpanswers = quest.unpanswers if answer != -1: intunpanswers += 1 if session.answered: # optional if user selects question to answer session.answered.append(questid) anscount = quest.answercounts anscount[answer] += 1 # update the question record based on above db(db.question.id == quest.id).update(answercounts=anscount, unpanswers=intunpanswers, urgency=quest.urgency, importance=quest.importance) elif uq: messagetxt = 'You have already answered this item' else: messagetxt = 'Answer not recorded' return 'jQuery(".w2p_flash").html("' + messagetxt + '").slideDown().delay(1500).slideUp(); $("#target").html("' \ + messagetxt + '"); $("#btns' + str(questid) + ' .btn-success").addClass("disabled").removeClass("btn-success"); $("#btns'\ + str(questid) + ' .btn-danger").addClass("disabled").removeClass("btn-danger");'
def score_complete_votes(): # this will identify votes which are overdue based on being in progress # beyond due date and with resmethod of vote - probably shouldn't happen # but leave in for now for testing # TODO Sort out if this function ever needed votemethods = db(db.resolvemethod.method == 'Vote').select() votelist = [x.resolve_name for x in votemethods] query = (db.question.duedate > datetime.datetime.utcnow()) & (db.question.status == 'In Progress') quests = db(query).select() for x in quests: if x.resolvemethod in votelist: # print('scoring' + x.id) score_question(x.id) # if quests: # print('processsed ' + str(len(quests))) # else: # print('zero items to process') return True
def quickanswer(): """ This willl provide a quick method of approving an action or issue by means of approve disapprove buttons basically needs to create a userquestion record and remove the buttons from the relevant row which may be more challenging - it will never apply to questions and there is a question about how scope changes and geography changes should be handled - but for now we are going to implicitly answer that these stay where they are and retrieve them from the question """ questid = request.args(0, cast=int, default=0) answer = request.args(1, cast=int, default=-1) quest = db(db.question.id == questid).select().first() uq = db((db.userquestion.questionid == questid) & (db.userquestion.auth_userid == auth.user_id) & (db.userquestion.status == 'In Progress')).select() if quest and not uq: uqid = db.userquestion.insert(questionid=questid, auth_userid=auth.user_id, uq_level=quest.question_level, answer=answer, reject=False, urgency=quest.urgency, importance=quest.importance, category=quest.category, activescope=quest.activescope, continent=quest.continent, country=quest.country) status = score_question(questid, uqid) if status == 'Resolved': scheduler.queue_task('send_email_resolved', pvars=dict(questid=questid), period=600) messagetxt = 'Answer recorded for item:' + str(questid) intunpanswers = quest.unpanswers if answer != -1: intunpanswers += 1 if session.answered: # optional if user selects question to answer session.answered.append(uq.questionid) anscount = quest.answercounts anscount[answer] += 1 # update the question record based on above db(db.question.id == quest.id).update(answercounts=anscount, unpanswers=intunpanswers, urgency=quest.urgency, importance=quest.importance) elif uq: messagetxt = 'You have already answered this item' else: messagetxt = 'Answer not recorded' return 'jQuery(".flash").html("' + messagetxt + '").slideDown().delay(1500).slideUp(); $("#target").html("' \ + messagetxt + '"); $("#btns' + str(questid) + ' .btn-success").addClass("disabled").removeClass("btn-success"); $("#btns'\ + str(questid) + ' .btn-danger").addClass("disabled").removeClass("btn-danger");'
def callscorequest(): questid = request.args(0, default='G') score_question(questid, 0, false, anon_resolve=PARAMS.anon_resolve)
def answer_question(): """ This allows the user to answer the question or pass and the result is handled by the score question function. This can really now be called from any event and it is an exposed url - so now need to check if not resolved or already answered and if so we will not accept another answer """ questid = request.args(0, cast=int, default=0) questtype = request.args(1, default='quest') # This will be All if on an event flow and this will flow to viewquest # This will display the question submitted to it by get_question form2 = SQLFORM(db.userquestion, showid=False, fields=['answer', 'reject', 'urgency', 'importance', 'answerreason', 'changecat', 'category', 'changescope', 'activescope', 'continent', 'country', 'subdivision'], submit_button='Answer', col3={'answer': 'Enter 0 to Pass', 'reject': 'Select if invalid or off subject '}, hidden=dict(uq_level='level'), formstyle='table3cols') #quest = db(db.question.id == questid).select().first().as_dict() form2.element(_type='submit')['_class'] = "btn btn-success" quest = db(db.question.id == questid).select().first() if session.exclude_groups is None: session.exclude_groups = get_exclude_groups(auth.user_id) if quest['answer_group'] in session.exclude_groups: redirect(URL('viewquest', 'notshowing', args=[questid, questtype])) if quest['status'] != 'In Progress': redirect(URL('viewquest', 'index', args=[questid, questtype])) else: uq = db((db.userquestion.questionid == questid) & (db.userquestion.status == 'In Progress') & (db.userquestion.auth_userid == auth.user_id)).select(db.userquestion.id).first() if uq: # User has already answered item so not allowed to answer again redirect(URL('viewquest', 'index', args=[questid, questtype])) form2.vars.activescope = quest['activescope'] form2.vars.continent = quest['continent'] form2.vars.country = quest['country'] form2.vars.subdivision = quest['subdivision'] form2.vars.category = quest['category'] if form2.validate(): form2.vars.auth_userid = auth.user.id form2.vars.questionid = questid form2.vars.uq_level = quest['question_level'] form2.vars.status = 'In Progress' # default to urgency 10 for testing so questions that are answered continue to get answered if auth.user.first_name[:4] == 'Test': form2.vars.urgency = 10 form2.vars.importance = 10 form2.vars.id = db.userquestion.insert(**dict(form2.vars)) response.flash = 'form accepted' status = score_question(questid, form2.vars.id,False, anon_resolve=PARAMS.anon_resolve) if status == 'Resolved': scheduler.queue_task('send_email_resolved', pvars=dict(questid=questid), period=600) redirect(URL('viewquest', 'index', args=[questid, questtype])) elif form2.errors: response.flash = 'form has errors' form2.vars.continet = quest['continent'] form2.vars.country = quest['country'] form2.vars.subdivision = quest['subdivision'] form2.vars.category = quest['category'] return dict(form2=form2, quest=quest)
def callscorequest(): questid = request.args(0, default='G') score_question(questid)
def answer_question(): """ This allows the user to answer the question or pass and the result is handled by the score question function. This can really now be called from any event and it is an exposed url - so now need to check if not resolved or already answered and if so we will not accept another answer """ questid = request.args(0, cast=int, default=0) questtype = request.args(1, default='quest') # This will be All if on an event flow and this will flow to viewquest # This will display the question submitted to it by get_question form2 = SQLFORM(db.userquestion, showid=False, fields=['answer', 'reject', 'urgency', 'importance', 'answerreason', 'changecat', 'category', 'changescope', 'activescope', 'continent', 'country', 'subdivision'], submit_button='Answer', col3={'answer': 'Enter 0 to Pass', 'reject': 'Select if invalid or off subject '}, hidden=dict(uq_level='level'), formstyle='table3cols') # bootstrap3_inline # quest = db(db.question.id == questid).select(cache=(cache.ram, 600), cacheable=True).first().as_dict() # this now caused userquestion to be set to wrong level so caching removed for now quest = db(db.question.id == questid).select().first().as_dict() if session.exclude_groups is None: session.exclude_groups = get_exclude_groups(auth.user_id) if quest['answer_group'] in session.exclude_groups: redirect(URL('viewquest', 'notshowing', args=[questid, questtype])) if quest['status'] != 'In Progress': redirect(URL('viewquest', 'index', args=[questid, questtype])) else: uq = db((db.userquestion.questionid == questid) & (db.userquestion.status == 'In Progress') & (db.userquestion.auth_userid == auth.user_id)).select(db.userquestion.id).first() if uq: # User has already answered item so not allowed to answer again redirect(URL('viewquest', 'index', args=[questid, questtype])) form2.vars.activescope = quest['activescope'] form2.vars.continent = quest['continent'] form2.vars.country = quest['country'] form2.vars.subdivision = quest['subdivision'] form2.vars.category = quest['category'] if form2.validate(): form2.vars.auth_userid = auth.user.id form2.vars.questionid = questid form2.vars.uq_level = quest['question_level'] form2.vars.status = 'In Progress' # default to urgency 10 for testing so questions that are answered continue to get answered if auth.user.first_name[:4] == 'Test': form2.vars.urgency = 10 form2.vars.importance = 10 form2.vars.id = db.userquestion.insert(**dict(form2.vars)) response.flash = 'form accepted' # redirect(URL('update_question', args=form2.vars.id)) status = score_question(questid, form2.vars.id) if status == 'Resolved': scheduler.queue_task('send_email_resolved', pvars=dict(questid=questid), period=600) redirect(URL('viewquest', 'index', args=[questid, questtype])) elif form2.errors: response.flash = 'form has errors' form2.vars.continet = quest['continent'] form2.vars.country = quest['country'] form2.vars.subdivision = quest['subdivision'] form2.vars.category = quest['category'] return dict(form2=form2, quest=quest)