Skip to content

Commit

Permalink
Merge 8fc9cd9 into bd0eecf
Browse files Browse the repository at this point in the history
  • Loading branch information
eheinrich committed Jul 11, 2019
2 parents bd0eecf + 8fc9cd9 commit 19a9586
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 19 deletions.
13 changes: 12 additions & 1 deletion observation_portal/proposals/filters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import django_filters
from django.utils import timezone
from dateutil.parser import parse
from observation_portal.proposals.models import Semester, Proposal
from observation_portal.proposals.models import Semester, Proposal, Membership


class MembershipFilter(django_filters.FilterSet):
first_name = django_filters.CharFilter(field_name='user__first_name', lookup_expr='icontains', label='First name contains')
last_name = django_filters.CharFilter(field_name='user__last_name', lookup_expr='icontains', label='Last name contains')
username = django_filters.CharFilter(field_name='user__username', lookup_expr='icontains', label='UserId contains')
email = django_filters.CharFilter(field_name='user__email', lookup_expr='icontains', label='Email contains')

class Meta:
model = Membership
fields = ('first_name', 'last_name', 'username', 'email')


class ProposalFilter(django_filters.FilterSet):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,22 @@ <h4>
</h4>
{% if user == object.pi %}
<h4>Co Investigators <small><i id="toggleci" class="fa fa-eye"></i></small></h4>
<table class="table" id="cilist">
<div id="cilist">
{% if members_are_paginated %}
<form method="get" role="form" action="">
<div class="form-row">
<div class="col mb-0 mt-auto">{% bootstrap_field members_filter.form.first_name form_group_class="form-group mb-0 mt-auto" %}</div>
<div class="col mb-0 mt-auto">{% bootstrap_field members_filter.form.last_name form_group_class="form-group mb-0 mt-auto" %}</div>
<div class="col mb-0 mt-auto">{% bootstrap_field members_filter.form.username form_group_class="form-group mb-0 mt-auto" %}</div>
<div class="col mb-0 mt-auto">{% bootstrap_field members_filter.form.email form_group_class="form-group mb-0 mt-auto" %}</div>
<div class="col-1 mb-0 mt-auto">{% bootstrap_button button_type="submit" content="Filter" button_class="btn-outline-secondary" %}</div>
</div>
</form>
<br/>
{% endif %}
<table class="table table-responsive">
<thead>
<tr><th>Name</th><th>UserId</th><th>Email</th><th>Hour Limit</th><th>Hours Requested</th>
<tr><th>First Name</th><th>Last Name</th><th>UserId</th><th>Email</th><th>Hour Limit</th><th>Hours Requested</th>
{% if object.public %}
<th>Simple Interface</th>
{% endif %}
Expand All @@ -28,10 +41,11 @@ <h4>Co Investigators <small><i id="toggleci" class="fa fa-eye"></i></small></h4>
</tr>
</thead>
<tbody>
{% for mem in object.membership_set.all %}
{% for mem in members_page %}
{% if mem.role != 'PI' %}
<tr>
<td>{{ mem.user.first_name }} {{ mem.user.last_name }}</td>
<td>{{ mem.user.first_name }}</td>
<td>{{ mem.user.last_name }}</td>
<td>{{ mem.user.username }}</td>
<td><a href="mailto:{{ mem.user.email }}">{{ mem.user.email }}</a></td>
<td>
Expand Down Expand Up @@ -62,6 +76,16 @@ <h4>Co Investigators <small><i id="toggleci" class="fa fa-eye"></i></small></h4>
{% endfor %}
</tbody>
</table>
{% if members_are_paginated %}
<div class="row">
<div class="col">
<span class="float-left"> {% bootstrap_pagination members_page size="small" parameter_name="ci_page" extra=request.GET.urlencode %}</span>
<span class="float-right">{{ members_page.paginator.count }} Co Investigators</span>
</div>
</div>
{% endif %}
<br/>
</div>
{% endif %}
<h4>Time Allocation</h4>
<table class="table">
Expand Down
12 changes: 10 additions & 2 deletions observation_portal/proposals/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
from django_filters.views import FilterView
from django.utils.translation import ugettext as _
from django.contrib.auth.mixins import UserPassesTestMixin
from django.core.paginator import Paginator

from observation_portal.sciapplications.models import Call
from observation_portal.proposals.forms import ProposalNotificationForm
from observation_portal.proposals.models import Proposal, Membership, ProposalNotification, Semester, ProposalInvite
from observation_portal.proposals.filters import ProposalFilter

from observation_portal.proposals.filters import ProposalFilter, MembershipFilter

