Untitled conversation
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
{% extends 'students/base.html' %} {% block content %}
{% if error %} {{ error }} {% endif %}
{% if question.type == 'mcqs' %}
{% for option in question.options %}
<div class="form-check">
<input class="form-check-input" type="radio" name="answer" id="option{{ forloop.counter }}" value="{{ option }}" {% if selected == option %}checked{% endif %} required>
<label class="form-check-label" for="option{{ forloop.counter }}">{{ option }}</label>
</div>
{% endfor %}
{% elif question.type == 'blanks' %}
{% if question.options %}
<select name="answer" class="form-select" required>
<option value="" disabled {% if not selected %}selected{% endif %}>-- Select your answer --</option>
{% for option in question.options %}
<option value="{{ option }}" {% if selected == option %}selected{% endif %}>{{ option }}</option>
{% endfor %}
</select>
{% else %}
<input type="text" name="answer" class="form-control" value="{{ selected }}" placeholder="Type your answer..." required>
{% endif %}
{% elif question.type == 'coding' %}
<textarea name="answer" class="resizable-box" placeholder="Type your answer...">{{ selected }}</textarea>
{% if question.sample_input or question.sample_output %}
<div class="mt-3">
{% if question.sample_input %}
<p><strong>Sample Input:</strong></p>
<div class="code-block">{{ question.sample_input }}</div>
{% endif %}
{% if question.sample_output %}
<p><strong>Sample Output:</strong></p>
<div class="code-block">{{ question.sample_output }}</div>
{% endif %}
</div>
{% endif %}
{% else %}
<input type="text" name="answer" class="form-control" value="{{ selected }}" placeholder="Enter your answer" required>
{% endif %}
<div class="nav-buttons">
<button type="submit" name="action" value="prev" class="btn btn-secondary" {% if index == 1 %}disabled{% endif %}>Previous</button>
{% if index < total %}
<button type="submit" name="action" value="next" class="btn btn-primary">Next</button>
{% else %}
<button type="submit" name="action" value="submit" class="btn btn-success">Submit</button>
{% endif %}
</div>
Here's the updated exam.html with the timer functionality added:
{% extends 'students/base.html' %}
{% block content %}
<style>
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
body {
background: #f4f6f8;
font-family: 'Roboto', sans-serif;
color: #212121;
}
.exam-container {
max-width: 800px;
margin: 40px auto;
background: #fff;
padding: 32px 36px;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.question-count {
font-size: 16px;
font-weight: 500;
color: #616161;
margin-bottom: 20px;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.question-text {
font-size: 20px;
font-weight: 600;
color: #212121;
margin-bottom: 24px;
}
.form-check {
margin-bottom: 12px;
}
.form-check-input {
margin-right: 10px;
accent-color: #1976d2;
}
.form-check-label {
font-size: 16px;
color: #424242;
cursor: pointer;
}
.form-select,
.form-control,
textarea {
font-size: 16px;
width: 100%;
padding: 12px 14px;
margin-top: 8px;
border-radius: 8px;
border: 1px solid #ccc;
background-color: #fafafa;
transition: border-color 0.3s;
}
.form-select:focus,
.form-control:focus,
textarea:focus {
outline: none;
border-color: #1976d2;
background-color: #fff;
}
textarea {
resize: vertical;
min-height: 150px;
font-family: monospace;
}
.code-block {
background-color: #f1f3f4;
padding: 12px 16px;
border-radius: 6px;
font-family: monospace;
white-space: pre-wrap;
color: #37474f;
border-left: 4px solid #90caf9;
margin-top: 8px;
}
.nav-buttons {
display: flex;
justify-content: space-between;
margin-top: 30px;
}
.nav-buttons button {
min-width: 120px;
padding: 12px 0;
font-size: 14px;
font-weight: 500;
border-radius: 6px;
border: none;
cursor: pointer;
transition: background 0.2s ease;
}
.btn-secondary {
background-color: #e0e0e0;
color: #424242;
}
.btn-secondary:hover {
background-color: #d6d6d6;
}
.btn-primary {
background-color: #1976d2;
color: #fff;
}
.btn-primary:hover {
background-color: #1565c0;
}
.btn-success {
background-color: #2e7d32;
color: #fff;
}
.btn-success:hover {
background-color: #1b5e20;
}
.btn-secondary:disabled {
background-color: #eeeeee;
color: #9e9e9e;
cursor: not-allowed;
}
.alert {
background-color: #ffebee;
color: #c62828;
padding: 14px;
border-left: 4px solid #f44336;
margin-bottom: 16px;
border-radius: 6px;
font-size: 15px;
}
/* Timer styles */
#timer {
position: fixed;
top: 20px;
right: 20px;
background: #1976d2;
color: white;
padding: 12px 20px;
border-radius: 8px;
font-weight: 600;
font-size: 18px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
z-index: 1000;
display: flex;
align-items: center;
gap: 8px;
}
#timer.warning {
background: #ff6f00;
}
#timer.danger {
background: #d32f2f;
animation: pulse 1s infinite;
}
#timer svg {
width: 20px;
height: 20px;
}
@keyframes pulse {
0%, 50% { opacity: 1; transform: scale(1); }
25% { opacity: 0.8; transform: scale(1.05); }
75% { opacity: 0.8; transform: scale(0.95); }
}
/* Mobile responsive timer */
@media (max-width: 768px) {
#timer {
top: 10px;
right: 10px;
padding: 8px 12px;
font-size: 16px;
}
}
</style>
<div id="timer">
<svg fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-12a1 1 0 10-2 0v4a1 1 0 00.293.707l2.828 2.829a1 1 0 101.415-1.415L11 9.586V6z" clip-rule="evenodd"/>
</svg>
<span id="time-display">2:00</span>
</div>
<div class="exam-container">
<div class="question-count">Question {{ index }} of {{ total }}</div>
{% if error %}
<div class="alert">{{ error }}</div>
{% endif %}
<form method="post" id="exam-form">
{% csrf_token %}
<p class="question-text">{{ question.question }}</p>
{% if question.type == 'mcqs' %}
{% for option in question.options %}
<div class="form-check">
<input class="form-check-input" type="radio" name="answer" id="option{{ forloop.counter }}" value="{{ option }}" {% if selected == option %}checked{% endif %} required>
<label class="form-check-label" for="option{{ forloop.counter }}">{{ option }}</label>
</div>
{% endfor %}
{% elif question.type == 'blanks' %}
{% if question.options %}
<select name="answer" class="form-select" required>
<option value="" disabled {% if not selected %}selected{% endif %}>-- Select your answer --</option>
{% for option in question.options %}
<option value="{{ option }}" {% if selected == option %}selected{% endif %}>{{ option }}</option>
{% endfor %}
</select>
{% else %}
<input type="text" name="answer" class="form-control" value="{{ selected }}" placeholder="Type your answer..." required>
{% endif %}
{% elif question.type == 'coding' %}
<textarea name="answer" class="resizable-box" placeholder="Type your answer...">{{ selected }}</textarea>
{% if question.sample_input or question.sample_output %}
<div class="mt-3">
{% if question.sample_input %}
<p><strong>Sample Input:</strong></p>
<div class="code-block">{{ question.sample_input }}</div>
{% endif %}
{% if question.sample_output %}
<p><strong>Sample Output:</strong></p>
<div class="code-block">{{ question.sample_output }}</div>
{% endif %}
</div>
{% endif %}
{% else %}
<input type="text" name="answer" class="form-control" value="{{ selected }}" placeholder="Enter your answer" required>
{% endif %}
<div class="nav-buttons">
<button type="submit" name="action" value="prev" class="btn btn-secondary" {% if index == 1 %}disabled{% endif %}>Previous</button>
{% if index < total %}
<button type="submit" name="action" value="next" class="btn btn-primary">Next</button>
{% else %}
<button type="submit" name="action" value="submit" class="btn btn-success">Submit</button>
{% endif %}
</div>
</form>
</div>
<script>
// Timer functionality
let remainingSeconds = {{ remaining_seconds }};
let timerInterval;
let serverCheckInterval;
function formatTime(seconds) {
const minutes = Math.floor(seconds / 60);
const secs = seconds % 60;
return `${minutes}:${secs.toString().padStart(2, '0')}`;
}
function updateTimerDisplay() {
const timerElement = document.getElementById('timer');
const timeDisplay = document.getElementById('time-display');
if (remainingSeconds <= 0) {
clearInterval(timerInterval);
clearInterval(serverCheckInterval);
timeDisplay.textContent = '0:00';
timerElement.classList.add('danger');
// Show alert and auto-submit
alert('Time is up! Your exam will be submitted automatically.');
// Create a hidden submit button and click it
const form = document.getElementById('exam-form');
const submitBtn = document.createElement('button');
submitBtn.type = 'submit';
submitBtn.name = 'action';
submitBtn.value = 'submit';
submitBtn.style.display = 'none';
form.appendChild(submitBtn);
submitBtn.click();
return;
}
timeDisplay.textContent = formatTime(remainingSeconds);
// Change timer appearance based on remaining time
if (remainingSeconds <= 30) {
timerElement.classList.remove('warning');
timerElement.classList.add('danger');
} else if (remainingSeconds <= 60) {
timerElement.classList.add('warning');
}
remainingSeconds--;
}
// Check server time to prevent client-side manipulation
function checkServerTime() {
fetch('{% url "student_assessments:check_time" %}')
.then(response => response.json())
.then(data => {
if (data.time_up) {
remainingSeconds = 0;
updateTimerDisplay();
} else {
// Sync with server time if there's a significant difference
if (Math.abs(data.remaining_seconds - remainingSeconds) > 5) {
remainingSeconds = data.remaining_seconds;
}
}
})
.catch(error => {
console.error('Error checking server time:', error);
});
}
// Initialize timer
if (remainingSeconds > 0) {
updateTimerDisplay(); // Show initial time immediately
timerInterval = setInterval(updateTimerDisplay, 1000);
// Check server time every 15 seconds
serverCheckInterval = setInterval(checkServerTime, 15000);
// Also check server time immediately
checkServerTime();
} else {
// If no time remaining, submit immediately
document.getElementById('time-display').textContent = '0:00';
document.getElementById('timer').classList.add('danger');
setTimeout(() => {
alert('Time is up! Your exam will be submitted automatically.');
window.location.href = '{% url "student_assessments:result" %}';
}, 100);
}
// Warn before leaving the page
window.addEventListener('beforeunload', function (e) {
if (remainingSeconds > 0) {
e.preventDefault();
e.returnValue = 'Are you sure you want to leave? Your exam progress will be saved, but the timer will continue.';
}
});
// Handle visibility change (when user switches tabs)
document.addEventListener('visibilitychange', function() {
if (!document.hidden && remainingSeconds > 0) {
// When user returns to the tab, check server time
checkServerTime();
}
});
</script>
{% endblock %}
The key additions to your template include:
The timer integrates seamlessly with your existing design and provides a clear, visible countdown that helps students manage their time effectively during the 2-minute exam.