Skip to content

Commit e248f7f

Browse files
authored
Merge pull request #3980 from ccnmtl/submission-cleanup
Clean up Submission model and UI
2 parents 12cc11a + b5a9e9d commit e248f7f

File tree

8 files changed

+35
-156
lines changed

8 files changed

+35
-156
lines changed

econplayground/api/serializers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,7 @@ class SubmissionSerializer(serializers.ModelSerializer):
231231
class Meta:
232232
model = Submission
233233
fields = (
234-
'graph', 'score',
235-
'feedback_fulfilled', 'feedback_unfulfilled',
236-
'created_at',
234+
'graph', 'score', 'created_at',
237235
)
238236

239237

econplayground/api/tests/test_views.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,16 +462,12 @@ def test_create(self):
462462

463463
response = self.client.post('/api/submissions/', {
464464
'graph': self.g2.pk,
465-
'feedback_unfulfilled': 'a;;b',
466-
'feedback_fulfilled': 'success!',
467465
'score': 0.6,
468466
})
469467
s = Submission.objects.last()
470468
self.assertEqual(response.status_code, 201)
471469
self.assertEqual(Submission.objects.count(), 2)
472470
self.assertEqual(s.score, Decimal('0.6'))
473-
self.assertEqual(s.feedback_unfulfilled, 'a;;b')
474-
self.assertEqual(s.feedback_fulfilled, 'success!')
475471

476472
def test_create_dup_fail(self):
477473
response = self.client.post('/api/submissions/', {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Generated by Django 5.2.1 on 2025-05-29 20:06
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('main', '0127_cohort_context_id_cohort_deployment_id'),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name='submission',
15+
name='feedback_fulfilled',
16+
),
17+
migrations.RemoveField(
18+
model_name='submission',
19+
name='feedback_unfulfilled',
20+
),
21+
]

econplayground/main/models.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,5 @@ class Meta:
550550
# Corresponds to the line_x_x_score
551551
score = models.DecimalField(max_digits=8, decimal_places=4, default=0)
552552

553-
feedback_fulfilled = models.TextField(blank=True, default='')
554-
feedback_unfulfilled = models.TextField(blank=True, default='')
555-
556553
created_at = models.DateTimeField(auto_now_add=True)
557554
updated_at = models.DateTimeField(auto_now=True)

econplayground/main/tests/factories.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ class Meta:
111111

112112
graph = factory.SubFactory(GraphFactory)
113113
user = factory.SubFactory(UserFactory)
114-
feedback_fulfilled = fuzzy.FuzzyText()
115-
feedback_unfulfilled = fuzzy.FuzzyText()
116114
score = fuzzy.FuzzyDecimal(0.0, 1.0)
117115

118116

