Skip to content

Commit

Permalink
Add details to pub list, and fix perms
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Powers committed Dec 19, 2024
1 parent 69de8ee commit 2c7aca9
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 16 deletions.
4 changes: 4 additions & 0 deletions projects/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PublicationAdmin(ProjectFields, admin.ModelAdmin):
]

fields = (
"submitted_date",
"project",
"publication_type",
"forum",
Expand All @@ -47,6 +48,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 = (
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
),
]
6 changes: 6 additions & 0 deletions projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ 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}"
Expand Down
22 changes: 20 additions & 2 deletions projects/pub_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
from django.db import transaction
from django.db.models import Max
from django.http import Http404
from django.template.loader import render_to_string
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 django.views.decorators.cache import never_cache

from djangoRT import rtModels, rtUtil
from projects.models import Publication, PublicationSource
Expand Down Expand Up @@ -69,16 +72,25 @@ 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(
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:
Expand All @@ -102,8 +114,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)


Expand Down
88 changes: 74 additions & 14 deletions projects/templates/projects/view_publications.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,80 @@
{% block title %}Publications{% endblock %}
{% block content %}

<h2>Publications</h2>
{% for p in publications %}
<style>
.user_pub_table td:first-child div {
display: flex;
}

.user_pub_table td div {
margin-right: 2rem;
}

<p>
<form role="form" method="post" style="display:inline">
{% csrf_token %}
<input type="hidden" name="pub_ref" value="{{ p.id }}">
<button type="submit" class="btn btn-xs btn-link" name="del_pub"><i class="fa fa-minus-square text-danger"></i><span class="sr-only">Remove publication</span></button>
</form>
<small>[{% if p.nickname %} {{p.nickname}} {% else %} {{ p.chargeCode }} {% endif %}]</small>
<small>[{{p.status}}]</small>
<a href="{{ p.link }}">{{ p.title }}</a>, {{ p.author }} In <i>{{ p.forum }}</i>. {{ p.month }} {{ p.year }}
</p>
.user_pub_table ul {
padding: 0;
}
</style>

{% endfor %}
<h2>Publications</h2>
<table class="user_pub_table">
<thead>
<tr>
<td>
Project
</td>
<td>
Submitted by
</td>
<td>
Status
</td>
<td>
Publication
</td>
</tr>
</thead>
{% for p in publications %}
<tr>
<td>
<div>
{% if p.added_by_username == user.username %}
<form role="form" method="post" style="display:inline">
{% csrf_token %}
<input type="hidden" name="pub_ref" value="{{ p.id }}">
<button type="submit" class="btn btn-xs btn-link" name="del_pub"><i
class="fa fa-minus-square text-danger"></i><span class="sr-only">Remove publication</span></button>
</form>
{% endif %}
{% if p.nickname %} {{p.nickname}} {% else %} {{ p.chargeCode }} {% endif %}
</div>
</td>
<td>
<div>
{{p.added_by_username}}{% if p.submitted_date %} on {{p.submitted_date}}{% endif %}
</div>
</td>
<td>
<div>{{p.status}}</div>
{% if p.reviewed_by %}
<details>
<summary>
Details
</summary>
<ul>
<li>Reviewer: {{ p.reviewed_by }}</li>
<li>Reviewed on: {{ p.reviewed_date }}</li>
<li>Comment: {{ p.reviewed_comment }}</li>
</ul>
</details>
{% endif %}
</td>
<td>
<div>
<a href="{{ p.link }}">{{ p.title }}</a>, {{ p.author }} In <i>{{ p.forum }}</i>. {{ p.month }} {{ p.year }}
</div>
</td>
</tr>
{% endfor %}
</table>

{% endblock %}
{% endblock %}

0 comments on commit 2c7aca9

Please sign in to comment.