Skip to content

Commit

Permalink
Merge pull request #7 from arielfayol37/master
Browse files Browse the repository at this point in the history
Master
  • Loading branch information
arielfayol37 authored Aug 19, 2023
2 parents 3b24f49 + 3062a47 commit 03aec4e
Show file tree
Hide file tree
Showing 32 changed files with 461 additions and 101 deletions.
6 changes: 6 additions & 0 deletions attacks.txt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
If the validation of algebraic expressions is done on
the front-end using mathjs' symbolicEqual() function.
So someone can modify the fetch() that gets the real answer
from the server.
Hence the reason why sympy is used in the backend for that,
and not mathjs.
Binary file modified db.sqlite3
Binary file not shown.
Binary file modified deimos/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file removed deimos/__pycache__/tests.cpython-311.pyc
Binary file not shown.
Binary file modified deimos/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file modified deimos/__pycache__/views.cpython-311.pyc
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.3 on 2023-08-19 00:26

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('deimos', '0005_alter_questionattempt_content'),
]

operations = [
migrations.AddField(
model_name='questionattempt',
name='timestamp',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='questionstudent',
name='success',
field=models.BooleanField(default=False),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.3 on 2023-08-19 01:49

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('deimos', '0006_questionattempt_timestamp_questionstudent_success'),
]

operations = [
migrations.RenameField(
model_name='questionattempt',
old_name='is_successful',
new_name='success',
),
]
Binary file not shown.
Binary file not shown.
5 changes: 3 additions & 2 deletions deimos/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class QuestionStudent(models.Model):
student = models.ForeignKey(Student, on_delete=models.CASCADE)
question = models.ForeignKey(Question, on_delete=models.CASCADE)
num_points = models.FloatField(default=0)

success = models.BooleanField(default=False)
def get_num_points(self):
"""
Calculates adn returns the number of points a student gets from a question
Expand Down Expand Up @@ -140,8 +140,9 @@ class QuestionAttempt(models.Model):
"""
content = models.CharField(max_length=1000, blank=False, null=False)
question_student = models.ForeignKey(QuestionStudent, on_delete=models.CASCADE, related_name='attempts')
is_successful = models.BooleanField(default=False, null=True)
success = models.BooleanField(default=False, null=True)
num_points = models.FloatField(default=0, null=True)
timestamp = models.DateTimeField(auto_now_add=True)

def __str__(self):
return f"{self.question_student.student.username} attempt for {self.question_student.question}"
102 changes: 102 additions & 0 deletions deimos/static/deimos/css/action_menu.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

.navigation-m{
margin-top: 5%;
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
.menuToggle {
position: relative;
width: 70px;
height: 70px;
background: #fff;
border-radius: 70px;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0 15px 25px rgba(0,0,0,0.15);
}
.menuToggle::before{
content:'+';
position: absolute;
font-size: 3em;
font-weight: 200;
color: #ff216d;
transition: 1.5s;
}
.menuToggle.active::before {
transform: rotateX(80deg);
}

.menu {
position: absolute;
width: 30px;
height:30px;
background: #fff;
border-radius: 70px;
z-index: -1;
transition: transform 0.5s, width 0.5s, height 0.5s;
transition-delay: 1s, 0.5s, 0.5s;
transition-timing-function: cubic-bezier(0.075, 0.82, 0.165, 1);
}

.menuToggle.active ~ .menu {
width: 240px;
height: 70px;
z-index: 1;
transform: translateY(-100px);
transition-delay: 0s, 0.5s, 0.5s;
box-shadow: 0 15px 25px rgba(0,0,0,0.15);
}

.menu::before
{
content: '';
position: absolute;
width: 16px;
height: 16px;
background:#fff;
left: calc(50% - 8px);
bottom: 4px;
transform: rotate(45deg);
border-radius: 2px;
transition: 0.5s;
}
.menuToggle.active ~ .menu::before{
transition-delay: 0.5s;
bottom: -6px;
}
.menu ul {
position: relative;
display: flex;
justify-content: center;
align-items: center;
height: 80px;
gap: 40px;
}
.menu ul li{
list-style: none;
cursor: pointer;
opacity: 0;
visibility: hidden;
transform: translateY(-30px);
transition: 0.25s;
transition-delay: calc(0s + var(--i));
}
.menuToggle.active ~ .menu ul li {
opacity: 1;
visibility: visible;
transform: translate(0px);
transition-delay: calc(0.75s + var(--i));
}
.menu ul li a{
display: block;
font-size: 2em;
text-decoration: none;
color: #555;
}
.menu ul li:hover a {
color: #ff216d;
}
11 changes: 11 additions & 0 deletions deimos/static/deimos/js/action_menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
document.addEventListener('DOMContentLoaded',()=>{

const menuToggle = document.querySelector('.menuToggle');
if (menuToggle != null){
menuToggle.addEventListener('click', (event)=>{
event.preventDefault();
menuToggle.classList.toggle('active');
})
}

})
88 changes: 87 additions & 1 deletion deimos/static/deimos/js/answer_input.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,52 @@
document.addEventListener('DOMContentLoaded', ()=> {
const answerFieldsDiv = document.querySelector('.answer-fields');
const form = document.querySelector('#question-form');
let currentAction = form.getAttribute('action');
const validateAnswerActionURL = extractQuestionPath(window.location.href) + '/validate_answer';
//console.log(newActionURL);
//form.setAttribute('action', newActionURL);
const submitBtn = document.querySelector('#submit-btn');
const formattedAnswerDiv = document.querySelector('.formatted-answer');
const calculatorDiv = document.querySelector('.calculator');
const inputedMcqAnswersDiv = document.querySelector('.inputed-mcq-answers');
var num_true_counter = 0;
const screen = document.querySelector('#screen');
const questionType = document.querySelector('.question-type');

/*-----------------------------Question submission-----------------------*/

submitBtn.addEventListener('click', (event)=>{
event.preventDefault();
if (questionType.value==='structural'){
fetch(`/${validateAnswerActionURL}`, {
method: 'POST',
headers: { 'X-CSRFToken': getCookie('csrftoken') },
body: JSON.stringify({
answer: screen.value,
questionType: questionType.value
})
})
.then(response => response.json())
.then(result => {
// Print result
console.log(result.correct);
});
} else if( questionType.value ==='mcq'){
fetch(`/${validateAnswerActionURL}`, {
method: 'POST',
headers: { 'X-CSRFToken': getCookie('csrftoken') },
body: JSON.stringify({
answer: getSelectedTrueAnswerIds(),
questionType: questionType.value
})
})
.then(response => response.json())
.then(result => {
// Print result
console.log(result.correct);
});
}

});

/*----------------------------DISPLAYING LATEX-------------------------*/

Expand Down Expand Up @@ -81,6 +121,7 @@ displayLatex();


form.addEventListener('submit', (event)=>{
event.preventDefault();
if (!(screen === null)){
const userInputNode = math.parse(screen.value);
var userInputString = userInputNode.toString();
Expand All @@ -104,4 +145,49 @@ function setCharAt(str,index,chr) {
return str.substring(0,index) + chr + str.substring(index+1);
}

function extractQuestionPath(url) {
const startIndex = url.indexOf('deimos');
if (startIndex !== -1) {
return url.substring(startIndex);
} else {
return null; // If 'courses' not found in URL
}
}


function getCookie(name) {
if (!document.cookie) {
return null;
}

const csrfCookie = document.cookie
.split(';')
.map(c => c.trim())
.find(c => c.startsWith(name + '='));

if (!csrfCookie) {
return null;
}

return decodeURIComponent(csrfCookie.split('=')[1]);
}

function getSelectedTrueAnswerIds() {
const mcqOptions = document.querySelectorAll('.mcq-option-answer');
const selectedAnswerIds = [];

mcqOptions.forEach((option) => {
const answerIdInput = option.querySelector('.answer_id');
const answerInfoInput = option.querySelector('.answer_info');

if (answerIdInput && answerInfoInput && answerInfoInput.value.charAt(0) === '1') {
selectedAnswerIds.push(answerIdInput.value);
}
});

return selectedAnswerIds;
}


});

20 changes: 20 additions & 0 deletions deimos/templates/deimos/action_menu.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!--deimos: action_menu.html-->
<div class="navigation-m">
<div class="menuToggle"></div>
<div class="menu">
<ul>
<li style="--i:0.1s;">
<a href="#"><ion-icon name="pencil-outline"></ion-icon>
</a>
</li>
<li style="--i:0.2s;">
<a href="#"><ion-icon name="camera-outline"></ion-icon>
</a>
</li>
<li style="--i:0.3s;">
<a href="#"><ion-icon name="mail-unread-outline"></ion-icon>
</a>
</li>
</ul>
</div>
</div>
Loading

0 comments on commit 03aec4e

Please sign in to comment.