def edit_question(short_name): (project, owner, n_tasks, n_task_runs, overall_progress, last_activity, n_results) = project_by_shortname(short_name) pro=pro_features() project_button = add_custom_contrib_button_to(project, get_user_id_or_ip()) feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) autoimporter_enabled = feature_handler.autoimporter_enabled_for(current_user) project_sanitized, owner_sanitized = sanitize_project_owner(project_button, owner, current_user) print project_button["contrib_button"] if "importer_type" in project.info.keys(): if(project.info["importer_type"]=="frg"): if(project_button["contrib_button"]=="draft"): if("questionSet" in project.info.keys()): session["edit_question_list"]=[] session["edit_question"]={"images":[],"documents":[],"videos":[],"audios":[]} for i in ["images","documents","videos","audios"]: if(len(project.info["questionSet"][i])>0): session["edit_question_list"].append(i) p=edit_draft_question(project) print "see"+p if(p!="-1"): return redirect_content_type(url_for('.'+p+"_edit",short_name=short_name)) else: return "-1" #return render_template('select_type.html',project=project_sanitized,pro_features=pro) else: return ("Sorry, You Edit the questions for draft project only.","alert") return "Sorry , You did not imported questions from Fundamenta Research"
def create_quiz(short_name): (project, owner, n_tasks, n_task_runs, overall_progress, last_activity, n_results) = project_by_shortname(short_name) project_id = project.id project_button = add_custom_contrib_button_to(project, get_user_id_or_ip()) feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) autoimporter_enabled = feature_handler.autoimporter_enabled_for( current_user) project_sanitized, owner_sanitized = sanitize_project_owner( project_button, owner, current_user) form = Add_quiz() if request.method == "POST" and form.validate(): quiz_name = form.name.data q = quiz(name=quiz_name, project_id=project_id) db.session.add(q) db.session.commit() project.info.update({"is_quiz_provided": True}) project_repo.update(project) session['quiz_name'] = quiz_name session['quiz_id'] = models.quiz.query.filter_by( name=quiz_name, project_id=project_id).first().quiz_id flash("Sucessfully created quiz", "success") return redirect(url_for('quiz.quiz_form', short_name=short_name)) return render_template("add_quiz.html", title="create quiz", form=form, project=project_sanitized, pro_features=pro_features())
def edit_question(short_name): (project, owner, n_tasks, n_task_runs, overall_progress, last_activity, n_results) = project_by_shortname(short_name) pro = pro_features() project_button = add_custom_contrib_button_to(project, get_user_id_or_ip()) feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) autoimporter_enabled = feature_handler.autoimporter_enabled_for( current_user) project_sanitized, owner_sanitized = sanitize_project_owner( project_button, owner, current_user) print project_button["contrib_button"] if (project_button["contrib_button"] == "draft"): if ("questionSet" not in project.info.keys()): project.info.update({ "questionSet": { "images": [], "videos": [], "audios": [], "documents": [] } }) project_repo.update(project) session["edit_question"] = { "images": [], "documents": [], "videos": [], "audios": [] } return redirect_content_type( url_for('.images_edit', short_name=short_name)) else: return ("Sorry, You Edit the questions for draft project only.", "alert")
def images(short_name): (project, owner, n_tasks, n_task_runs, overall_progress, last_activity, n_results) = project_by_shortname(short_name) pro=pro_features() project_button = add_custom_contrib_button_to(project, get_user_id_or_ip()) feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) autoimporter_enabled = feature_handler.autoimporter_enabled_for(current_user) project_sanitized, owner_sanitized = sanitize_project_owner(project_button, owner, current_user) if(session.get("question") is None): return redirect_content_type(url_for('.success',short_name=short_name)) if request.method == 'POST': type_q="normal" answer=[] if(request.form.get('question','')==""): flash("Atleast 1 question is required","warning") return render_template('images.html',project=project_sanitized, pro_features=pro) if(request.form.get('checkbox','')!=""): if(request.form.getlist('answer')[0]=="" or request.form.getlist('answer')[1]==""): flash("Atleast 2 answers are required","warning") return render_template('images.html',project=project_sanitized, pro_features=pro) else: type_q="mcqs" answer=request.form.getlist('answer') dictobj={"questionString":request.form.get('question'),"answers":answer,"type":type_q} session["question"]["images"].append(dictobj) if(request.form.get('submit','')=="submit"): p=draft_project(project) if(p!="-1"): return redirect_content_type(url_for('.'+p.lower(),short_name=short_name)) else: return redirect_content_type(url_for('.success',short_name=short_name)) return render_template('images.html',project=project_sanitized,pro_features=pro) #we are going to tags.html
def get_export_task_jobs(queue): """Export tasks to zip.""" from pybossa.core import project_repo import pybossa.cache.projects as cached_projects from pybossa.pro_features import ProFeatureHandler feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) timeout = current_app.config.get('TIMEOUT') if feature_handler.only_for_pro('updated_exports'): if queue == 'high': projects = cached_projects.get_from_pro_user() else: projects = (p.dictize() for p in project_repo.filter_by(published=True) if p.owner.pro is False) else: projects = (p.dictize() for p in project_repo.filter_by(published=True)) for project in projects: project_id = project.get('id') job = dict(name=project_export, args=[project_id], kwargs={}, timeout=timeout, queue=queue) yield job
def get_weekly_stats_update_projects(): """Return email jobs with weekly stats update for project owner.""" from sqlalchemy.sql import text from pybossa.core import db from pybossa.pro_features import ProFeatureHandler feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) only_pros = feature_handler.only_for_pro('project_weekly_report') only_pros_sql = 'AND "user".pro=true' if only_pros else '' send_emails_date = current_app.config.get('WEEKLY_UPDATE_STATS') today = datetime.today().strftime('%A').lower() timeout = current_app.config.get('TIMEOUT') if today.lower() == send_emails_date.lower(): sql = text(''' SELECT project.id FROM project, "user", task WHERE "user".id=project.owner_id %s AND "user".subscribed=true AND task.project_id=project.id AND task.state!='completed' UNION SELECT project.id FROM project WHERE project.featured=true; ''' % only_pros_sql) results = db.slave_session.execute(sql) for row in results: job = dict(name=send_weekly_stats_project, args=[row.id], kwargs={}, timeout=timeout, queue='low') yield job
def test_better_stats_enabled_for_admin_user_always_returns_True(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.better_stats_enabled_for(self.admin, self.no_pro) is True pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.better_stats_enabled_for(self.admin, self.no_pro) is True
def test_auditlog_enabled_for_pro_always_returns_True(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.auditlog_enabled_for(self.pro) is True pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.auditlog_enabled_for(self.pro) is True
def test_webhooks_enabled_for_admin_always_returns_True(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.webhooks_enabled_for(self.admin) is True pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.webhooks_enabled_for(self.admin) is True
def test_autoimporter_enabled_for_admin_always_returns_True(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.autoimporter_enabled_for(self.admin) is True pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.autoimporter_enabled_for(self.admin) is True
def edit_success(short_name): (project, owner, n_tasks, n_task_runs, overall_progress, last_activity, n_results) = project_by_shortname(short_name) pro=pro_features() project_button = add_custom_contrib_button_to(project, get_user_id_or_ip()) feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) autoimporter_enabled = feature_handler.autoimporter_enabled_for(current_user) project_sanitized, owner_sanitized = sanitize_project_owner(project_button, owner, current_user) return render_template('edit_success.html',project=project_sanitized, pro_features=pro) #we are going to tags.html
def audios_edit(short_name): (project, owner, n_tasks, n_task_runs, overall_progress, last_activity, n_results) = project_by_shortname(short_name) pro=pro_features() project_button = add_custom_contrib_button_to(project, get_user_id_or_ip()) feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) autoimporter_enabled = feature_handler.autoimporter_enabled_for(current_user) project_sanitized, owner_sanitized = sanitize_project_owner(project_button, owner, current_user) if request.method == 'POST': session_count=len(session["edit_question"]["audios"]); session["edit_question"]["audios"]=[] for j in range(1,session_count+1): ans=[] type_q="normal" print str(j)+'_question' if(request.form.get(str(j)+'_question','')!=""): que=request.form.get(str(j)+'_question') if(request.form.get(str(j)+'_divcheckbox','')!=""): type_q="mcqs" if(request.form.get(str(j)+'_answer','')!=""): ans=request.form.getlist(str(j)+'_answer') dictobj={"questionString":request.form.get(str(j)+'_question'),"answers":ans,"type":type_q} session["edit_question"]["audios"].append(dictobj) if(request.form.get('submit','')=="submit"): p=edit_draft_question(project) project.info["questionSet"]["audios"]=session["edit_question"]["audios"] project_repo.update(project) if(p!="-1"): return redirect_content_type(url_for('.'+p.lower()+"_edit",short_name=short_name)) else: return redirect_content_type(url_for('.edit_success',short_name=short_name)) else: type_q="normal" answer=[] if(request.form.get('question','')==""): flash("Question field is Empty","warning") return render_template('audios_edit.html',project=project_sanitized, pro_features=pro) if(request.form.get('checkbox','')!=""): if(request.form.getlist('answer')[0]=="" or request.form.getlist('answer')[1]==""): flash("Atleast 2 answers are required","warning") return render_template('audios_edit.html',project=project_sanitized, pro_features=pro) else: type_q="mcqs" answer=request.form.getlist('answer') dictobj={"questionString":request.form.get('question'),"answers":answer,"type":type_q} session["edit_question"]["audios"].append(dictobj) return render_template('audios_edit.html',project=project_sanitized,pro_features=pro) #we are going to tags.html
def get_autoimport_jobs(queue='high'): current_app.logger.error("This isn't really an error, autoimport was triggered!") """Get autoimport jobs.""" from pybossa.core import project_repo #current_app.logger.error("v1a") import pybossa.cache.projects as cached_projects #current_app.logger.error("v1b") from pybossa.pro_features import ProFeatureHandler #current_app.logger.error("v1c") feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) timeout = current_app.config.get('TIMEOUT') #current_app.logger.error("v2") #if feature_handler.only_for_pro('autoimporter'): # current_app.logger.error("v3a") # projects = cached_projects.get_from_pro_user() #else: #current_app.logger.error("v3b") projects = (p.dictize() for p in project_repo.get_all()) #current_app.logger.error("v4") for project_dict in projects: #current_app.logger.error("v5") project = project_repo.get(project_dict['id']) #current_app.logger.error(str(project)) if project.has_autoimporter(): #current_app.logger.error(str(project)) #current_app.logger.error("v6") job = dict(name=import_tasks, args=[project.id, True], kwargs=project.get_autoimporter(), timeout=timeout, queue=queue) #current_app.logger.error(str(job)) #current_app.logger.error("v7") yield job
def notify_blog_users(blog_id, project_id, queue='high'): """Send email with new blog post.""" from sqlalchemy.sql import text from pybossa.core import db from pybossa.core import blog_repo from pybossa.pro_features import ProFeatureHandler blog = blog_repo.get(blog_id) users = 0 feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) only_pros = feature_handler.only_for_pro('notify_blog_updates') timeout = current_app.config.get('TIMEOUT') if blog.project.featured or (blog.project.owner.pro or not only_pros): sql = text(''' SELECT email_addr, name from "user", task_run WHERE task_run.project_id=:project_id AND task_run.user_id="user".id AND "user".subscribed=true AND "user".restrict=false GROUP BY email_addr, name, subscribed; ''') results = db.slave_session.execute(sql, dict(project_id=project_id)) for row in results: subject = "Project Update: %s by %s" % (blog.project.name, blog.project.owner.fullname) body = render_template('/account/email/blogupdate.md', user_name=row.name, blog=blog, config=current_app.config) html = render_template('/account/email/blogupdate.html', user_name=row.name, blog=blog, config=current_app.config) mail_dict = dict(recipients=[row.email_addr], subject=subject, body=body, html=html) job = dict(name=send_mail, args=[mail_dict], kwargs={}, timeout=timeout, queue=queue) enqueue_job(job) users += 1 msg = "%s users notified by email" % users return msg
def success(short_name): (project, owner, n_tasks, n_task_runs, overall_progress, last_activity, n_results) = project_by_shortname(short_name) pro=pro_features() add_task(project) global previous_data previous_data=[] project_button = add_custom_contrib_button_to(project, get_user_id_or_ip()) feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) autoimporter_enabled = feature_handler.autoimporter_enabled_for(current_user) project_sanitized, owner_sanitized = sanitize_project_owner(project_button, owner, current_user) flash("Your Tasks Uploded Successfully","success") #return render_template('success.html',project=project_sanitized,pro_features=pro) #we are going to tags.html if(not is_quiz_provided(project.id)): return redirect(url_for('quiz.create_quiz',short_name=short_name)) else: return redirect(url_for('project.details',short_name=short_name))
def get_export_task_jobs(queue): """Export tasks to zip.""" from pybossa.core import project_repo import pybossa.cache.projects as cached_projects from pybossa.pro_features import ProFeatureHandler feature_handler = ProFeatureHandler(current_app.config.get("PRO_FEATURES")) if feature_handler.only_for_pro("updated_exports"): if queue == "high": projects = cached_projects.get_from_pro_user() else: projects = (p.dictize() for p in project_repo.get_all() if p.owner.pro is False) else: projects = (p.dictize() for p in project_repo.get_all()) for project in projects: project_id = project.get("id") job = dict(name=project_export, args=[project_id], kwargs={}, timeout=(10 * MINUTE), queue=queue) yield job
def upload_task(short_name): (project, owner, n_tasks, n_task_runs, overall_progress, last_activity, n_results) = project_by_shortname(short_name) pro=pro_features() project_button = add_custom_contrib_button_to(project, get_user_id_or_ip()) feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) autoimporter_enabled = feature_handler.autoimporter_enabled_for(current_user) project_sanitized, owner_sanitized = sanitize_project_owner(project_button, owner, current_user) if request.method=='POST': upload_form=TaskUpload() if upload_form.validate_on_submit(): _file=request.files['avatar'] #extract_files_local(parent_path+"/uploads"+CONTAINER,_file.filename) if _file and allowed_file(_file.filename): _file.save(os.path.join((parent_path+'/uploads/'+CONTAINER) , _file.filename)) if(check_file_size(parent_path+'/uploads/'+CONTAINER+"/"+_file.filename)): global zipobj zipobj=extract_files_local((parent_path+"/uploads/"+CONTAINER),_file.filename,project.id) session["zzz"]=zipobj["zzz"] zipobj.pop("zzz",None) if "directory_names" not in project.info.keys(): project.info.update({"directory_names":[]}) project.info["directory_names"].append(session["zzz"]) project_repo.update(project) #add_task(project.id,zipobj["zzz"]) return redirect_content_type(url_for('.select_type', short_name=short_name)) else: if os.path.exists(parent_path+'/uploads/'+CONTAINER+"/"+_file.filename): os.remove(parent_path+'/uploads/'+CONTAINER+"/"+_file.filename) flash('File Size should be less than 5 MB'); else: flash(gettext('Please upload the file'),'warning') upload_form =TaskUpload() response =dict(template='/upload_form.html', upload_form=upload_form, project=project_sanitized, pro_features=pro ) return handle_content_type(response)
def get_autoimport_jobs(queue='low'): """Get autoimport jobs.""" from pybossa.core import project_repo import pybossa.cache.projects as cached_projects from pybossa.pro_features import ProFeatureHandler feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) if feature_handler.only_for_pro('autoimporter'): projects = cached_projects.get_from_pro_user() else: projects = (p.dictize() for p in project_repo.get_all()) for project_dict in projects: project = project_repo.get(project_dict['id']) if project.has_autoimporter(): job = dict(name=import_tasks, args=[project.id], kwargs=project.get_autoimporter(), timeout=IMPORT_TASKS_TIMEOUT, queue=queue) yield job
def test_better_stats_enabled_for_pro_owner_always_returns_True(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.better_stats_enabled_for( self.no_pro, self.pro) is True assert pro_enabled_handler.better_stats_enabled_for( self.anonymous, self.pro) is True pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.better_stats_enabled_for( self.no_pro, self.pro) is True assert pro_disabled_handler.better_stats_enabled_for( self.anonymous, self.pro) is True
def get_autoimport_jobs(queue='low'): """Get autoimport jobs.""" from pybossa.core import project_repo import pybossa.cache.projects as cached_projects from pybossa.pro_features import ProFeatureHandler feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) timeout = current_app.config.get('TIMEOUT') if feature_handler.only_for_pro('autoimporter'): projects = cached_projects.get_from_pro_user() else: projects = (p.dictize() for p in project_repo.get_all()) for project_dict in projects: project = project_repo.get(project_dict['id']) if project.has_autoimporter(): job = dict(name=import_tasks, args=[project.id, True], kwargs=project.get_autoimporter(), timeout=timeout, queue=queue) yield job
def get_autoimport_jobs(queue="low"): """Get autoimport jobs.""" from pybossa.core import project_repo import pybossa.cache.projects as cached_projects from pybossa.pro_features import ProFeatureHandler feature_handler = ProFeatureHandler(current_app.config.get("PRO_FEATURES")) if feature_handler.only_for_pro("autoimporter"): projects = cached_projects.get_from_pro_user() else: projects = (p.dictize() for p in project_repo.get_all()) for project_dict in projects: project = project_repo.get(project_dict["id"]) if project.has_autoimporter(): job = dict( name=import_tasks, args=[project.id], kwargs=project.get_autoimporter(), timeout=IMPORT_TASKS_TIMEOUT, queue=queue, ) yield job
def test_autoimporter_enabled_for_admin_always_returns_True(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.autoimporter_enabled_for(self.admin) is True pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.autoimporter_enabled_for( self.admin) is True
def select_type(short_name): (project, owner, n_tasks, n_task_runs, overall_progress, last_activity, n_results) = project_by_shortname(short_name) pro=pro_features() project_button = add_custom_contrib_button_to(project, get_user_id_or_ip()) feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) autoimporter_enabled = feature_handler.autoimporter_enabled_for(current_user) project_sanitized, owner_sanitized = sanitize_project_owner(project_button, owner, current_user) print short_name global zipobj li=["Images","Videos",'Audios','Documents'] #classification files if request.method == 'POST': global list_container list_container=request.form.getlist('selecttype') #selected classification list for i in li: if i not in list_container: n=session["zzz"]#this is parent path of the folder which were unchecked by user if os.path.exists(n+"/"+i.lower()): shutil.rmtree(n+"/"+i.lower()) #deletion of folder if(len(list_container)==0): flash("You must select atleast one file","danger") return render_template('select_type.html',arr=zipobj,project=project_sanitized,pro_features=pro) print "Going to function" global previous_data p=draft_project(project) if(len(previous_data)!=0): l=" , ".join(previous_data) print l flash(l+" questions are already uploaded","info") if(p!="-1"): return redirect_content_type(url_for('.'+p.lower(),short_name=short_name)) else: return redirect_content_type(url_for('.success',short_name=short_name)) return render_template('select_type.html',arr=zipobj,project=project_sanitized, pro_features=pro) #sending the classified information to the select_type.html
def test_better_stats_enabled_for_pro_owner_always_returns_True(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.better_stats_enabled_for(self.no_pro, self.pro) is True assert pro_enabled_handler.better_stats_enabled_for(self.anonymous, self.pro) is True pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.better_stats_enabled_for(self.no_pro, self.pro) is True assert pro_disabled_handler.better_stats_enabled_for(self.anonymous, self.pro) is True
def test_better_stats_enabled_for_admin_user_always_returns_True(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.better_stats_enabled_for( self.admin, self.no_pro) is True pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.better_stats_enabled_for( self.admin, self.no_pro) is True
def test_webhooks_enabled_for_non_pro_returns_False_if_enabled(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.webhooks_enabled_for(self.no_pro) is False
def test_autoimporter_enabled_for_non_pro_returns_False_if_enabled(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.autoimporter_enabled_for(self.no_pro) is False
def test_auditlog_enabled_for_non_pro_returns_True_if_disabled(self): pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.auditlog_enabled_for(self.no_pro) is True
def test_only_for_pro_returns_True_if_feature_is_only_for_pro(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.only_for_pro('auditlog') is True
def test_only_for_pro_returns_False_if_feature_is_for_everyone(self): pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.only_for_pro('auditlog') is False
def test_better_stats_enabled_for_non_pro_owner_and_non_pro_user_returns_False_if_enabled( self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.better_stats_enabled_for( self.no_pro, self.no_pro) is False
def test_better_stats_enabled_for_non_pro_owner_and_anonym_user_returns_True_if_disabled( self): pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.better_stats_enabled_for( self.anonymous, self.no_pro) is True
def test_better_stats_enabled_for_non_pro_owner_and_anonym_user_returns_True_if_disabled(self): pro_disabled_handler = ProFeatureHandler(self.config_disabled) assert pro_disabled_handler.better_stats_enabled_for(self.anonymous, self.no_pro) is True
def quiz_form(short_name): (project, owner, n_tasks, n_task_runs, overall_progress, last_activity, n_results) = project_by_shortname(short_name) form = Create_quiz() # Fetch appropriate form from forms.py project_button = add_custom_contrib_button_to(project, get_user_id_or_ip()) feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES')) autoimporter_enabled = feature_handler.autoimporter_enabled_for( current_user) project_sanitized, owner_sanitized = sanitize_project_owner( project_button, owner, current_user) if request.method == "POST" and form.validate(): #collecting data from forms.py que = form.question_text.data #collect the entered question text _file = request.files['file_field'] if _file and allowed_file(_file.filename): parent_path = current_app.root_path[:current_app.root_path. rfind("/")] _file.save( os.path.join((parent_path + '/uploads/' + CONTAINER), _file.filename)) file_path = '/uploads/' + CONTAINER + '/' + _file.filename option_A = form.oA.data #collect entered option A text option_B = form.oB.data #collect entered option B text option_C = form.oC.data #collect entered option C text option_D = form.oD.data #collect entered option D text correct_answer = form.correct_answer.data #collect entered correct answer # Based on entered answer, store the option text in the answer field in the database if correct_answer == 'A': correct_answer = option_A elif correct_answer == 'B': correct_answer = option_B elif correct_answer == 'C': correct_answer = option_C elif correct_answer == 'D': correct_answer = option_D category = form.category.data #collect entered question category q = question(quiz_id=session['quiz_id'], q_text=que, file_path=file_path, option1=option_A, option2=option_B, option3=option_C, option4=option_D, answer=correct_answer, category=category ) # Create object of class question from questions.py db.session.add(q) # Add object q to db.session db.session.commit() # Commit changes to app.db if request.form['submit'] == 'ADD': return redirect(url_for('quiz.quiz_form', short_name=short_name)) elif request.form['submit'] == 'SUBMIT': flash("Sucessfully added questions to " + session['quiz_name'], "success") return redirect(url_for('project.details', short_name=short_name)) return render_template("create_quiz.html", title="Add Question", quiz_name=session['quiz_name'], form=form, project=project_sanitized, pro_features=pro_features()) # Render form template
def test_autoimporter_enabled_for_non_pro_returns_False_if_enabled(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.autoimporter_enabled_for( self.no_pro) is False
def test_better_stats_enabled_for_non_pro_owner_and_non_pro_user_returns_False_if_enabled(self): pro_enabled_handler = ProFeatureHandler(self.config_enabled) assert pro_enabled_handler.better_stats_enabled_for(self.no_pro, self.no_pro) is False