Skip to content

Commit

Permalink
Merge c186ab2 into 59d73f1
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaboiangiu committed Nov 26, 2020
2 parents 59d73f1 + c186ab2 commit a70c44e
Show file tree
Hide file tree
Showing 7 changed files with 502 additions and 2 deletions.
11 changes: 11 additions & 0 deletions insitu/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,14 @@ def save(self, commit=True):
instance.requests.add(request)
self.send_mail_accept_request(instance.user, request)
return instance


class StandardReportForm(forms.Form):
service = forms.ModelMultipleChoiceField(
required=False,
queryset=models.CopernicusService.objects.all(),
label='Service')
component = forms.ModelMultipleChoiceField(
required=False,
queryset=models.Component.objects.all(),
label='Component')
1 change: 0 additions & 1 deletion insitu/management/commands/transfer_ownership.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def transfer_ownership_on_objects(self, objects, **options):


def handle(self, *args, **options):
import pdb;pdb.set_trace();
requirements = Requirement.objects.filter(created_by__username=options['old_username'])
self.transfer_ownership_on_objects(requirements, **options)
data_objects = Data.objects.filter(created_by__username=options['old_username'])
Expand Down
1 change: 1 addition & 0 deletions insitu/templates/reports/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ <h1 class="col-sm-12">
</div>

<div class="container" style="margin-bottom:20px;">
<a href="{% url 'reports:standard_report' %}"><h3>Standard Report</h3></a>
<h3>Special reports:</h3>
<p>Those reports are exported as spreadsheet files with unmerged cells that can be filtered afterwards with specialized tools.</p>
<h4>1.This report contains all relevant columns from products, requirements, data and data requirements for the following services:</h4>
Expand Down
64 changes: 64 additions & 0 deletions insitu/templates/reports/standard_report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{% extends '_layout.html' %}
{% load bootstrap3 %}
{% load static %}
{% load utils %}

{% block title %}Reports{% endblock %}

{% block content %}
<div class="row">
<h1 class="col-sm-12">
<span>Standard Report</span>
</h1>
</div>

<div class="container" style="margin-bottom:20px;">
</div>

<form action="" method="POST" style="width: 50%">
{% csrf_token %}
<div class="form-group">
<label class="control-label" for="id_service">Service</label>
<select name="service" class="form-control" title="" id="id_service" multiple="multiple">
{% for service in services %}
<option value="{{ service.id }}" class="{{ service.id }}">{{ service.name }}</option>
{% endfor %}
</select>
</div>

<div class="form-group">
<label class="control-label" for="id_component">Component</label>
<select name="component" class="form-control" title="" id="id_component" multiple="multiple">
{% for component in components %}
<option value="{{ component.id }}" class="{{ component.service.id }}">{{ component.name }}</option>
{% endfor %}
</select>
</div>

<input class="btn btn-primary" type="submit" value="Generate Excel"/>
<a href="{% url 'home' %}"
class="btn btn-default">Cancel</a>
</form>

{% endblock %}

{% block scripts %}
<script>
$(document).ready(function () {
var allOptions = $('#id_component option')
$('#id_service').change(function () {
$('#id_component option').remove();
var classes = [];
$('#id_service option:selected').each(function( index ) {
classes.push($(this).prop('class'));
});
var opts = allOptions.filter( function(index) {
return $.inArray($(this).prop('class'), classes) > -1;
});
$.each(opts, function (i, j) {
$(j).appendTo('#id_component');
});
});
});
</script>
{% endblock %}
4 changes: 3 additions & 1 deletion insitu/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@
url(r'^list/$',
views.ReportsListView.as_view(),
name='list'),

url(r'^standard_report/$',
views.ReportsStandardReportView.as_view(),
name='standard_report'),
url(r'^(?P<query_id>\d+)/$',
views.ReportsDetailView.as_view(),
name='detail'),
Expand Down
35 changes: 35 additions & 0 deletions insitu/views/reports.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import datetime
import json

import string
import xlsxwriter
from io import BytesIO

from django.template.loader import get_template
Expand Down Expand Up @@ -30,6 +32,9 @@

from wkhtmltopdf.views import PDFTemplateResponse, PDFTemplateView

from insitu.models import Component, CopernicusService
from insitu.forms import StandardReportForm
from insitu.views.reportsmixins import ReportExcelMixin
from insitu.views import protected
from insitu.views.protected.views import ProtectedTemplateView, ProtectedView

Expand Down Expand Up @@ -187,3 +192,33 @@ def post(self, request, *args, **kwargs):
"date": datetime.datetime.now().strftime('%Y %m %d'),
}
return self.render(context, request)


class ReportsStandardReportView(ProtectedTemplateView, ReportExcelMixin):
template_name = 'reports/standard_report.html'
permission_classes = (protected.IsAuthenticated,)
permission_denied_redirect = reverse_lazy('auth:login')

def get_context_data(self, **kwargs):
context = super(ReportsStandardReportView, self).get_context_data(**kwargs)
context['services'] = CopernicusService.objects.all()
context['components'] = Component.objects.all()
context['form'] = StandardReportForm()
return context

def generate_excel(self):
output = BytesIO()
workbook = xlsxwriter.Workbook(output)
self.generate_excel_file(workbook)
workbook.close()
output.seek(0)
filename = 'StandardReport{}.xlsx'.format(datetime.date.today())
response = HttpResponse(
output,
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
)
response['Content-Disposition'] = 'attachment; filename=%s' % filename
return response

def post(self, request, *args, **kwargs):
return self.generate_excel()
Loading

0 comments on commit a70c44e

Please sign in to comment.