how to add racord my (Que) field from mysql database
below is my code.
this is my .js code
frappe.pages[‘subject’].on_page_load = function(wrapper) {
frappe.subject = new frappe.Subject(wrapper);
frappe.breadcrumbs.add(“subject”, “Assignment”);
}
frappe.Subject = Class.extend({
init: function(parent) {
this.parent = parent;
this.make();
this.refresh();
},
refresh: function() {
//if(!this.assignment)
{
this.show_start();
}
},
make: function() {
this.page = frappe.ui.make_app_page({
parent: this.parent,
title: (“Test”),
single_column: true
});
},
show_start: function() {
this.page.main.html(frappe.render_template(“assignment_builder_start”, {}));
// this.page.clear_actions();
this.page.set_title((“Test”));
this.start_question();
this.start_answare();
},
start_question: function(sql) {
//sql.executeSql("""select q_1 FROM `tabAdd Test Question` where tabAssignment.subject_name = %s""")
var me = this;
//this.more.find(".btn").on("click", function() { me.next_question() });
//date controler
var date = new Date();
var day = date.getDate();
var month = date.getMonth() + 1;
var year = date.getFullYear();
if (month < 10) month = "0" + month;
if (day < 10) day = "0" + day;
var today = day + "-" + month + "-" + year;
document.getElementById("theDate").value = today;
//time controller
function countdown(minutes) {
var seconds = 60;
var mins = minutes
function tick() {
var counter = document.getElementById("timer");
var current_minutes = mins-1
seconds--;
counter.innerHTML =
current_minutes.toString() + ":" + (seconds < 10 ? "0" : "") + String(seconds);
if( seconds > 0 ) {
setTimeout(tick, 1000);
} else {
if(mins > 1){
//alert("Time's up!")
//return;
// countdown(mins-1); never reach “00″ issue solved:Contributed by Victor Streithorst
setTimeout(function () { countdown(mins - 1); }, 1000);
}
}
}
tick();
}
countdown(5);
this.question_input = frappe.ui.form.make_control({
parent: this.page.main.find(".question"),
df: {
fieldtype: "Data",
label: __("Que"),
},
render_input: true
});
},
start_answare: function() {
var me = this;
this.answare_input = frappe.ui.form.make_control({
parent: this.page.main.find(".answare"),
df: {
fieldtype: "Small Text",
label: __("Ans")
},
render_input: true
});
},
//page.main.find(".btn-next_question").on("click", function() {
// erpnext.open_as_pos = true;
// new_doc(pos_type.get_value());
});
this is my html code
<div class="question"></div>
{%= __("<< Previous") %} {%= __("Next >>") %}
this is my .py code
Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
License: GNU General Public License v3. See license.txt
from future import unicode_literals
import frappe
import time
import subject
class Subject(Document):
'''def countdown(t):
while t:
mins, secs = divmod(t, 60)
timeformat = '{:02d}:{:02d}'.format(mins, secs)
print(timeformat, end='\r')
time.sleep(1)
t -= 1
print('Time is Over')'''
def strat_question(self):
if frappe.db.sql("""select t1.q_1 FROM `tabAdd Test Question` t1
WHERE tabAssignment.subject_name = %s """,
(self.subject_name))
if submit_question:
frappe.throw(_(".format(self.submit_question[0][0]))