Skip to content

Commit

Permalink
Merge pull request #1 from mysterymask/master
Browse files Browse the repository at this point in the history
来自mysterymask的更新
  • Loading branch information
hanc00l authored Jul 10, 2017
2 parents 88dd60e + 4efe1f3 commit 0a5599f
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 36 deletions.
2 changes: 1 addition & 1 deletion runserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#-*- coding: utf-8 -*-
from webexam import app

app.run(host='0.0.0.0',debug=True)
app.run(host='0.0.0.0',debug=True,threaded=True)
36 changes: 31 additions & 5 deletions webexam/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,20 @@ def delete(self, id):
ids = id.split(',')
try:
for _id in ids:
obj = self.obj_instance.get(self.instance).query.filter(
text('id==%s' % _id)).first()
db_session.delete(obj)
#
if self.instance == 'subject':
if self.instance == 'lib':
self.__delete_lib_related(_id)
elif self.instance == 'section':
self.__delete_seciton_related(_id)
elif self.instance == 'subject':
self.__delete_subject_option_and_other(_id)
elif self.instance == 'user':
self.__delete_user_subject_and_other(_id)

obj = self.obj_instance.get(self.instance).query.filter(text('id==%s' % _id)).first()
db_session.delete(obj)

db_session.commit()
print obj
return json.dumps({'status': 'ok', 'msg': u'记录删除成功!'})
except:
return json.dumps({'status': 'fail', 'msg': u'记录删除失败!'})
Expand All @@ -269,6 +274,27 @@ def delete_all(self):
except:
return json.dumps({'status': 'fail', 'msg': u'记录删除失败!'})

def __delete_lib_related(self,lib_id):
'''
级联删除题库相关联数据
'''

obj = self.obj_instance.get('section').query.filter(text('libid==%s' % lib_id)).all()
for a_obj in obj:
self.__delete_seciton_related(a_obj.id)
self.obj_instance.get('section').query.filter(text('id==%s' % a_obj.id)).delete(synchronize_session=False)
db_session.commit()

def __delete_seciton_related(self,section_id):
'''
级联删除章节关联数据
'''
obj = self.obj_instance.get('subject').query.filter(text('sectionid==%s' % section_id)).all()
for a_obj in obj:
self.__delete_subject_option_and_other(a_obj.id)
self.obj_instance.get('subject').query.filter(text('id==%s' % a_obj.id)).delete(synchronize_session=False)
db_session.commit()

def __delete_subject_option_and_other(self,subject_id):
self.obj_instance.get('option').query.filter(
text('subjectid==%s' % subject_id)).delete(synchronize_session=False)
Expand Down
1 change: 1 addition & 0 deletions webexam/templates/exam_start.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ <h4 class="panel-title ">选择练习的试题
url = '/admin/{{instance}}/count?libid='+data.libid+'&&sectionid='+data.sectionid+"&&subjecttype="+data.subjecttype+"&&degree="+data.degree;
$.getJSON(url,function(data){
$('#spanTotal_'+index).text(data.total_rows);
$('#inputCount_'+index).val(data.total_rows);
});
}
function check_count(index){
Expand Down
21 changes: 12 additions & 9 deletions webexam/templates/lib.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,20 @@ <h4 class="modal-title" id="myModalLabel">题库编辑
if(ids.length<1) return;
obj_ids=''
sep=''
for(i=0;i<ids.length;i++){
if($(ids[i]).is(':checked')){
id=$(ids[i]).attr('value');
obj_ids +=sep
obj_ids +=id
sep = ','
var res = confirm("确定删除相关数据?");
if(res){
for(i=0;i<ids.length;i++){
if($(ids[i]).is(':checked')){
id=$(ids[i]).attr('value');
obj_ids +=sep
obj_ids +=id
sep = ','
}
}
$.getJSON('/admin/lib/delete/'+obj_ids,function(data){
refresh();
})
}
$.getJSON('/admin/lib/delete/'+obj_ids,function(data){
refresh();
})
}
function get_selected_lib(){
ids = $('input[type="checkbox"]');
Expand Down
24 changes: 14 additions & 10 deletions webexam/templates/section.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,21 @@ <h4 class="modal-title" id="myModalLabel">章节编辑
if(ids.length<1) return;
obj_ids=''
sep=''
for(i=0;i<ids.length;i++){
if($(ids[i]).is(':checked')){
id=$(ids[i]).attr('value');
obj_ids +=sep
obj_ids +=id
sep = ','
}
var res = confirm("确定删除相关数据?");
if(res){
for(i=0;i<ids.length;i++){
if($(ids[i]).is(':checked')){
id=$(ids[i]).attr('value');
obj_ids +=sep
obj_ids +=id
sep = ','
}
}
$.getJSON('/admin/section/delete/'+obj_ids,function(data){
refresh();
})
}
$.getJSON('/admin/section/delete/'+obj_ids,function(data){
refresh();
})

}
</script>
</div>
Expand Down
25 changes: 14 additions & 11 deletions webexam/templates/subject.html
Original file line number Diff line number Diff line change
Expand Up @@ -501,17 +501,20 @@ <h4 class="panel-title ">选项及答案
if(ids.length<1) return;
obj_ids=''
sep=''
for(i=0;i<ids.length;i++){
if($(ids[i]).is(':checked')){
id=$(ids[i]).attr('value');
obj_ids +=sep
obj_ids +=id
sep = ','
}
}
$.getJSON('/admin/subject/delete/'+obj_ids,function(data){
refresh();
})
var res = confirm("确定删除相关数据?");
if(res){
for(i=0;i<ids.length;i++){
if($(ids[i]).is(':checked')){
id=$(ids[i]).attr('value');
obj_ids +=sep
obj_ids +=id
sep = ','
}
}
$.getJSON('/admin/subject/delete/'+obj_ids,function(data){
refresh();
})
}
}
function generate_one_option(id,value){
divHtml='<div class="input-group">\
Expand Down

0 comments on commit 0a5599f

Please sign in to comment.