From 866776b90f9cc03280bff57043ae3cb191d9d746 Mon Sep 17 00:00:00 2001 From: Odin Vatne <odinjv@stud.ntnu.no> Date: Wed, 15 Dec 2021 01:17:53 +0100 Subject: [PATCH] Final touches for paper release branch --- pasapp/admin.py | 1 + pasapp/migrations/0006_auto_20211214_1820.py | 27 +++++++ pasapp/migrations/0007_auto_20211215_0114.py | 80 +++++++++++++++++++ pasapp/models.py | 34 +++++++- pasapp/templates/pasapp/base_template.html | 4 +- .../pasapp/professor_applications.html | 2 +- .../pasapp/project_applications.html | 2 +- pasapp/views.py | 8 +- 8 files changed, 146 insertions(+), 12 deletions(-) create mode 100644 pasapp/migrations/0006_auto_20211214_1820.py create mode 100644 pasapp/migrations/0007_auto_20211215_0114.py diff --git a/pasapp/admin.py b/pasapp/admin.py index 459fea2..09feb04 100644 --- a/pasapp/admin.py +++ b/pasapp/admin.py @@ -7,3 +7,4 @@ admin.site.register(Project) admin.site.register(Application) admin.site.register(Tag) admin.site.register(ProjectTag) +admin.site.register(TagCategory) diff --git a/pasapp/migrations/0006_auto_20211214_1820.py b/pasapp/migrations/0006_auto_20211214_1820.py new file mode 100644 index 0000000..471403c --- /dev/null +++ b/pasapp/migrations/0006_auto_20211214_1820.py @@ -0,0 +1,27 @@ +# Generated by Django 3.2.9 on 2021-12-14 17:20 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('pasapp', '0005_application_priority'), + ] + + operations = [ + migrations.CreateModel( + name='TagCategory', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('category', models.CharField(max_length=128)), + ('color', models.CharField(max_length=6)), + ], + ), + migrations.AddField( + model_name='tag', + name='category', + field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='pasapp.tagcategory'), + ), + ] diff --git a/pasapp/migrations/0007_auto_20211215_0114.py b/pasapp/migrations/0007_auto_20211215_0114.py new file mode 100644 index 0000000..5a605e2 --- /dev/null +++ b/pasapp/migrations/0007_auto_20211215_0114.py @@ -0,0 +1,80 @@ +# Generated by Django 3.2.9 on 2021-12-15 00:14 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('pasapp', '0006_auto_20211214_1820'), + ] + + operations = [ + migrations.RenameField( + model_name='application', + old_name='date_sent', + new_name='date_created', + ), + migrations.RemoveField( + model_name='tagcategory', + name='color', + ), + migrations.AddField( + model_name='application', + name='last_updated', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='application', + name='professor_status', + field=models.CharField(default='Pending', max_length=32), + preserve_default=False, + ), + migrations.AddField( + model_name='application', + name='student_status', + field=models.CharField(default='Pending', max_length=32), + preserve_default=False, + ), + migrations.AddField( + model_name='project', + name='date_created', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='project', + name='group_size', + field=models.CharField(default=2, max_length=128), + preserve_default=False, + ), + migrations.AddField( + model_name='project', + name='last_updated', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='tag', + name='class_ids', + field=models.CharField(blank=True, default=None, max_length=256, null=True), + ), + migrations.AlterField( + model_name='tag', + name='category', + field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, to='pasapp.tagcategory'), + ), + migrations.CreateModel( + name='StudentTag', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ('tag', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='pasapp.tag')), + ], + ), + ] diff --git a/pasapp/models.py b/pasapp/models.py index 656b834..6e19a0e 100644 --- a/pasapp/models.py +++ b/pasapp/models.py @@ -1,15 +1,17 @@ -from django.conf import settings from django.db import models from django.contrib.auth.models import User -# Create your models here. - class Project(models.Model): title = models.CharField(max_length=200) professor = models.ForeignKey(User, on_delete=models.CASCADE) description = models.CharField(max_length=2048) + group_size = models.CharField(max_length=128) # TODO: Not implemented status = models.CharField(max_length=128) + date_created = models.DateTimeField( + auto_now_add=True, name='date_created') # TODO: Not implemented + last_updated = models.DateTimeField( + auto_now_add=True, name='last_updated') # TODO: Not implemented # Tags - see ProjectTag below def __str__(self): @@ -20,15 +22,30 @@ class Application(models.Model): project = models.ForeignKey(Project, on_delete=models.CASCADE) student = models.ForeignKey(User, on_delete=models.CASCADE) message = models.CharField(max_length=2000) - date = models.DateTimeField(auto_now_add=True, name='date_sent') + date_created = models.DateTimeField(auto_now_add=True, name='date_created') + last_updated = models.DateTimeField( + auto_now_add=True, name='last_updated') # TODO: Not implemented priority = models.IntegerField(default=None, blank=True, null=True) + professor_status = models.CharField(max_length=32) # TODO: Not implemented + student_status = models.CharField(max_length=32) # TODO: Not implemented def __str__(self): return f'{self.student} on {self.project}' +class TagCategory(models.Model): + category = models.CharField(max_length=128) + + def __str__(self): + return self.category + + class Tag(models.Model): name = models.CharField(max_length=256, unique=True) + category = models.ForeignKey( + TagCategory, on_delete=models.SET_NULL, blank=True, null=True, default=None) + class_ids = models.CharField( + max_length=256, blank=True, null=True, default=None) # TODO: not implemented def __str__(self): return self.name @@ -40,3 +57,12 @@ class ProjectTag(models.Model): def __str__(self): return f'{self.project.title}: {self.tag.name}' + + +class StudentTag(models.Model): + # TODO: not implemented + student = models.ForeignKey(User, on_delete=models.CASCADE) + tag = models.ForeignKey(Tag, on_delete=models.CASCADE) + + def __str__(self): + return f'{self.student.first_name} {self.student.last_name}: {self.tag.name}' diff --git a/pasapp/templates/pasapp/base_template.html b/pasapp/templates/pasapp/base_template.html index 2372c65..c2f6a8e 100644 --- a/pasapp/templates/pasapp/base_template.html +++ b/pasapp/templates/pasapp/base_template.html @@ -34,9 +34,7 @@ </div> {% endif %} </div> - <div class="messagebox {{message_type}}"> - {{message}} - </div> + <div class="messagebox {{message_type}}">{{message}}</div> {% block content %} {% endblock %} </body> </html> diff --git a/pasapp/templates/pasapp/professor_applications.html b/pasapp/templates/pasapp/professor_applications.html index 5abb184..7d39ab1 100644 --- a/pasapp/templates/pasapp/professor_applications.html +++ b/pasapp/templates/pasapp/professor_applications.html @@ -9,7 +9,7 @@ <ul> {% for application in applications %} <li class="dashed-box"> - <b>{{application.student.first_name}} {{application.student.last_name}}</b> on {{application.date_sent}} + <b>{{application.student.first_name}} {{application.student.last_name}}</b> on {{application.date_created}} <br> {% if application.priority %} <em>Priority: </em> {{application.priority}} diff --git a/pasapp/templates/pasapp/project_applications.html b/pasapp/templates/pasapp/project_applications.html index 6b1f791..0806990 100644 --- a/pasapp/templates/pasapp/project_applications.html +++ b/pasapp/templates/pasapp/project_applications.html @@ -7,7 +7,7 @@ <ul> {% for application in applications %} <li> - {{application.student}} on {{application.date_sent}} + {{application.student}} on {{application.date_created}} <br /> {{application.message}} </li> diff --git a/pasapp/views.py b/pasapp/views.py index 41e8ce1..43cbc0a 100644 --- a/pasapp/views.py +++ b/pasapp/views.py @@ -102,7 +102,7 @@ def project_applications(request, project_id): if not request.user.id == project.professor.id: return HttpResponseForbidden() applications = Application.objects.filter( - project=project_id).order_by('-date_sent') + project=project_id).order_by('-date_created') context = {'project': project, 'applications': applications} return render(request, 'pasapp/project_applications.html', contextWithHeader(context, request)) @@ -191,7 +191,7 @@ def student_applications_view(request): Displays all of the student's project applications and allows them to set rankings (see update_priorities below) ''' applications = Application.objects.filter(student=request.user).order_by( - F('priority').asc(nulls_last=True), '-date_sent') + F('priority').asc(nulls_last=True), '-date_created') context = {'applications': applications} return render(request, 'pasapp/student_applications.html', contextWithHeader(context, request)) @@ -202,11 +202,13 @@ def professor_applications_view(request): ''' projects = Project.objects.filter(professor=request.user) sections = {project: Application.objects.filter( - project=project).order_by('-date_sent') for project in projects} + project=project).order_by('-date_created') for project in projects} context = {'sections': sections} return render(request, 'pasapp/professor_applications.html', contextWithHeader(context, request)) +@login_required +@user_passes_test(is_student) def update_priorities(request): ''' Endpoint for updating the priority values of a student's applications. POST only. -- GitLab