diff --git a/pasapp/admin.py b/pasapp/admin.py index 459fea25396ab21c35680fde31a1f60807969488..09feb045b9f3bc9fd73dac5d3deffbc56017f65f 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 0000000000000000000000000000000000000000..471403c773c83104c4d8e6e84280378808882952 --- /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 0000000000000000000000000000000000000000..5a605e26268d7e7b27394a845bced24864e6b4e0 --- /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 656b83411712572cf21353005898959589632d95..6e19a0e6482b4268a7b2e1b48cd4da4ef0679106 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 2372c658e14173829bf3dae2cd2afe31b4553b7a..c2f6a8e405610a385f584759c37c7b8b76db4a75 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 5abb184b2b06dfddd723538915f5555906097e1b..7d39ab106580ff2a0ff0560d1defe782fb3d615c 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 6b1f791f4c70395ca839b8c77c9251790061427d..0806990df0ea8f0870f75d57cf339515bdfc1040 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 41e8ce1416f26840afbe3bc19102b56eab4e18d9..43cbc0a553efbbf6f8d45a3bcfef2cf87d251e88 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.