Skip to content

Commit

Permalink
- fixed issue with user office not being able to get user projects fo…
Browse files Browse the repository at this point in the history
…r consumables and recurring charges
  • Loading branch information
rptmat57 committed Dec 7, 2022
1 parent 7cda7e9 commit 3d3f13d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion NEMO/templates/consumables/consumables.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ <h1>Withdraw consumables</h1>
$('#customer_search').prop('required', false).hide();
$('#chosen_customer').val(search_selection.name).show();
$('#customer').val(search_selection.id);
ajax_get("{% url 'get_projects' %}", {'user_id': search_selection.id}, update_projects);
ajax_get("{% url 'get_projects_for_consumables' %}", {'user_id': search_selection.id}, update_projects);
}
function update_projects(response, status, xml_http_request)
{
Expand Down
6 changes: 3 additions & 3 deletions NEMO/templates/consumables/recurring_charge.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h1 class="form-group">{% if form.instance.id %}Modify {{ form.instance.name }}{
<div class="form-group">
<label class="control-label col-sm-2" for="recurring_charge_name"><b>Name</b></label>
<div class="col-sm-6 col-md-4">
<input required class="form-control" id="recurring_charge_name" name="name" type="text" autocomplete="off" value="{{ form.instance.name }}" {% if form.fields.name.disabled %}disabled{% endif %}/>
<input required class="form-control" id="recurring_charge_name" name="name" type="text" autocomplete="off" value="{{ form.instance.name }}" {% if form.fields.name.disabled %}disabled{% endif %} autofocus/>
</div>
{% if form.name.errors %}
<div class="col-sm-4 col-md-6 form-control-static danger-highlight">
Expand Down Expand Up @@ -167,7 +167,7 @@ <h1 class="form-group">{% if form.instance.id %}Modify {{ form.instance.name }}{
$('#customer_search').hide();
$('#chosen_customer').val(search_selection.name).show();
$('#customer').val(search_selection.id);
ajax_get("{% url 'get_projects' %}", {'user_id': search_selection.id}, [update_projects, callback]);
ajax_get("{% url 'get_projects_for_consumables' %}", {'user_id': search_selection.id}, [update_projects, callback]);
}
function update_projects(response, status, xml_http_request)
{
Expand Down Expand Up @@ -199,7 +199,7 @@ <h1 class="form-group">{% if form.instance.id %}Modify {{ form.instance.name }}{
}
window.addEventListener("load", function ()
{
$('#customer_search').autocomplete('users', fetch_projects, {{ users|json_search_base }}).focus();
$('#customer_search').autocomplete('users', fetch_projects, {{ users|json_search_base }});
{% if form.cleaned_data %}
{% if form.cleaned_data.customer %}
fetch_projects(null, {'id': '{{ form.cleaned_data.customer.id }}', 'name': '{{ form.cleaned_data.customer.get_name }}' }, null, function(){$('#project').val('{{ form.cleaned_data.project.id }}');});
Expand Down
2 changes: 1 addition & 1 deletion NEMO/templates/training/training.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ <h1>Training</h1>
"entry_number": row
};
let target_element = "#project__" + row;
let url = "{% url 'get_projects' %}?" + jQuery.param(parameters);
let url = "{% url 'get_projects_for_training' %}?" + jQuery.param(parameters);
let report_error = ajax_complete_callback("Could not fetch projects for user", "There was a problem obtaining the list of projects for the user.");
$(target_element).load(url, undefined, report_error);
}
Expand Down
3 changes: 2 additions & 1 deletion NEMO/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
path("", landing.landing, name="landing"),

# Get a list of projects for a user:
path("get_projects/", get_projects.get_projects, name="get_projects"),
path("get_projects_for_consumables/", get_projects.get_projects_for_consumables, name="get_projects_for_consumables"),
path("get_projects_for_training/", get_projects.get_projects_for_training, name="get_projects_for_training"),
path("get_projects_for_tool_control/", get_projects.get_projects_for_tool_control, name="get_projects_for_tool_control"),
path("get_projects_for_self/", get_projects.get_projects_for_self, name="get_projects_for_self"),

Expand Down
10 changes: 10 additions & 0 deletions NEMO/views/get_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@

@staff_member_or_tool_superuser_required
@require_GET
def get_projects_for_training(request):
return get_projects(request)


@any_staff_required
@require_GET
def get_projects_for_consumables(request):
return get_projects(request)


def get_projects(request):
""" Gets a list of all active projects for a specific user. This is only accessible by staff members. """
user = get_object_or_404(User, id=request.GET.get('user_id', None))
Expand Down

0 comments on commit 3d3f13d

Please sign in to comment.