Skip to content

Commit

Permalink
#49 #50 Updated the main Requests List view (not the individual ones.)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaraballo17 committed Nov 9, 2020
1 parent ed53d77 commit a58f3ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ <h3>Pending Requests</h3>
<header>
<h3>All Requests</h3>
</header>
{% for request_type in requests %}
{% for request in requests %}
<div class="list-item column two-columns {% if forloop.last %} last-list-item {% endif %}">
<div class="list-title"><a href="{{ request_type.url }}"><h3>{{ request_type.vocabulary }}</h3></a></div>
<div class="list-description"><p>All requests for the {{ request_type.vocabulary }} vocabulary.</p></div>
<div class="list-title"><a href="{{ request.url }}"><h3>{{ request.vocabulary_verbose_name }}</h3></a></div>
<div class="list-description"><p>All requests for the {{ request.vocabulary_verbose_name }} vocabulary.</p></div>
</div>
{% endfor %}
<div class="clear"></div>
Expand Down
18 changes: 8 additions & 10 deletions src/cvinterface/views/request_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from operator import itemgetter

from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse, reverse_lazy

from django.utils.decorators import method_decorator
Expand Down Expand Up @@ -44,24 +45,21 @@
)


class RequestsView(ListView):
class RequestsView(ListView, LoginRequiredMixin):
queryset = []
login_url = reverse_lazy('login')
template_name = 'cvinterface/requests/main_requests_list.html'

@method_decorator(login_required(login_url=reverse_lazy('login')))
def dispatch(self, *args, **kwargs):
return super(RequestsView, self).dispatch(*args, **kwargs)

def get_context_data(self, **kwargs):
context = super(RequestsView, self).get_context_data(**kwargs)
requests_list = [{'name': vocabulary.get('request').get('name'),
'url': reverse(f'{vocabulary_name}request'),
'vocabulary': vocabulary.get('name')}
for vocabulary_name, vocabulary in vocabularies.items()]
'url': reverse(vocabulary.get('request').get('list_url_name')),
'vocabulary_verbose_name': vocabulary.get('name')}
for vocabulary_code, vocabulary in vocabularies.items()]

pending_requests = [(pending_object, pending_object._meta.verbose_name, f'{vocabulary_name}request_update_form')
pending_requests = [(pending_request, vocabulary.get('request').get('name'), vocabulary.get('request').get('update_url_name'))
for vocabulary_name, vocabulary in vocabularies.items()
for pending_object in vocabulary.get('request').get('model').objects.filter(status='Pending')
for pending_request in vocabulary.get('request').get('model').objects.filter(status='Pending')
if vocabulary.get('request').get('model').objects.filter(status='Pending').count() > 0]

context['requests'] = sorted(requests_list, key=itemgetter('name'))
Expand Down

0 comments on commit a58f3ea

Please sign in to comment.