From 9242ae6693b193bed2e675891e202b8e73ca49ad Mon Sep 17 00:00:00 2001 From: Baruta Daniel Mihai Date: Sat, 6 Mar 2021 18:12:20 +0200 Subject: [PATCH 1/5] Dev (#299) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Removed f-string formatting without variables and in logging functions (#266) * Removed f-string formatting in logger functions * Removed f-string formatting for strings without variables * fix coding style * Recomputes total score when the soft deadline changes (#268) * Recomputes total score when the soft deadline changes * Update testsuite/test_ta_workflow.py Co-authored-by: Baruta Daniel Mihai Co-authored-by: Baruta Daniel Mihai * fix coding style * New state ERROR for submission update method (#270) * Add CONTRIB.md (#267) * Add CONTRIB.md * bold * add try / except to update method and create STATE_ERROR * add debug message * unit test WIP * update try catch implementation * update update_state method if statement * update update_state method tests * update submission state Co-authored-by: Baruta Daniel Mihai * coding style * Replace asserts (#269) * Add CONTRIB.md (#267) * Add CONTRIB.md * bold * Replace asserts * Tweak done call to return an HTTP 400 response instead * Run flake8 and black Co-authored-by: Baruta Daniel Mihai * move options to pyproject.toml * use postgres in dev and tests * black * flake8 * black * improve postgres.sh * Add sleep * improve postgres.sh * Fix test ta workflow * Add vault * Enable tests * Disable tests * use absoulte path * Root media * waitress * Add fix Signed-off-by: George Muraru * GitHub actions (#277) * Github Actions * Format the project * Fix state * Change order for submission state change * Remove save to storage process * Save storage * Profiler * Remove assignment * Start with debug * Remove profiler * Create migration for Error state * Update README (#281) * Check only Running subs (#280) * Check only running submissions * Fix flake/black * Change default state * Change default state * make migration Co-authored-by: Baruta Daniel Mihail * Profiler (#284) * Use silk * Fix assignment page * Profiler on env & add shellcheck * Pytest in actions * Pagination for assignment * Pagination for user page * enable tests * update tests * Use silk * Fix assignment page * Profiler on env & add shellcheck * Pytest in actions * Pagination for assignment * Pagination for user page * enable tests * update tests * remove stupid * Add badge * use codecov script * Add unify config (#255) * Add unify config * Fix flake * Fix fixtures * Fix name * Fix deadlines * Holiday must be a list Holiday must be a list * Add unify config * Fix flake * Fix fixtures * Fix name * Fix deadlines * Holiday must be a list Holiday must be a list * Add default * Holiday fix * Tests fix Co-authored-by: Baruta Daniel Mihail * st * Disable profiling while testing in the CI * Improve queries * Improve queries * Add log * Fix name * Fix name * Add GZIP Middleware * Remove bad select_related * Dockerhub on github actions * Add more logs (#288) * Add more logs * Add exception * Add parameter when sending model * Fix param * Keep sub in memory (#289) * Add in memory waitqueue * Create set * Add hash for sub * Fix black * Add try catch * Add save fields * Remove history * Fix Moss (#291) * Add moss buffer * github actions update Co-authored-by: Baruta Daniel Mihail * Add hide button for assignments (#295) Everything is fine! :dancers: * Jw refactor homepage (#296) * Dropdown * Dev (#285) * Removed f-string formatting without variables and in logging functions (#266) * Removed f-string formatting in logger functions * Removed f-string formatting for strings without variables * fix coding style * Recomputes total score when the soft deadline changes (#268) * Recomputes total score when the soft deadline changes * Update testsuite/test_ta_workflow.py Co-authored-by: Baruta Daniel Mihai Co-authored-by: Baruta Daniel Mihai * fix coding style * New state ERROR for submission update method (#270) * Add CONTRIB.md (#267) * Add CONTRIB.md * bold * add try / except to update method and create STATE_ERROR * add debug message * unit test WIP * update try catch implementation * update update_state method if statement * update update_state method tests * update submission state Co-authored-by: Baruta Daniel Mihai * coding style * Replace asserts (#269) * Add CONTRIB.md (#267) * Add CONTRIB.md * bold * Replace asserts * Tweak done call to return an HTTP 400 response instead * Run flake8 and black Co-authored-by: Baruta Daniel Mihai * move options to pyproject.toml * use postgres in dev and tests * black * flake8 * black * improve postgres.sh * Add sleep * improve postgres.sh * Fix test ta workflow * Add vault * Enable tests * Disable tests * use absoulte path * Root media * waitress * Add fix Signed-off-by: George Muraru * GitHub actions (#277) * Github Actions * Format the project * Fix state * Change order for submission state change * Remove save to storage process * Save storage * Profiler * Remove assignment * Start with debug * Remove profiler * Create migration for Error state * Update README (#281) * Check only Running subs (#280) * Check only running submissions * Fix flake/black * Change default state * Change default state * make migration Co-authored-by: Baruta Daniel Mihail * Profiler (#284) * Use silk * Fix assignment page * Profiler on env & add shellcheck * Pytest in actions * Pagination for assignment * Pagination for user page * enable tests * update tests * Use silk * Fix assignment page * Profiler on env & add shellcheck * Pytest in actions * Pagination for assignment * Pagination for user page * enable tests * update tests * remove stupid * Add badge * use codecov script * Add unify config (#255) * Add unify config * Fix flake * Fix fixtures * Fix name * Fix deadlines * Holiday must be a list Holiday must be a list * Add unify config * Fix flake * Fix fixtures * Fix name * Fix deadlines * Holiday must be a list Holiday must be a list * Add default * Holiday fix * Tests fix Co-authored-by: Baruta Daniel Mihail * st * Disable profiling while testing in the CI * Improve queries * Improve queries * Add log * Fix name * Fix name * Add GZIP Middleware * Remove bad select_related * Dockerhub on github actions * Add more logs (#288) * Add more logs * Add exception * Add parameter when sending model * Fix param * Keep sub in memory (#289) * Add in memory waitqueue * Create set * Add hash for sub * Fix black * Add try catch * Add save fields * Remove history Co-authored-by: ptrstr <57736901+ptrstr@users.noreply.github.com> Co-authored-by: José Clovis Ramírez de la Rosa Co-authored-by: Guillaume Co-authored-by: George Muraru Co-authored-by: Sebika <44608549+sebika@users.noreply.github.com> * Final merge * Fix test * Remove redefinition Co-authored-by: ptrstr <57736901+ptrstr@users.noreply.github.com> Co-authored-by: José Clovis Ramírez de la Rosa Co-authored-by: Guillaume Co-authored-by: George Muraru Co-authored-by: Sebika <44608549+sebika@users.noreply.github.com> * Remove duplicate clean * Add ignore for moss (#300) Co-authored-by: ptrstr <57736901+ptrstr@users.noreply.github.com> Co-authored-by: José Clovis Ramírez de la Rosa Co-authored-by: Guillaume Co-authored-by: George Muraru Co-authored-by: Sebika <44608549+sebika@users.noreply.github.com> --- .github/workflows/ci.yml | 3 ++- codecov.yml | 2 ++ .../migrations/0024_auto_20210124_1829.py | 23 ++++++++++++++++ interface/models.py | 1 + interface/moss.py | 6 +++-- .../templates/interface/generics/base.html | 5 ++-- interface/templates/interface/homepage.html | 26 +++++++++++++------ interface/views.py | 9 +++++-- testsuite/test_views.py | 2 +- 9 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 codecov.yml create mode 100644 interface/migrations/0024_auto_20210124_1829.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 08ceb909..715c860b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,6 +38,8 @@ jobs: Publish: needs: Pytest runs-on: ubuntu-latest + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true steps: - name: Checkout Code uses: actions/checkout@v2 @@ -61,4 +63,3 @@ jobs: with: push: true tags: ${{ github.repository }}:${{ env.BRANCH_NAME }} - diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000..f0e04ee1 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,2 @@ +ignore: + - "interface/moss.py" # For the moment we can not automatically test the Moss Checker diff --git a/interface/migrations/0024_auto_20210124_1829.py b/interface/migrations/0024_auto_20210124_1829.py new file mode 100644 index 00000000..80becefd --- /dev/null +++ b/interface/migrations/0024_auto_20210124_1829.py @@ -0,0 +1,23 @@ +# Generated by Django 3.1.2 on 2021-01-24 16:29 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('interface', '0023_auto_20201024_1949'), + ] + + operations = [ + migrations.AddField( + model_name='assignment', + name='hide', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='historicalassignment', + name='hide', + field=models.BooleanField(default=False), + ), + ] diff --git a/interface/models.py b/interface/models.py index 71d46fcf..e41c454e 100644 --- a/interface/models.py +++ b/interface/models.py @@ -85,6 +85,7 @@ def get_default_vm_info(): history = HistoricalRecords() hidden_score = models.BooleanField(default=True) + hide = models.BooleanField(null=False, default=False) def clean(self): penalty_weights = self.penalty_info["penalty_weights"] diff --git a/interface/moss.py b/interface/moss.py index 63b9b91b..5e0163aa 100644 --- a/interface/moss.py +++ b/interface/moss.py @@ -1,5 +1,6 @@ import glob import logging +from io import BytesIO from pathlib import Path from zipfile import ZipFile from tempfile import TemporaryDirectory @@ -25,14 +26,15 @@ def moss_check(submissions, assignment, request): tmp = Path(_tmp) for submission in submissions: + buff = BytesIO() try: - submission.download(tmp / f"{submission.pk}.zip") + submission.download(buff) except MissingFile: msg = f"File missing for {submission!r}" messages.error(request, msg) log.warning(msg) - submission_archive = ZipFile(tmp / f"{submission.pk}.zip") + submission_archive = ZipFile(buff) submission_archive.extractall( tmp / f"{submission.user.username}", ) diff --git a/interface/templates/interface/generics/base.html b/interface/templates/interface/generics/base.html index a12afb83..aa3e101e 100644 --- a/interface/templates/interface/generics/base.html +++ b/interface/templates/interface/generics/base.html @@ -10,8 +10,9 @@ - - + + + VMCK diff --git a/interface/templates/interface/homepage.html b/interface/templates/interface/homepage.html index 63a36fc3..3041e65a 100644 --- a/interface/templates/interface/homepage.html +++ b/interface/templates/interface/homepage.html @@ -2,19 +2,29 @@ {% block body_content %}
- {% for course in courses %} -

{{ course.name }}

-
    - {% for assignment in course.assignment_set.all %} +
    + + + +
    + +
      + {% for assignment in assignments %}
    • {{ assignment.name }}: {% if assignment.is_active %} - Upload, + Upload, {% endif %} - Results + Results
    • {% endfor %} -
    - {% endfor %} +
+
{% endblock %} diff --git a/interface/views.py b/interface/views.py index ee6877d4..9aeb4abe 100644 --- a/interface/views.py +++ b/interface/views.py @@ -22,7 +22,7 @@ from interface import models from interface import utils from interface.forms import UploadFileForm, LoginForm -from interface.models import Submission, Course, User +from interface.models import Submission, Course, User, Assignment from interface.backend.submission.submission import ( handle_submission, TooManySubmissionsError, @@ -130,10 +130,15 @@ def download(request, pk): @login_required def homepage(request): + courseID = int(request.GET.get("course", "-1")) + assignments = Assignment.objects.filter( + course__id=courseID, hide=False + ).prefetch_related("course") + return render( request, "interface/homepage.html", - {"courses": Course.objects.all().prefetch_related("assignment_set")}, + {"courses": Course.objects.all(), "assignments": assignments}, ) diff --git a/testsuite/test_views.py b/testsuite/test_views.py index c9a2f5ff..84b0c080 100644 --- a/testsuite/test_views.py +++ b/testsuite/test_views.py @@ -30,7 +30,7 @@ def test_homepage(client, STC, base_db_setup): (_, _, user, course, assignment) = base_db_setup client.login(username=user.username, password="pw") - response = client.get("/homepage/") + response = client.get(f"/homepage/?course={course.id}") STC.assertTemplateUsed(response, "interface/homepage.html") assert response.context["courses"] From 2ff0b4a42312e0de3cd2adcd25b80c3ae2746a7e Mon Sep 17 00:00:00 2001 From: Lucian-MihaiStan Date: Wed, 10 Mar 2021 00:11:23 +0200 Subject: [PATCH 2/5] manage --- interface/models.py | 1 + interface/views.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/interface/models.py b/interface/models.py index e41c454e..10773136 100644 --- a/interface/models.py +++ b/interface/models.py @@ -86,6 +86,7 @@ def get_default_vm_info(): history = HistoricalRecords() hidden_score = models.BooleanField(default=True) hide = models.BooleanField(null=False, default=False) + hide_student = models.BooleanField(null=False, default=False) def clean(self): penalty_weights = self.penalty_info["penalty_weights"] diff --git a/interface/views.py b/interface/views.py index 87d962d4..b4bc4823 100644 --- a/interface/views.py +++ b/interface/views.py @@ -130,6 +130,7 @@ def download(request, pk): @login_required def homepage(request): + user_logged = request.user courseID = int(request.GET.get("course", "-1")) assignments = Assignment.objects.filter( course__id=courseID, hide=False @@ -138,7 +139,8 @@ def homepage(request): return render( request, "interface/homepage.html", - {"courses": Course.objects.all(), "assignments": assignments}, + {"courses": Course.objects.all(), "assignments": assignments, + "user_logged": user_logged}, ) From 5cd83b641d35cf2f2ec9115c305689690f619eb4 Mon Sep 17 00:00:00 2001 From: Lucian-MihaiStan Date: Wed, 10 Mar 2021 20:30:19 +0200 Subject: [PATCH 3/5] Add button for allowing students to upload --- interface/models.py | 2 +- interface/templates/interface/homepage.html | 2 +- interface/views.py | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/interface/models.py b/interface/models.py index 10773136..025c33e8 100644 --- a/interface/models.py +++ b/interface/models.py @@ -86,7 +86,7 @@ def get_default_vm_info(): history = HistoricalRecords() hidden_score = models.BooleanField(default=True) hide = models.BooleanField(null=False, default=False) - hide_student = models.BooleanField(null=False, default=False) + assignment_on = models.BooleanField(null=False, default=False) def clean(self): penalty_weights = self.penalty_info["penalty_weights"] diff --git a/interface/templates/interface/homepage.html b/interface/templates/interface/homepage.html index 3041e65a..257da9b0 100644 --- a/interface/templates/interface/homepage.html +++ b/interface/templates/interface/homepage.html @@ -18,7 +18,7 @@ {% for assignment in assignments %}
  • {{ assignment.name }}: - {% if assignment.is_active %} + {% if assignment.is_active and assignment.assignment_on or assignment.is_active and user in assignment.course.teaching_assistants.all %} Upload, {% endif %} Results diff --git a/interface/views.py b/interface/views.py index b4bc4823..98dd3597 100644 --- a/interface/views.py +++ b/interface/views.py @@ -139,8 +139,7 @@ def homepage(request): return render( request, "interface/homepage.html", - {"courses": Course.objects.all(), "assignments": assignments, - "user_logged": user_logged}, + {"courses": Course.objects.all(), "assignments": assignments}, ) From 8ea5f2339d90e67c691eb96067bb4371d3b90d7e Mon Sep 17 00:00:00 2001 From: Lucian-MihaiStan Date: Wed, 10 Mar 2021 20:38:12 +0200 Subject: [PATCH 4/5] button students allow upload --- interface/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/views.py b/interface/views.py index 98dd3597..87d962d4 100644 --- a/interface/views.py +++ b/interface/views.py @@ -130,7 +130,6 @@ def download(request, pk): @login_required def homepage(request): - user_logged = request.user courseID = int(request.GET.get("course", "-1")) assignments = Assignment.objects.filter( course__id=courseID, hide=False From dd90ccca765024a6bd02d850c3e6a850b7f18fcc Mon Sep 17 00:00:00 2001 From: Luci <56245077+Lucian-MihaiStan@users.noreply.github.com> Date: Wed, 10 Mar 2021 21:21:52 +0200 Subject: [PATCH 5/5] button students allow upload button students allow upload --- .../migrations/0025_auto_20210310_2056.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 interface/migrations/0025_auto_20210310_2056.py diff --git a/interface/migrations/0025_auto_20210310_2056.py b/interface/migrations/0025_auto_20210310_2056.py new file mode 100644 index 00000000..2726fd5d --- /dev/null +++ b/interface/migrations/0025_auto_20210310_2056.py @@ -0,0 +1,23 @@ +# Generated by Django 3.1.2 on 2021-03-10 18:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('interface', '0024_auto_20210124_1829'), + ] + + operations = [ + migrations.AddField( + model_name='assignment', + name='assignment_on', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='historicalassignment', + name='assignment_on', + field=models.BooleanField(default=False), + ), + ]