class ProposalDetailView(LoginRequiredMixin, DetailView):
model = Proposal
Expand All @@ -42,6 +42,14 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
enabled = ProposalNotification.objects.filter(user=self.request.user, proposal=self.get_object()).exists()
context['notification_form'] = ProposalNotificationForm(initial={'notifications_enabled': enabled})
# Paginate and allow fitering on CoI's as some proposals have a large number of them
members_queryset = self.get_object().membership_set.filter(role=Membership.CI).order_by('id')
members_filter = MembershipFilter(self.request.GET, queryset=members_queryset)
paginate_by = 25
members_paginator = Paginator(members_filter.qs, paginate_by)
context['members_page'] = members_paginator.get_page(self.request.GET.get('ci_page'))
context['members_filter'] = members_filter
context['members_are_paginated'] = members_queryset.count() > paginate_by
return context


Expand Down
14 changes: 8 additions & 6 deletions observation_portal/requestgroups/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,6 @@ class Meta:
read_only_fields = ('priority',)

def validate_instrument_configs(self, value):
# TODO: remove this check once we support multiple instrument configs
if len(value) != 1:
raise serializers.ValidationError(_(
'Currently only a single instrument_config is supported. This restriction will be lifted in the future.'
))
if [instrument_config.get('fill_window', False) for instrument_config in value].count(True) > 1:
raise serializers.ValidationError(_('Only one instrument_config can have `fill_window` set'))
return value
Expand All @@ -249,6 +244,13 @@ def validate(self, data):
default_modes = configdb.get_default_modes_by_type(instrument_type)
guiding_config = data['guiding_config']

# Validate the number of instrument configs if this is not a SOAR instrument
# TODO: remove this check once we support multiple instrument configs
if len(data['instrument_configs']) != 1 and 'SOAR' not in instrument_type.upper():
raise serializers.ValidationError(_(
'Currently only a single instrument_config is supported. This restriction will be lifted in the future.'
))

# Validate the guide mode
guide_validation_helper = ModeValidationHelper('guiding', instrument_type, default_modes, modes)
if guide_validation_helper.mode_is_not_set(guiding_config):
Expand Down Expand Up @@ -631,7 +633,7 @@ class Meta:
)
extra_kwargs = {
'proposal': {'error_messages': {'null': 'Please provide a proposal.'}},
'name': {'error_messages': {'blank': 'Please provide a title.'}}
'name': {'error_messages': {'blank': 'Please provide a name.'}}
}

@transaction.atomic
Expand Down
1 change: 1 addition & 0 deletions static/js/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function archiveAjaxSetup(){
jqXHR.setRequestHeader('Authorization', 'Token ' + sessionStorage.getItem('archiveAuthToken'));
}
});
$(document).trigger('archivelogin');
});
}

Expand Down
14 changes: 11 additions & 3 deletions static/js/components/archivetable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@
],
watch: {
requestid: function(){
$('#archive-table').bootstrapTable('refresh',
{url: archiveRoot + 'frames/?limit=1000&REQNUM=' + this.requestid}
);
this.refreshTable();
}
},
methods: {
Expand All @@ -58,6 +56,13 @@
},
downloadAll: function(){
downloadAll(this.requestid);
},
refreshTable: function() {
if (this.requestid) {
$('#archive-table').bootstrapTable('refresh',
{url: archiveRoot + 'frames/?limit=1000&REQNUM=' + this.requestid}
);
}
}
},
computed: {
Expand Down Expand Up @@ -132,6 +137,9 @@
}
}]
});
$(document).on('archivelogin', function() {
that.refreshTable();
})
}
};
</script>
Expand Down
4 changes: 2 additions & 2 deletions static/js/components/requestgroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
<b-form>
<customfield
v-model="requestgroup.name"
label="Title"
field="title"
label="Name"
field="name"
:errors="errors.name"
@input="update"
/>
Expand Down
10 changes: 9 additions & 1 deletion static/js/request_row.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $('.downloadall').click(function(){
downloadAll($(this).data('requestid'));
});

$(document).ready(function() {
function loadThumbnail() {
$('.thumbnail-small').each(function(idx, elem) {
getLatestFrame($(elem).data('request'), function(frame) {
if (!frame) {
Expand All @@ -21,6 +21,7 @@ $(document).ready(function() {
$(elem).attr('alt', frame.filename);
$(elem).attr('title', frame.filename);
$(elem).prev().show().html('<center><span class="fa fa-spinner fa-spin"></span></center>');
$('button[data-requestid="' + $(elem).data('request') +'"]').prop('disabled', false);
getThumbnail(frame.id, 75, function(data) {
if (data.error) {
$(elem).prev().html(data.error);
Expand All @@ -32,7 +33,14 @@ $(document).ready(function() {
}
});
});
}

$(document).on('archivelogin', function() {
loadThumbnail();
});

$(document).ready(function() {
loadThumbnail();
$('.pending-details').each(function() {
let that = $(this);
let requestId = $(this).data('request');
Expand Down

0 comments on commit 19a9586

Please sign in to comment.