econplayground/main/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ class GraphEmbedPublicMinimalView(
363363
model = Graph
364364
template_name = 'main/graph_embed_public_minimal.html'
365365

366+
def post(self, request, pk):
367+
pass
368+
366369

367370
class GraphDeleteView(LoginRequiredMixin, CohortInstructorMixin, DeleteView):
368371
model = Graph

media/js/src/GraphViewer.jsx

Lines changed: 10 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import * as commonmark from 'commonmark';
4-
import Assessment from './Assessment.js';
54

65
import ADASEditor from './editors/ADASEditor.jsx';
76
import CobbDouglasEditor from './editors/CobbDouglasEditor.jsx';
@@ -25,12 +24,9 @@ import PositiveExternalityIndustryEditor from
2524

2625
import ExportGraphButton from './buttons/ExportGraphButton.jsx';
2726
import ResetGraphButton from './buttons/ResetGraphButton.jsx';
28-
import SubmitButton from './buttons/SubmitButton.jsx';
2927
import JXGBoard from './JXGBoard.jsx';
3028
import Feedback from './Feedback.jsx';
31-
import {
32-
forceFloat, getOrCreateSubmission, BOARD_WIDTH, BOARD_HEIGHT
33-
} from './utils';
29+
import {BOARD_WIDTH, BOARD_HEIGHT} from './utils';
3430
import RevenueElasticityEditor from './editors/RevenueElasticityEditor.jsx';
3531
import TaxRevenueEditor from './editors/TaxRevenueEditor.jsx';
3632

@@ -214,7 +210,7 @@ export default class GraphViewer extends React.Component {
214210
<div className="GraphViewer">
215211
{titleEl}
216212
{instructionsEl}
217-
<form onSubmit={this.handleSubmit.bind(this)} action={action} method="post">
213+
<form action={action} method="post">
218214
<input type="hidden" name="csrfmiddlewaretoken" value={token} />
219215
<input type="hidden" name="score" value={this.state.score} />
220216
<input type="hidden" name="next" value={successUrl} />
@@ -228,17 +224,13 @@ export default class GraphViewer extends React.Component {
228224

229225
{rightSide}
230226

227+
<hr />
228+
231229
<ResetGraphButton
232230
initialState={initialState}
233231
updateGraph={this.updateGraph} />
234232

235233
<ExportGraphButton />
236-
237-
<SubmitButton
238-
assessment={this.props.assessment}
239-
gNeedsSubmit={this.props.gNeedsSubmit}
240-
submission={this.props.submission}
241-
isInstructor={isInstructor} />
242234
</form>
243235
</div>
244236
);
@@ -301,7 +293,7 @@ export default class GraphViewer extends React.Component {
301293
<div className="GraphViewer">
302294
{titleEl}
303295
{instructionsEl}
304-
<form onSubmit={this.handleSubmit.bind(this)} action={action} method="post">
296+
<form action={action} method="post">
305297
<input type="hidden" name="csrfmiddlewaretoken" value={token} />
306298
<input type="hidden" name="score" value={this.state.score} />
307299
<input type="hidden" name="next" value={successUrl} />
@@ -315,17 +307,13 @@ export default class GraphViewer extends React.Component {
315307

316308
{rightSide}
317309

310+
<hr />
311+
318312
<ResetGraphButton
319313
initialState={initialState}
320314
updateGraph={this.updateGraph} />
321315

322316
<ExportGraphButton />
323-
324-
<SubmitButton
325-
assessment={this.props.assessment}
326-
gNeedsSubmit={this.props.gNeedsSubmit}
327-
submission={this.props.submission}
328-
isInstructor={isInstructor} />
329317
</form>
330318
</div>
331319
);
@@ -363,7 +351,7 @@ export default class GraphViewer extends React.Component {
363351
<div className="GraphViewer">
364352
{titleEl}
365353
{instructionsEl}
366-
<form onSubmit={this.handleSubmit.bind(this)} action={action} method="post">
354+
<form action={action} method="post">
367355
<input type="hidden" name="csrfmiddlewaretoken" value={token} />
368356
<input type="hidden" name="score" value={this.state.score} />
369357
<input type="hidden" name="next" value={successUrl} />
@@ -381,98 +369,19 @@ export default class GraphViewer extends React.Component {
381369
<div className="col-lg-6">
382370
{rightSide}
383371

372+
<hr />
373+
384374
<ResetGraphButton
385375
initialState={initialState}
386376
updateGraph={this.updateGraph} />
387377

388378
<ExportGraphButton />
389-
390-
<SubmitButton
391-
assessment={this.props.assessment}
392-
gNeedsSubmit={this.props.gNeedsSubmit}
393-
submission={this.props.submission}
394-
isInstructor={isInstructor} />
395379
</div>
396380
</div>
397381
</form>
398382
</div>
399383
);
400384
}
401-
// When the submission is loaded by the Viewer, see if
402-
// this.state.currentFeedback should be updated.
403-
componentDidUpdate(prevProps) {
404-
if (prevProps.submission !== this.props.submission) {
405-
this.loadFeedback(
406-
this.props.submission.feedback_unfulfilled,
407-
this.props.submission.feedback_fulfilled);
408-
}
409-
}
410-
loadFeedback(unfulfilledFeedback, fulfilledFeedback) {
411-
const currentFeedback = [];
412-
413-
unfulfilledFeedback = unfulfilledFeedback.split(';;');
414-
fulfilledFeedback = fulfilledFeedback.split(';;');
415-
416-
unfulfilledFeedback.forEach(e => {
417-
if (e) {
418-
currentFeedback.push({
419-
feedback: e,
420-
fulfilled: false
421-
});
422-
}
423-
});
424-
fulfilledFeedback.forEach(e => {
425-
if (e) {
426-
currentFeedback.push({
427-
feedback: e,
428-
fulfilled: true
429-
});
430-
}
431-
});
432-
433-
this.setState({currentFeedback: currentFeedback});
434-
}
435-
handleSubmit(event) {
436-
event.preventDefault();
437-
const assessment = new Assessment(this.props.assessment);
438-
const responses = assessment.evalState(this.props);
439-
440-
if (this.props.gNeedsSubmit) {
441-
// LTI Assessment graph submitted. Create a Submission
442-
// object and submit to Canvas with LTI.
443-
const form = event.target;
444-
445-
// Sum up the scores for all fulfilled rules.
446-
const scores = responses.map(x => forceFloat(x.score));
447-
const score = scores.reduce((a, b) => a + b, 0);
448-
449-
this.setState({score: score});
450-
451-
// Save the user's feedback on their Submission object to
452-
// make it persistent.
453-
const fulfilledFeedback = responses
454-
.filter(x => x.fulfilled)
455-
.map(x => x.feedback)
456-
.join(';;');
457-
const unfulfilledFeedback = responses
458-
.filter(x => !x.fulfilled)
459-
.map(x => x.feedback)
460-
.join(';;');
461-
462-
getOrCreateSubmission({
463-
graph: this.props.gId,
464-
feedback_fulfilled: fulfilledFeedback,
465-
feedback_unfulfilled: unfulfilledFeedback,
466-
score: score
467-
}).then(function() {
468-
form.submit();
469-
});
470-
} else {
471-
// Practice Assessment submitted. Show feedback
472-
// immediately.
473-
this.setState({currentFeedback: responses});
474-
}
475-
}
476385
updateGraph(state) {
477386
this.setState({currentFeedback: state.currentFeedback});
478387
return this.props.updateGraph(state);
@@ -484,7 +393,6 @@ GraphViewer.propTypes = {
484393
gType: PropTypes.number,
485394
gTitle: PropTypes.string,
486395
gInstructions: PropTypes.string,
487-
gNeedsSubmit: PropTypes.bool,
488396
gAssignmentType: PropTypes.number.isRequired,
489397

490398
gShowIntersection: PropTypes.bool.isRequired,
@@ -603,7 +511,5 @@ GraphViewer.propTypes = {
603511
gExpression2: PropTypes.string,
604512
gExpression3: PropTypes.string,
605513

606-
assessment: PropTypes.array,
607-
submission: PropTypes.object,
608514
updateGraph: PropTypes.func.isRequired
609515
};

media/js/src/buttons/SubmitButton.jsx

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)