Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
grady
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Maximilian Michal
grady
Commits
e2110167
Commit
e2110167
authored
7 years ago
by
Jan Maximilian Michal
Browse files
Options
Downloads
Patches
Plain Diff
Added overall_score method to student and provided first serializers
parent
2e8308e3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!3
Resolve "New input format"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
core/models.py
+30
-9
30 additions, 9 deletions
core/models.py
core/serializers.py
+49
-0
49 additions, 0 deletions
core/serializers.py
core/views/export_csv.py
+3
-7
3 additions, 7 deletions
core/views/export_csv.py
with
82 additions
and
16 deletions
core/models.py
+
30
−
9
View file @
e2110167
...
...
@@ -43,6 +43,7 @@
from
random
import
sample
,
randrange
from
string
import
ascii_lowercase
from
collections
import
OrderedDict
from
django.contrib.auth.models
import
User
from
django.db
import
models
...
...
@@ -50,6 +51,7 @@ from django.db.models import Q
SLUG_LENGTH
=
16
def
random_slug
():
return
''
.
join
(
sample
(
ascii_lowercase
,
SLUG_LENGTH
))
...
...
@@ -67,13 +69,13 @@ class SubmissionType(models.Model):
possible_solution
=
models
.
TextField
()
correction_guideline
=
models
.
TextField
()
def
__str__
(
self
):
return
self
.
name
class
Meta
:
verbose_name
=
"
SubmissionType
"
verbose_name_plural
=
"
SubmissionType Set
"
def
__str__
(
self
):
return
self
.
name
class
Student
(
models
.
Model
):
# Fields
...
...
@@ -86,17 +88,31 @@ class Student(models.Model):
limit_choices_to
=
{
'
groups__name
'
:
'
Students
'
},
)
def
score_per_submission
(
self
):
if
self
.
submissions
.
all
():
return
OrderedDict
({
s
.
type
:
s
.
feedback
.
score
if
hasattr
(
s
,
'
feedback
'
)
else
0
for
s
in
self
.
submissions
.
all
()
})
else
:
return
OrderedDict
({
t
.
name
:
0
for
t
in
SubmissionType
.
objects
.
all
()
})
def
overall_score
(
self
):
return
sum
(
self
.
score_per_submission
().
values
())
def
disable
(
self
):
self
.
has_logged_in
=
True
self
.
save
()
def
__str__
(
self
):
return
self
.
user
.
username
class
Meta
:
verbose_name
=
"
Student
"
verbose_name_plural
=
"
Student Set
"
def
__str__
(
self
):
return
self
.
user
.
username
class
Submission
(
models
.
Model
):
...
...
@@ -111,7 +127,11 @@ class Submission(models.Model):
)
text
=
models
.
TextField
(
blank
=
True
)
pre_corrections
=
models
.
TextField
(
blank
=
True
)
student
=
models
.
ForeignKey
(
Student
,
on_delete
=
models
.
CASCADE
)
student
=
models
.
ForeignKey
(
Student
,
on_delete
=
models
.
CASCADE
,
related_name
=
'
submissions
'
)
class
Meta
:
verbose_name
=
"
Submission
"
...
...
@@ -145,7 +165,7 @@ class Submission(models.Model):
candidates
=
cls
.
objects
.
filter
(
(
Q
(
feedback__isnull
=
True
)
Q
(
feedback__isnull
=
True
)
|
Q
(
feedback__origin
=
Feedback
.
DID_NOT_COMPILE
)
|
Q
(
feedback__origin
=
Feedback
.
COULD_NOT_LINK
)
)
...
...
@@ -161,7 +181,8 @@ class Submission(models.Model):
return
False
submission
=
candidates
[
0
]
feedback
=
submission
.
feedback
if
hasattr
(
submission
,
'
feedback
'
)
else
Feedback
()
feedback
=
submission
.
feedback
if
hasattr
(
submission
,
'
feedback
'
)
else
Feedback
()
feedback
.
origin
=
Feedback
.
MANUAL
feedback
.
status
=
Feedback
.
EDITABLE
feedback
.
of_tutor
=
tutor
...
...
This diff is collapsed.
Click to expand it.
core/serializers.py
0 → 100644
+
49
−
0
View file @
e2110167
from
rest_framework
import
serializers
from
core.models
import
SubmissionType
,
Student
from
django.contrib.auth.models
import
User
class
SubmissionTypeSerializer
(
serializers
.
ModelSerializer
):
def
create
(
self
,
validated_data
):
return
SubmissionType
(
**
validated_data
)
class
Meta
:
model
=
SubmissionType
exclude
=
(
'
slug
'
,
'
correction_guideline
'
,)
class
CreateStudentSerializer
(
serializers
.
ModelSerializer
):
username
=
serializers
.
CharField
(
source
=
'
user.username
'
)
email
=
serializers
.
CharField
(
source
=
'
user.email
'
)
password
=
serializers
.
CharField
(
source
=
'
user.password
'
)
class
Meta
:
model
=
Student
fields
=
(
'
username
'
,
'
name
'
,
'
email
'
,
'
matrikel_no
'
,
'
password
'
)
extra_kwargs
=
{
'
password
'
:
{
'
write_only
'
:
True
}}
def
to_representation
(
self
,
obj
):
return
{
'
username
'
:
obj
.
user
.
username
,
'
name
'
:
obj
.
name
,
'
matrikel_no
'
:
obj
.
matrikel_no
,
}
def
create
(
self
,
validated_data
):
user
=
User
(
email
=
validated_data
[
'
email
'
],
username
=
validated_data
[
'
username
'
]
)
user
.
set_password
(
validated_data
[
'
password
'
])
student
=
Student
(
name
=
validated_data
[
'
name
'
],
matrikel_no
=
validated_data
[
'
matrikel_no
'
],
user
=
user
,
)
return
student
This diff is collapsed.
Click to expand it.
core/views/export_csv.py
+
3
−
7
View file @
e2110167
import
csv
from
django.http
import
HttpResponse
from
core.models
import
Student
,
SubmissionType
,
Submission
from
core.models
import
Student
,
SubmissionType
from
core.custom_annotations
import
group_required
...
...
@@ -16,16 +16,12 @@ def export_csv(request):
[
s
.
name
for
s
in
SubmissionType
.
objects
.
all
().
order_by
(
'
name
'
)])
for
student
in
Student
.
objects
.
all
():
submissions
=
Submission
.
objects
.
filter
(
student
=
student
)
score_list
=
[
s
.
feedback
.
score
if
hasattr
(
s
,
'
feedback
'
)
else
0
for
s
in
submissions
.
order_by
(
'
type__name
'
)]
if
not
score_list
:
score_list
=
[
0
]
*
SubmissionType
.
objects
.
count
()
writer
.
writerow
([
student
.
matrikel_no
,
student
.
user
.
username
,
student
.
name
,
s
um
(
score_list
),
*
s
core_list
s
tudent
.
overall_score
(
),
*
s
tudent
.
score_per_submission
().
values
()
])
return
response
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment