Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions searchapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class Board(models.Model):
board = models.CharField(
max_length=4,blank=False, null=False, default='CBSE', unique=True)

objects = models.Manager()

def __str__(self):
return self.board

Expand All @@ -48,6 +50,8 @@ class Grade(models.Model):
grade = MinMaxFloat(min_value=1, max_value=12, default=10)
board = models.ForeignKey('Board', on_delete=models.CASCADE)

objects = models.Manager()

def __str__(self):
return str(self.grade)

Expand All @@ -56,6 +60,8 @@ class Subject(models.Model):
subject_name = models.CharField(max_length=100, blank=False, null=False)
grade = models.ForeignKey('Grade', on_delete=models.CASCADE)

objects = models.Manager()

def __str__(self):
return self.subject_name

Expand Down Expand Up @@ -94,6 +100,8 @@ class Questions(models.Model):
text = models.TextField(null=False, blank=False)
source = models.TextField(null=True, blank=True)

objects = models.Manager()


class MCQOptions(models.Model):
question_id = models.ForeignKey('Questions', on_delete=models.CASCADE)
Expand Down Expand Up @@ -139,5 +147,7 @@ class Chapter(models.Model):
subject = models.ForeignKey('Subject', on_delete=models.CASCADE)
chapter_name = models.CharField(max_length=100)

objects = models.Manager()

def __str__(self):
return self.chapter_name
16 changes: 16 additions & 0 deletions searchapp/static/edit_questions.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.selectable-field {
/* padding: 1em 1em; */
display: flex;
justify-content: space-between;
}
.selectable-field:hover {
background: rgba(0, 0, 0, 0.05);
color: rgba(0, 0, 0, 0.95);
}
.pencil {
cursor: pointer;
transition: 0.3s;
}
.pencil:hover {
font-size: 1.2em;
}
131 changes: 131 additions & 0 deletions searchapp/static/edit_questions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
$(document).ready(() => {
$('#board').dropdown({
onChange: value => filter(value, 'board')
});
$('#grade').dropdown({
onChange: value => filter(value, 'grade')
});
$('#subject').dropdown({
onChange: value => filter(value, 'subject')
});
$('#chapter').dropdown({
onChange: value => filter(value, 'chapter')
});
$('#question_type').dropdown({
onChange: value => filter(value, 'question_type')
});
$('#question_weightage').dropdown({
onChange: value => filter(value, 'question_weightage')
});
$('#text').keyup(function (e) {
e.preventDefault();
filter(e.target.value, 'text');
});
$('.modal .actions .deny').click(function(e) {
e.target.parentElement.previousElementSibling.children[0].value = '';
})
$('.modal .actions .positive').click(function(e) {
let element = $(this).parent().prev().children('input');
let data = {
id: element.attr('question'),
text: element.val(),
csrfmiddlewaretoken: $('input[name="csrfmiddlewaretoken"]').val()
}
$.ajax({
type: "post",
url: "/edit_questions",
data,
dataType: "json",
success: resp => {
questions = questions.map(question => {
if (question.id === resp.id) question.text = resp.text;
return question
})
filter(null, 'chapter')
new PNotify({
title: 'Success!',
text: 'Question successfully edited in the database',
type: 'success'
});
},
error: err => {
new PNotify({
title: 'Error',
text: err.responseJSON.error,
type: 'error'
});
}
});
})
fill_rows(questions);
})

let questions = JSON.parse($('#questions')[0].innerHTML);
$('#questions').remove();
let filters = {
board: [],
grade: [],
subject: [],
chapter: [],
question_type: [],
question_weightage: [],
text: ''
}

const fill_rows = questions => {
let rows = ``
for (var question of questions) {
rows += `
<tr question="${question.id}">
<td>${question.board}</td>
<td>${question.grade}</td>
<td>${question.subject}</td>
<td>${question.chapter}</td>
<td>${question.question_type}</td>
<td>${question.question_weightage}</td>
<td class="selectable-field icon">
<span class="text">${question.text}</span>
<i class="pencil alternate icon"></i>
</td>
</tr>
`
}
$('#questions_table').html(rows);
$('.pencil').click(function(e) {
$('.modal .content input').val(e.target.previousElementSibling.innerText);
$('.modal .content input').attr('question', $(this).parent().parent().attr('question'));
$('.ui.modal').modal('show');
})
}


