this is .js file
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 .html file***
<div style="float: right">
Date:<input type="date" id="theDate" readonly>
<!--<div id="timer">5m:00s</div>-->
</div>
<div class="padding" style="max-width: 300px;">
<div class="question"></div>
</div>
<div class="padding" style="max-width: 300px;">
<div class="answare"></div>
<!-- <div class="name-selector"></div>-->
<p>
<button class="btn btn-sm btn-default btn-previos-question">
{%= __("<< Previous") %}</button>
<button class="btn btn-sm btn-default btn-next-question">
{%= __("Next >>") %}</button>
</p>
</div>
this is .py file
from __future__ import unicode_literals
import frappe
import time
import MySQLdb
import subject
db = MySQLdb.connect("localhost", "root", "gSbku0ExRIa4AtW1", "1db3e0294d")
cursor = db.cursor()
id, q_1, q_2, q_3, q_4, q_5 = [],[],[],[],[]
sql = "SELECT * FROM tabAdd Test Question"
try:
cursor.execute(sql)
rcount = int(cursor.rowcount)
for r in rcount:
row = cursor.fetchone()
id.append(row[0])
q_1.append(row[1])
q_2.append(row[2])
q_3.append(row[3])
q_4.append(row[4])
q_5.append(row[5])
except:
print "Error: unable to fecth data"
#today = datetime.now().date() + timedelta(days=1)
add_answare = ("INSERT INTO tabassignment_answare "
"(date, q_1, ans_1, q_2, ans_2, q_3, ans_3, q_4, ans_4, q_5, ans_5)"
"VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)")
cursor.execute(add_answare)
db.close()