Skip to content
Snippets Groups Projects
Commit 4a1bf52e authored by Jan Maximilian Michal's avatar Jan Maximilian Michal
Browse files

Provided basic views for submissions and feedback

parent 53e02009
No related branches found
No related tags found
No related merge requests found
Showing
with 425 additions and 11 deletions
......@@ -17,4 +17,4 @@ tests/.coverage
build/
tests/report/
db.sqlite3
env-grady/
\ No newline at end of file
env-grady/
default_app_config = 'core.apps.CoreConfig'
......@@ -3,3 +3,4 @@ from django.apps import AppConfig
class CoreConfig(AppConfig):
name = 'core'
verbose_name = 'where everything comes together'
[
{
"fields": {
"correct_solution": "Das geht dich gar nichts an.",
"correction_guideline": "Mach das mal so und so.",
"full_score": 10,
"name": "Irgendwas Sortieren"
},
"model": "core.submissiontype",
"pk": "123"
},
{
"fields": {
"matrikel_no": 21999999,
"user": 17
},
"model": "core.student",
"pk": 1
},
{
"fields": {
"final_feedback": null,
"pre_corrections": "Was das System halt so kann.",
"student": 1,
"submission_text": "class Uhrzeit implements Comparable<Uhrzeit> {\r\n private int stunde; // Stundenangabe\r\n private int minute; // Minutenangabe\r\n public Uhrzeit(int stunde, int minute) { // nur sinnvolle Zeitangaben ..\r\n if ( 0 <= stunde && stunde <= 23 && // .. behandeln\r\n 0 <= minute && minute <= 59) {\r\n this.stunde = stunde; // Stundenangabe zuweisen\r\n this.minute = minute; // Minutenangabe zuweisen\r\n } else throw new RuntimeException(\"Ungültige Zeitangabe!\");\r\n }\r\n\r\n public String toString() { // String-Darstellung in der Form:\r\n return stunde + \" Uhr und \" + minute + \" Minute(n)\"; // <Stundenangabe> Uhr und <Minutenangabe> Minuten\r\n }\r\n}",
"submission_type": "123"
},
"model": "core.submission",
"pk": 1
},
{
"fields": {
"of_reviewer": [
16
],
"of_submission": 1,
"of_tutor": 15,
"score": 10,
"text": "You did a good job"
},
"model": "core.feedback",
"pk": 1
}
]
from django import forms
from core.models import Feedback, Submission
class CorrectionForm(forms.Form):
comments = forms.TextField()
score = forms.PositiveIntegerField(initial=0)
# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-03-03 20:53
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('core', '0002_auto_20170303_1837'),
]
operations = [
migrations.AlterModelOptions(
name='feedback',
options={'verbose_name': 'Feedback', 'verbose_name_plural': 'Feedback Set'},
),
migrations.AlterModelOptions(
name='student',
options={'verbose_name': 'Student', 'verbose_name_plural': 'Students'},
),
migrations.AddField(
model_name='submission',
name='submission_text',
field=models.TextField(blank=True),
),
migrations.RemoveField(
model_name='feedback',
name='of_reviewer',
),
migrations.AddField(
model_name='feedback',
name='of_reviewer',
field=models.ManyToManyField(related_name='reviewd_submissions', to=settings.AUTH_USER_MODEL),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-03-04 09:29
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0003_auto_20170303_2053'),
]
operations = [
migrations.AddField(
model_name='submission',
name='final_feedback',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='core.Feedback'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-03-04 12:00
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0004_submission_final_feedback'),
]
operations = [
migrations.AlterField(
model_name='submission',
name='pre_corrections',
field=models.TextField(blank=True),
),
migrations.AlterField(
model_name='submission',
name='submission_text',
field=models.TextField(),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-03-04 15:23
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0005_auto_20170304_1200'),
]
operations = [
migrations.AlterField(
model_name='feedback',
name='of_reviewer',
field=models.ManyToManyField(blank=True, related_name='reviewd_submissions', to=settings.AUTH_USER_MODEL),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-03-04 16:05
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0006_auto_20170304_1523'),
]
operations = [
migrations.AddField(
model_name='feedback',
name='slug',
field=models.SlugField(default=0),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-03-04 16:12
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0007_feedback_slug'),
]
operations = [
migrations.AlterField(
model_name='feedback',
name='slug',
field=models.SlugField(blank=True),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-03-04 16:14
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0008_auto_20170304_1612'),
]
operations = [
migrations.AlterField(
model_name='feedback',
name='slug',
field=models.SlugField(editable=False),
),
]
from random import sample
from string import ascii_lowercase
from django.db import models
from django.contrib.auth.models import User
from django.template.defaultfilters import slugify
# Create your models here.
class SubmissionType(models.Model):
# Fields
......@@ -22,19 +24,28 @@ class SubmissionType(models.Model):
class Student(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
# Fields
user = models.OneToOneField(
User, on_delete=models.CASCADE, limit_choices_to={'groups__name': 'Students'})
matrikel_no = models.PositiveIntegerField(unique=True, default=0)
class Meta:
verbose_name = "Student"
verbose_name_plural = "Students"
def __str__(self):
return "{} ({})".format(self.user.username, self.matrikel_no)
class Submission(models.Model):
# Fields
pre_corrections = models.TextField()
submission_type = models.ForeignKey(SubmissionType, related_name='submissions')
submission_type = models.ForeignKey(
SubmissionType, related_name='submissions')
submission_text = models.TextField()
pre_corrections = models.TextField(blank=True)
final_feedback = models.OneToOneField('Feedback', null=True, blank=True)
student = models.OneToOneField(Student)
class Meta:
......@@ -42,24 +53,41 @@ class Submission(models.Model):
verbose_name_plural = "Submissions"
def __str__(self):
pass
return "Submission of type '{}' from Student '{}'".format(
self.submission_type,
self.student
)
class Feedback(models.Model):
# fields
# Fields
score = models.PositiveIntegerField(default=0)
text = models.TextField()
of_submission = models.ForeignKey(Submission)
of_tutor = models.ForeignKey(User, related_name='corrected_submissions')
of_reviewer = models.ForeignKey(User, related_name='reviewd_submissions')
of_tutor = models.ForeignKey(
User,
related_name='corrected_submissions',
limit_choices_to={'groups__name': 'Tutors'}
)
of_reviewer = models.ManyToManyField(
User,
related_name='reviewd_submissions',
limit_choices_to={'groups__name': 'Reviewers'},
blank=True
)
slug = models.SlugField(editable=False)
class Meta:
verbose_name = "Feedback"
verbose_name_plural = "Feedback Set"
def save(self, *args, **kwargs):
self.slug = ''.join(sample(ascii_lowercase, 16))
super(Feedback, self).save(*args, **kwargs)
def __str__(self):
pass
return 'Feedback for {}'.format(self.of_submission)
def is_full_score(self):
return of_submission.full_score == score
<html>
<head>
<meta charset="UTF-8">
<title>Feedback View</title>
</head>
<body>
<h1>This is the view for {{ feedback }}</h1>
<div>
<h2>The student {{ feedback.of_submission.student }} has submitted:</h2>
<pre>{{ feedback.of_submission.submission_text }}</pre>
<h2> {{ feedback.of_tutor }} has created this feedback:</h2>
<pre>{{ feedback.text }}</pre>
<p>The final score based on this feedback is <code>{{ feedback.score }}</code>. </p>
</div>
{% if not feedback.of_reviwer %}
<h2>Nobody reviewed this feedback so far</h2>
{% endif %}
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Rango</title>
</head>
<body>
<h1>All the types</h1>
{% for subm in submission_t %}
<h2> {{ subm }}</h2>
<ul>
{% for s in submissions %}
<li> {{ s }} </li>
{% endfor %}
</ul>
{% endfor %}
<strong>{{ boldmessage }}</strong><br>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title>Grady -- Login</title>
</head>
<body>
<h1>Welcome to Correction Hell</h1>
<form id="login_form" method="post" action="/login/">
{% csrf_token %}
<p>Username: <input type="text" name="username" value="" size="30"></p>
<p>Passwort: <input type="password" name="password" value="" size="30"></p>
<p><input type="submit" value="submit" /></p>
</form>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title>Tutor Startpage</title>
</head>
<body>
<h1>Hello {{tutor_name}}! </h1>
{% if feedback_list|length == 0 %}
<h2>You havn't provided any feedback yet. Sad. Get to work!</h2>
{% else %}
{% if feedback_list|length == 1 %}
<h2>So far you have provieded one constribution </h2>
{% else %}
<h2>So far you have provided {{feedback_list|length}} constributions.</h2>
{% endif %}
<ul>
{% for feedback in feedback_list %}
<li> <a href="/feedback/{{ feedback.slug }}/"> {{ feedback }}</a> </li>
{% endfor %}
</ul>
{% endif %}
<p><a href="/logout/">Logout</a></p>
</body>
</html>
from django.conf.urls import url
from core import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^login/$', views.user_login, name='login'),
url(r'^logout/$', views.user_logout, name='logout'),
url(r'^tutor/$', views.tutor_startpage, name='tutor'),
url(r'^feedback/(?P<feedback_slug>\w+)/$', views.feedback, name='feedback'),
]
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import User, Group
from django.contrib.auth.decorators import user_passes_test, login_required
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render
from core.models import Submission, SubmissionType, Feedback
# Create your views here.
def index(request):
context = {
'boldmessage': 'Delbert Grady says hey there world!',
'submission_t': SubmissionType.objects.all(),
'submissions': Submission.objects.all(),
}
return render(request, 'core/index.html', context)
def delegate_user(user) -> str:
if user.groups.filter(name='Tutors').exists():
return '/tutor/'
if user.groups.filter(name='Reviewers').exists():
return '/reviewers/'
if user.groups.filter(name='Students').exists():
return '/students/'
def user_login(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
return HttpResponseRedirect(delegate_user(user))
else:
return HttpResponse("Your Grady account is disabled.")
else:
# Bad login details were provided. So we can't log the user in.
print("Invalid login details: {0}, {1}".format(username, password))
return HttpResponse("Invalid login details supplied.")
else:
return render(request, 'core/login.html', {})
@login_required
def user_logout(request):
logout(request)
return HttpResponseRedirect('/login/')
def is_tutor(user):
group = Group.objects.get(name='Tutors')
return group in user.groups.all()
@user_passes_test(is_tutor, login_url='/login/')
def tutor_startpage(request):
context = {
'tutor_name': request.user.username,
'feedback_list': Feedback.objects.filter(of_tutor=request.user)
}
return render(request, 'core/tutor_startpage.html', context)
@user_passes_test(is_tutor, login_url='/login/')
def feedback(request, feedback_slug):
context = {'feedback': Feedback.objects.get(slug=feedback_slug)}
# Go render the response and return it to the client.
return render(request, 'core/feedback.html', context)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment