Skip to content

Commit

Permalink
added detail page for draft registrations in admin app
Browse files Browse the repository at this point in the history
  • Loading branch information
ihorsokhanexoft committed Feb 6, 2025
1 parent e62c9fc commit 0602579
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 5 deletions.
1 change: 1 addition & 0 deletions admin/draft_registrations/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

urlpatterns = [
re_path(r'^$', views.UserDraftRegistrationSearchView.as_view(), name='search'),
re_path(r'^(?P<draft_registration_id>\w+)/$', views.DraftRegistrationView.as_view(), name='detail'),
]
32 changes: 30 additions & 2 deletions admin/draft_registrations/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
from django.urls import NoReverseMatch, reverse_lazy
from django.urls import NoReverseMatch, reverse
from django.contrib import messages
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.shortcuts import redirect
from django.views.generic import FormView
from django.views.generic import DetailView

from admin.base.forms import GuidForm
from osf.models.registrations import DraftRegistration


class DraftRegistrationMixin(PermissionRequiredMixin):

def get_object(self):
draft_registration = DraftRegistration.load(self.kwargs['draft_registration_id'])
draft_registration.guid = draft_registration._id
return draft_registration

def get_success_url(self):
return reverse('draft_registrations:detail', kwargs={
'draft_registration_id': self.kwargs['draft_registration_id']
})


class UserDraftRegistrationSearchView(PermissionRequiredMixin, FormView):
Expand All @@ -19,8 +34,21 @@ def form_valid(self, form):
guid = form.cleaned_data['guid']
if guid:
try:
return redirect(reverse_lazy('users:draft-registrations', kwargs={'guid': guid}))
return redirect(reverse('users:draft-registrations', kwargs={'guid': guid}))
except NoReverseMatch as e:
messages.error(self.request, str(e))

return super().form_valid(form)


class DraftRegistrationView(DraftRegistrationMixin, DetailView):
""" Allows authorized users to view draft registration
"""
template_name = 'draft_registrations/detail.html'
permission_required = 'osf.view_draftregistration'

def get_context_data(self, **kwargs):
draft_registration = self.get_object()
return super().get_context_data(**{
'draft_registration': draft_registration
}, **kwargs)
11 changes: 10 additions & 1 deletion admin/nodes/templatetags/node_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
AbstractNode,
Contributor,
Preprint,
PreprintContributor
PreprintContributor,
DraftRegistration,
DraftRegistrationContributor
)

from osf.models.spam import SpamStatus
Expand Down Expand Up @@ -57,6 +59,11 @@ def reverse_schema_response(value):
return reverse('schema_responses:detail', kwargs={'schema_response_id': value.id})


@register.filter
def reverse_draft_registration(value):
return reverse('draft_registrations:detail', kwargs={'draft_registration_id': value._id})


@register.filter
def order_by(queryset, args):
args = [x.strip() for x in args.split(',')]
Expand All @@ -69,6 +76,8 @@ def get_permissions(user, resource):
return Contributor.objects.get(user=user, node=resource).permission
elif isinstance(resource, Preprint):
return PreprintContributor.objects.get(user=user, preprint=resource).permission
elif isinstance(resource, DraftRegistration):
return DraftRegistrationContributor.objects.get(user=user, draft_registration=resource).permission


@register.simple_tag
Expand Down
29 changes: 29 additions & 0 deletions admin/templates/draft_registrations/contributors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% load node_extras %}

<tr>
<td>Contributors</td>
<td>
<table class="table table-bordered table-hover">
<thead>
<tr>
<td>Email</td>
<td>Name</td>
<td>Permissions</td>
</tr>
</thead>
<tbody>
{% for user in draft_registration.contributors %}
<tr>
<td>
<a href="{{ user | reverse_user }}">
{{ user }}
</a>
</td>
<td>{{ user.fullname }}</td>
<td>{% get_permissions user draft_registration %}</td>
</tr>
{% endfor %}
</tbody>
</table>
</td>
</tr>
61 changes: 61 additions & 0 deletions admin/templates/draft_registrations/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{% extends 'base.html' %}
{% load static %}
{% load node_extras %}
{% block title %}
<title>{{ draft_registration.type|cut:'osf.'|title }}: {{draft_registration.guid}} </title>
{% endblock title %}
{% block content %}
<div class="container-fluid">
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
<div class="row">
<h2>Draft Registration: <b>{{ draft_registration.title }}</b> <a href="{{ draft_registration.absolute_url }}"> ({{draft_registration.guid}})</a> </h2>
<table class="table table-striped">
<thead>
<tr>
<th>Field</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Guid</td>
<td>{{ draft_registration.guid }}</td>
</tr>
<tr>
<td>Url</td>
<td><a href="{{ draft_registration.absolute_url }}">{{ draft_registration.absolute_url }}</a></td>
</tr>
<tr>
<td>Title</td>
<td>{{ draft_registration.title }}</td>
</tr>
<tr>
<td>Creator</td>
<td><a href="{{ draft_registration.creator | reverse_user }}">{{ draft_registration.creator }}</a></td>
</tr>
<tr>
<td>Deleted</td>
<td>{{ draft_registration.deleted }}</td>
</tr>
<tr>
<td>Public</td>
<td>{{ draft_registration.is_public }}</td>
</tr>
<tr>
<td>Provider</td>
{% if draft_registration.provider %}
<td><a href="{{ draft_registration | reverse_registration_provider }}">{{ draft_registration.provider.name }}</a></td>
{% else %}
<td>None</td>
{% endif %}
</tr>
{% include "draft_registrations/contributors.html" with draft_registration=draft_registration %}
</tbody>
</table>
</div>
</div>
{% endblock content %}
2 changes: 1 addition & 1 deletion admin/templates/users/draft-registrations.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% for draft_registration in draft_registrations %}
<tr>
<td>
<a href="{{ draft_registration | reverse_node }}"
<a href="{{ draft_registration | reverse_draft_registration }}"
class="btn btn-primary">
{{ draft_registration.guid }}
</a>
Expand Down
1 change: 0 additions & 1 deletion admin/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,6 @@ class UserDraftRegistrationsList(UserMixin, ListView):
permission_required = 'osf.view_draftregistration'
raise_exception = True
ordering = ('-created')
form_class = UserSearchForm
paginate_by = 25

def get_queryset(self):
Expand Down

0 comments on commit 0602579

Please sign in to comment.