const filter = (value, field) => {
if (value !== null) {
const values = field != 'text' ? value.split(',') : [value];
// console.log(values)
filters[field] = values;
}
if (filters[field].includes("")) filters[field] = []
// console.log(value)
// console.log(filters)
let filtered_questions = questions.filter(question => {
let removed = false;
// console.log(question)
Object.keys(filters).forEach(filter => {
if (removed) return;
// console.log(filter)
// console.log(question[filter])
Copy link
Copy Markdown
Collaborator

@ishanisri ishanisri Dec 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all console.log()

// console.log(filters[filter].length != 0 && !filters[filter].includes(question[filter]))
if (filter == 'text') {
if (filters[filter].length != 0 && !question[filter].toLowerCase().includes(filters[filter][0].toLowerCase())) {
removed = true;
}
}
else if (filters[filter].length != 0 && !filters[filter].includes(question[filter])) {
removed = true;
}
})
return !removed;
});
fill_rows(filtered_questions);
}
10 changes: 9 additions & 1 deletion searchapp/static/student_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ $(document).ready(function(){
});
});
},
error: err => {
new PNotify({
title: err.responseJSON.error,
text: 'Click here to login',
type: 'error',
});
$('.brighttheme-error').click(() => window.location.href = '/login?next=/student_view')
}
});
}
}
Expand All @@ -126,7 +134,7 @@ function upload_click(e) {
let subject = $("#customized-subject").dropdown('get value');
let file_data = $('#realfile').prop("files")[0];
let formData = new FormData();
formData.append("file",file_data);
formData.append("file", file_data);
formData.append('subject',subject);
$.ajax({
enctype: 'multipart/form-data',
Expand Down
126 changes: 126 additions & 0 deletions searchapp/templates/edit_questions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{% extends "layout.html" %}
{% load static %}

{% block title %}
Edit Questions
{% endblock %}
{% block li %}
{% if user.is_authenticated %}
<li><a href="/mentor_view">Mentor Dashboard</a></li>
{% else %}
<li><a href="/login">Login</a></li>
{% endif %}
{% endblock %}
{% block student_view %}
<!-- Select worksheet type -->
<br>

<div id="div">
<div id="board" class="ui fluid multiple search selection dropdown chapter">
<input name="board" type="hidden">
<i class="dropdown icon"></i>
<div class="default text">Select board</div>
<div id="board-options-parent" class="menu">
{% for element in boards %}
<div class="item" data-value="{{element}}">{{element}}</div>
{% endfor %}
</div>
</div>
<br>
<div id="grade" class="ui fluid multiple search selection dropdown chapter">
<input name="grade" type="hidden">
<i class="dropdown icon"></i>
<div class="default text">Select Grade</div>
<div id="grade-options-parent" class="menu">
{% for element in grades %}
<div class="item" data-value="{{element}}">{{element}}</div>
{% endfor %}
</div>
</div>
<br>
<div id="subject" class="ui fluid multiple search selection dropdown chapter">
<input name="subject" type="hidden">
<i class="dropdown icon"></i>
<div class="default text">Select Subject</div>
<div id="board-options-parent" class="menu">
{% for element in subjects %}
<div class="item" data-value="{{element}}">{{element}}</div>
{% endfor %}
</div>
</div>
<br>
<div id="chapter" class="ui fluid multiple search selection dropdown chapter">
<input name="chapter" type="hidden">
<i class="dropdown icon"></i>
<div class="default text">Select Chapter</div>
<div id="chapter-options-parent" class="menu">
{% for element in chapters %}
<div class="item" data-value="{{element}}">{{element}}</div>
{% endfor %}
</div>
</div>
<br>
<div id="question_type" class="ui fluid multiple search selection dropdown chapter">
<input name="question_type" type="hidden">
<i class="dropdown icon"></i>
<div class="default text">Select Question Type</div>
<div id="question_type-options-parent" class="menu">
{% for element in question_types %}
<div class="item" data-value="{{element}}">{{element}}</div>
{% endfor %}
</div>
</div>
<br>
<div id="question_weightage" class="ui fluid multiple search selection dropdown chapter">
<input name="question_weightage" type="hidden">
<i class="dropdown icon"></i>
<div class="default text">Select Question Weightage</div>
<div id="question_weightage-options-parent" class="menu">
{% for element in question_weightage %}
<div class="item" data-value="{{element}}">{{element}}</div>
{% endfor %}
</div>
</div>
<br>
<div id="text" class="ui fluid search icon input chapter">
<i class="search icon"></i>
<input type="text" placeholder="Search by text">
</div>
<br>
</div>
<br>
<!-- <button id="submit">GET QUESTIONS</button> -->
<table class="ui celled padded table">
<thead>
<tr>
<th>Board</th>
<th>Grade</th>
<th>Subject</th>
<th>Chapter</th>
<th>Question Type</th>
<th>Question Weightage</th>
<th>Text</th>
</tr>
</thead>
<tbody id="questions_table"></tbody>
</table>
<div class="ui modal">
{% csrf_token %}
<div class="header">Edit question</div>
<div class="ui input content">
<input type="text" placeholder="Question here" style="width: 100%;">
</div>
<div class="actions">
<div class="ui black deny button">Cancel</div>
<div class="ui positive right button">Save</div>
</div>
</div>
{% endblock %}
{% block js %}
<link rel="stylesheet" type="text/css" href="{% static 'edit_questions.css' %}"/>
<script type="application/json" id="questions">
{{questions|safe}}
</script>

<script type="text/javascript" src="{% static 'edit_questions.js' %}"></script>
{% endblock %}
7 changes: 4 additions & 3 deletions searchapp/templates/mentor_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
<br>
<div class="dashboard">
<div class="ui grid">
<div class="four wide column"><div class="button"><a href="questions_upload" class="button">Upload Questions</a></div></div>
<div class="four wide column"><div class="button"><a href="generated_documents" class="button">View Generated Customized Paper</a></div></div>
<div class="four wide column"><div class="button"><a href="chapter_and_split_view" class="button">Add and Delete Chapters and Subject Splits</a></div></div>
<div class="three wide column"><div class="button"><a href="questions_upload" class="button">Upload Questions</a></div></div>
<div class="three wide column"><div class="button"><a href="generated_documents" class="button">View Generated Customized Paper</a></div></div>
<div class="three wide column"><div class="button"><a href="chapter_and_split_view" class="button">Add and Delete Chapters and Subject Splits</a></div></div>
<div class="three wide column"><div class="button"><a href="{% url 'searchapp:edit_questions' %}" class="button">Edit questions</a></div></div>
</div>
</div>
{% endblock %}
1 change: 1 addition & 0 deletions searchapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
path('logout', views.logout_view, name='logout'),
path('mentor_view', views.mentor_view, name='mentor_view'),
path('student_view', views.student_view, name='student_view'),
path('edit_questions', views.edit_questions, name='edit_questions'),
path('chapter_and_split_view', views.chapter_and_split_view, name='chapter_and_split_view'),
path('get_chapters', views.get_chapters, name='get_chapters'),
path('add_chapter', views.add_chapter, name='add_chapter'),
Expand Down
Loading