diff --git a/.gitignore b/.gitignore index ca929290e4f2d04940740493b3d3147db53836ce..c613aeb37805b215be4197de319e2087d1d4d6b6 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ data/ raw/ testing_facility/ login_data.csv +klausur_* diff --git a/core/templates/core/feedback_form.html b/core/templates/core/feedback_form.html index 440651fe3ebc4de9c98329f704f0bfc4587eede2..ecc2fcfac6ce24fd218df1122101361e750f08f5 100644 --- a/core/templates/core/feedback_form.html +++ b/core/templates/core/feedback_form.html @@ -67,7 +67,7 @@ <div class="form-inline"> {# Score field #} - <div class="input-group col-5 nopadding mr-1"> + <div class="input-group col-5 nopadding mr-1 mb-1"> <span class="input-group-addon">Score:</span> <input class="form-control" @@ -85,7 +85,7 @@ {# status select #} {% with form.fields.status as status %} - <div class="form-group mr-1"> + <div class="form-group mr-1 mb-1"> <select class="custom-select" id="id_status" name="status"> {% for val, name in status.choices %} <option value="{{val}}" {% if val == feedback.status %}selected{% endif %}> {{name}}</option> @@ -94,18 +94,19 @@ </div> {% endwith %} - <button type="submit" form="form1" class="btn btn-secondary mr-1" name="update" value="Submit">Submit</button> + <button type="submit" form="form1" class="btn btn-secondary mr-1 mb-1" name="update" value="Submit">Submit</button> - {% if feedback.status != feedback.ACCEPTED and feedback.origin == feedback.MANUAL%} - <button type="submit" form="form1" class="btn btn-success mr-1" name="update" value="Next">Next</button> + {# Beware! compares status and origin #} + {% if feedback.status == feedback.NEEDS_REVIEW or feedback.status == feedback.EDITABLE %} + <button type="submit" form="form1" class="btn btn-success mr-1 mb-1" name="update" value="Next">Next</button> {% endif %} {% if feedback.origin != feedback.MANUAL %} - <a href="{% url 'FeedbackDelete' feedback.slug %}" class="btn btn-outline-danger" name="delete" value="Delete">Delete auto feedback</a> + <a href="{% url 'FeedbackDelete' feedback.slug %}" class="btn btn-outline-danger mr-1 mb-1" name="delete" value="Delete">Delete auto feedback</a> {% endif %} {% if feedback.status == feedback.ACCEPTED %} - <button class="btn btn-secondary mr-1" value="Submit" disabled>View is read only</button> + <button class="btn btn-secondary mr-1 mb-1" value="Submit" disabled>View is read only</button> {% endif %} </div> </form> diff --git a/core/views/feedback.py b/core/views/feedback.py index b7cff5c7dfd8efc983fc50fc6c07b706d848a62b..60c9ed67a7759051552fa6b1145c1f7b51b872cc 100644 --- a/core/views/feedback.py +++ b/core/views/feedback.py @@ -67,7 +67,16 @@ class FeedbackEdit(UpdateView): form.instance.finalize_feedback(self.request.user) else: form.instance.unfinalize_feedback() - if 'Next' in self.request.POST['update'] and not in_groups(self.request.user, ('Reviewers', )): + + # ugly needs patch + if 'Next' in self.request.POST['update']: + if in_groups(self.request.user, ('Reviewers',)): + needs_review = Feedback.objects.filter(status=Feedback.NEEDS_REVIEW) + needs_review = needs_review[0] if needs_review else None + if needs_review: + return HttpResponseRedirect(reverse('FeedbackEdit', args=(needs_review.slug,))) + else: + return HttpResponseRedirect(self.get_success_url()) return HttpResponseRedirect(reverse('CreateFeedbackForType', args=(form.instance.of_submission.type.slug,))) return HttpResponseRedirect(self.get_success_url()) diff --git a/core/views/user_startpages.py b/core/views/user_startpages.py index 1e8c7c1324513e6ed317ff2f286e439f00892721..51fb03e8fb9f06affcc4a2247a47f19398c7e7ca 100644 --- a/core/views/user_startpages.py +++ b/core/views/user_startpages.py @@ -39,7 +39,7 @@ def get_annotated_feedback_count(): return SubmissionType.objects.annotate( # to display only manual feedback_count=Count('submissions__feedback_list')).annotate( submission_count=Count('submissions') - ).all() + ).all().order_by('name') @group_required('Tutors') def tutor_view(request): diff --git a/populatedb.py b/populatedb.py index fb01ebadf8cec01ffdc349ad8cb1f3c3052aa724..fa66d65f2a8b6ed58ec50fd104141872fba7ae31 100644 --- a/populatedb.py +++ b/populatedb.py @@ -10,8 +10,10 @@ import argparse from collections import namedtuple django.setup() -HTML_DIR = 'data/html' -SOLUTION_DIR = 'data/code/code-lsg' +INFO = 0 + +HTML_DIR = 'html' +SOLUTION_DIR = 'code/code-lsg' wordfile = xp.locate_wordfile() wordlist = xp.generate_wordlist(wordfile=wordfile, min_length=5, max_length=8) @@ -21,6 +23,10 @@ from django.contrib.auth.models import Group, User from core.models import Student, Submission, SubmissionType, Feedback +if INFO: + info = print +else: + info = lambda _: 0 def parseme(): parser = argparse.ArgumentParser() @@ -75,9 +81,9 @@ def add_submission_type(name, task.correction_guideline = correction_guideline task.save() if created: - print(f"- Created Task {task.name}") + info(f"- Created Task {task.name}") else: - print(f"- Got Task {task.name}") + info(f"- Got Task {task.name}") return task @@ -97,12 +103,12 @@ def add_submission(type, text, student, compiler_output): sub.pre_corrections = compiler_output sub.save() add_auto_feedback(sub, compiler_output) - print(f"- Created Submission of Type {sub.type}") + info(f"- Created Submission of Type {sub.type}") return sub def add_auto_feedback(submission, compiler_output): - if not compiler_output: + if submission.text and not compiler_output: return # let the tutor do his job def deduct_feedback_type() -> (str, str): @@ -112,18 +118,22 @@ def add_auto_feedback(submission, compiler_output): return Feedback.DID_NOT_COMPILE, Feedback.NEEDS_REVIEW elif compiler_output.endswith('COULD NOT LINK'): return Feedback.COULD_NOT_LINK, Feedback.NEEDS_REVIEW + else: + return None, None auto_correct, _ = User.objects.get_or_create(username='auto_correct') feedback = Feedback() feedback.text = "--- Was generated automatically ---" feedback.origin, feedback.status = deduct_feedback_type() + if feedback.origin is None and feedback.status is None: + return feedback.of_submission = submission feedback.of_tutor = auto_correct feedback.save() if feedback.origin == Feedback.WAS_EMPTY: submission.final_feedback = feedback submission.save() - print(f"- Created {feedback.origin} Feedback for Submission {submission}") + info(f"- Created {feedback.origin} Feedback for Submission {submission}") return feedback @@ -148,17 +158,17 @@ def add_user(username, group): login_writer.writerow([username, password]) user.set_password(password) group.user_set.add(user) - print(f"- Created user {user} and added him to group {group}") + info(f"- Created user {user} and added him to group {group}") user.save() else: - print(f"- User {user} of group {group} was already created.") + info(f"- User {user} of group {group} was already created.") return user def add_group(group_name): group, _ = Group.objects.get_or_create(name=group_name) - print(f"- Created group {group}") + info(f"- Created group {group}") return group @@ -167,7 +177,7 @@ def create_superuser(): User.objects.create_superuser( username='doncamillo', password=getpass.getpass(), email='a@b.com') except Exception as e: - print("- Superuser was already created.") + info("- Superuser was already created.") return @@ -213,8 +223,8 @@ class PopulateDatabase: self.type_dict = {} for t in types: with \ - open(os.path.join(SOLUTION_DIR, t.id + '-lsg.c' )) as lsg, \ - open(os.path.join(HTML_DIR, t.id + '.html' )) as desc: + open(os.path.join(self.args.DATADIR, SOLUTION_DIR, t.id + '-lsg.c' )) as lsg, \ + open(os.path.join(self.args.DATADIR, HTML_DIR, t.id + '.html' )) as desc: self.type_dict[t.id] = add_submission_type( f"[{t.id}] {t.name}", t.score,