diff --git a/projects/admin.py b/projects/admin.py index 2584e88c..0b0c804a 100644 --- a/projects/admin.py +++ b/projects/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin from django.utils.html import format_html +from django.urls import reverse from allocations.models import Allocation from projects.models import ( @@ -34,6 +35,7 @@ class PublicationAdmin(ProjectFields, admin.ModelAdmin): ] fields = ( + "submitted_date", "project", "publication_type", "forum", @@ -47,6 +49,9 @@ class PublicationAdmin(ProjectFields, admin.ModelAdmin): "added_by_username", "status", "checked_for_duplicates", + "reviewed_date", + "reviewed_by", + "reviewed_comment", ) ordering = ["-status", "-id", "-year"] list_display = ( @@ -214,7 +219,24 @@ class ProjectAdmin(admin.ModelAdmin): list_display = ["charge_code", "pi", "nickname", "title"] search_fields = ["charge_code", "pi__username", "pi__email", "nickname", "title"] list_filter = ["tag"] - readonly_fields = ["charge_code", "automatically_tagged", "join_url"] + readonly_fields = [ + "charge_code_link", + "automatically_tagged", + "join_url", + ] + fields = [ + "charge_code_link", + "title", + "nickname", + "description", + "pi", + "join_url", + ] + + def charge_code_link(self, obj): + return format_html( + f'{obj.charge_code}' + ) def join_url(self, obj): return format_html( diff --git a/projects/migrations/0023_publication_reviewed_by_publication_reviewed_comment_and_more.py b/projects/migrations/0023_publication_reviewed_by_publication_reviewed_comment_and_more.py new file mode 100644 index 00000000..f0e8ab20 --- /dev/null +++ b/projects/migrations/0023_publication_reviewed_by_publication_reviewed_comment_and_more.py @@ -0,0 +1,37 @@ +# Generated by Django 4.2.16 on 2024-12-17 15:02 + +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), + ('projects', '0022_remove_joinrequest_join_request_user_link_unique_constraint_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='publication', + name='reviewed_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), + migrations.AddField( + model_name='publication', + name='reviewed_comment', + field=models.TextField(null=True), + ), + migrations.AddField( + model_name='publication', + name='reviewed_date', + field=models.DateField(null=True), + ), + migrations.AddField( + model_name='publication', + name='submitted_date', + field=models.DateField(null=True), + ), + ] diff --git a/projects/models.py b/projects/models.py index 592fb8d8..783488cd 100644 --- a/projects/models.py +++ b/projects/models.py @@ -377,6 +377,14 @@ class Publication(models.Model): doi = models.CharField(max_length=500, null=True, blank=True) status = models.CharField(choices=STATUSES, max_length=30, null=False) checked_for_duplicates = models.BooleanField(default=False, null=False) + submitted_date = models.DateField(default=timezone.now, null=True) + reviewed_date = models.DateField(default=timezone.now, null=True) + reviewed_by = models.ForeignKey( + settings.AUTH_USER_MODEL, + on_delete=models.CASCADE, + null=True, + ) + reviewed_comment = models.TextField(null=True) def __str__(self) -> str: return f"{self.id} {self.title}, {self.author}, In {self.forum}. {self.year}" diff --git a/projects/pub_views.py b/projects/pub_views.py index 6103805c..7be6e781 100644 --- a/projects/pub_views.py +++ b/projects/pub_views.py @@ -2,14 +2,13 @@ import logging import bibtexparser -from django.conf import settings from django.contrib import messages from django.contrib.auth.decorators import login_required from django.db import transaction from django.db.models import Max from django.http import Http404 +from django.template.loader import get_template from django.shortcuts import render -from django.utils.html import strip_tags from django.core.exceptions import PermissionDenied from djangoRT import rtModels, rtUtil @@ -69,7 +68,14 @@ def user_publications(request): try: del_pub_id = request.POST["pub_ref"] logger.debug("deleting publication with id {}".format(del_pub_id)) - Publication.objects.get(pk=del_pub_id).delete_pub() + pub = Publication.objects.get(pk=del_pub_id) + if pub.added_by_username != request.user.username: + messages.error( + request, + "You do not have permission to delete that publication!", + ) + else: + pub.delete_pub() except Exception: logger.exception("Failed removing publication") messages.error( @@ -77,8 +83,10 @@ def user_publications(request): "An unexpected error occurred while attempting " "to remove this publication. Please try again", ) + mapper = ProjectAllocationMapper(request) + project_ids = [p["id"] for p in mapper.get_user_projects(request.user.username)] context["publications"] = [] - pubs = Publication.objects.filter(added_by_username=request.user.username).exclude( + pubs = Publication.objects.filter(project_id__in=project_ids).exclude( status=Publication.STATUS_DELETED ) for pub in pubs: @@ -102,8 +110,14 @@ def user_publications(request): "nickname": project.nickname, "chargeCode": project.charge_code, "status": pub.status, + "added_by_username": pub.added_by_username, + "submitted_date": pub.submitted_date, + "reviewed_by": pub.reviewed_by, + "reviewed_date": pub.reviewed_date, + "reviewed_comment": pub.reviewed_comment, } ) + logger.info(get_template("projects/view_publications.html").template.origin) return render(request, "projects/view_publications.html", context) diff --git a/projects/templates/projects/view_publications.html b/projects/templates/projects/view_publications.html index 201e4c1b..42b8d0b8 100644 --- a/projects/templates/projects/view_publications.html +++ b/projects/templates/projects/view_publications.html @@ -3,20 +3,80 @@ {% block title %}Publications{% endblock %} {% block content %} -

Publications

-{% for p in publications %} + -{% endfor %} +

Publications

+ + + + + + + + + + {% for p in publications %} + + + + + + + {% endfor %} +
+ Project + + Submitted by + + Status + + Publication +
+
+ {% if p.added_by_username == user.username %} +
+ {% csrf_token %} + + +
+ {% endif %} + {% if p.nickname %} {{p.nickname}} {% else %} {{ p.chargeCode }} {% endif %} +
+
+
+ {{p.added_by_username}}{% if p.submitted_date %} on {{p.submitted_date}}{% endif %} +
+
+
{{p.status}}
+ {% if p.reviewed_by %} +
+ + Details + +
    +
  • Reviewer: {{ p.reviewed_by }}
  • +
  • Reviewed on: {{ p.reviewed_date }}
  • +
  • Comment: {{ p.reviewed_comment }}
  • +
+
+ {% endif %} +
+
+ {{ p.title }}, {{ p.author }} In {{ p.forum }}. {{ p.month }} {{ p.year }} +
+
-{% endblock %} +{% endblock %} \ No newline at end of file