Repository: akvo/akvo-rsr

Issue:
Add My Reports section to My RSR
## Test plan

GIVEN MyRSR
WHEN the user is logged in
THEN the 'My reports' section should be visible

GIVEN the My reports page
WHEN a report is selected
THEN the other form parameters should respond accordingly (e.g. project or organisation parameter is shown, and the correct formats are shown)

GIVEN the My reports page
WHEN all parameters are filled in
THEN the 'Download' button becomes enabled
ELSE the 'Download' button is disabled

GIVEN the user is a superuser or RSR admin
WHEN the user has selected a report template
THEN the organisation or project parameter should be a typeahead with all organisations or projects
ELSE the organisation or project parameter should be a dropdown with all organisations or projects that the user has access to

GIVEN the 'Download' button is clicked
THEN all fields should be disabled for 5 seconds
AND the report should be downloaded _(cannot be tested locally, needs ReportServer)_
## Issue description

Add My Reports section to My RSR where users can export reports about their project(s). Reports created with reportserver.

@Geerts is working on templates for: 
- Financial report: shows budget related info
- Quality report: showing overview of actions that need to be done after project expiry date
- Overview report: shows the status of projects. 

Design team is creating a UI design according to:

User story 33
As an authorised user I want to choose a report template. 

Scenario 33 
An a PME manager I want to be able to choose a report template from a pre-set list of templates. In this way I can create a report about my results framework, but also about financial transactions, all RSR updates made to a project or an overview of all active projects that my organisation is showing online. 

User story 34
As an authorised user I want to choose the report format. 

Scenario 34
As a PME manager I want to be able to export my format to Word (to be able to edit), PDF (standard design), Excel (raw data file) or ODT (open document) or HTML. 

User story 35
As an authorised user I want to create a report about a specific project.

Scenario 35
As a program manager I want to be able to create a report for a specific project, because I want to share the progress we are making with everyone involved in order for internal program steering. 

User story 36
As an authorised user I want to create a report about a set of projects using the same (inherited) results framework.

Scenario 36
As a program manager I want to be able to create a report about a set of child projects, because I want to give an overall overview about the progress my organisation is making. I therefore need to be able to select multiple projects for the same report. 

User story 37
As an authorised user I want to create a report about a specific time period. 

Scenario 37
As a program manager I want to be able to create a report about the last year, since I need to send an annual report to my donor. Therefore I need to be able to select a specific period of time. 

User story 38
As an authorised user I want to export the template and be able to add and edit data, and save it. 

Scenario 38
As a PME manager I want to export a report to a format e.g. DOC in which I can add photos and additional text myself, and to match it with the branding of my organisation.

User story 39
As an authorised user I want to export the report and save it.

Scenario 39
As a project officer I want to export a report and save it, so that I can share it via email or internally. 
progress my organisation is making. I therefore need to be able to select multiple projects for the same report. 



Discussion:

Resolving patch:
diff --git a/akvo/rsr/reports.py b/akvo/rsr/reports.py
new file mode 100644
--- /dev/null
+++ b/akvo/rsr/reports.py
@@ -0,0 +1,75 @@
+# -*- coding: utf-8 -*-
+
+# Akvo RSR is covered by the GNU Affero General Public License.
+# See more details in the license.txt file located at the root folder of the Akvo RSR module.
+# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.
+
+from django.utils.translation import ugettext_lazy as _
+
+# Data for all available reports from ReportServer, with the following fields:
+# - key: A unique identifier for the report
+# - title: The title of the report, will be shown on the 'My reports' page as such
+# - description: The description of the report, as displayed on the 'My reports' page
+# - formats: The available formats for the report, see options below
+# - parameters: The available parameters for the report, options; ['project', 'organisation']
+# - url: The URL where the report is available. Parameter(s) should be indicated in between {..}'s.
+
+REPORTS = [
+    {
+        'key': 'results-framework',
+        'title': unicode(_('Results and indicators overview')),
+        'description': unicode(_('This report gives an overview of the status of your project\'s '
+                                 'results and indicators.')),
+        'formats': ['pdf', 'word', 'excel', 'html'],
+        'parameters': ['project', ],
+        'url': '/en/reports/project_results/{project}?format={format}&download=true'
+    },
+    {
+        'key': 'projects-overview',
+        'title': unicode(_('Projects overview')),
+        'description': unicode(_('This report provides information about your organisation\'s '
+                                 'projects: amount of updates, country, total budgets, project '
+                                 'statuses, start- and end dates.')),
+        'formats': ['excel', 'word'],
+        'parameters': ['organisation', ],
+        'url': '/en/reports/projects_overview/{organisation}?format={format}&download=true'
+    },
+    {
+        'key': 'data-quality',
+        'title': unicode(_('Data quality overview')),
+        'description': unicode(_('This report gives an overview of your organisation\'s projects '
+                                 'that have passed the planned end date, need funding or that '
+                                 'haven\'t been edited or updated for 3 months.')),
+        'formats': ['excel', 'word'],
+        'parameters': ['organisation', ],
+        'url': '/en/reports/data_quality/{organisation}?format={format}&download=true'
+    }
+]
+
+# Data for all available formats from ReportServer, with the following fields:
+# - key: A unique identifier for the format, also used in the formats field of the reports
+# - displayName: The display name of the format, as displayed on the 'My reports' page
+# - icon: The font awesome icon of the format, as displayed on the 'My reports' page
+
+FORMATS = [
+    {
+        'key': 'pdf',
+        'displayName': 'PDF',
+        'icon': 'file-pdf-o',
+    },
+    {
+        'key': 'excel',
+        'displayName': 'Excel',
+        'icon': 'file-excel-o',
+    },
+    {
+        'key': 'word',
+        'displayName': 'Word',
+        'icon': 'file-word-o',
+    },
+    {
+        'key': 'html',
+        'displayName': 'HTML',
+        'icon': 'code',
+    },
+]
diff --git a/akvo/rsr/views/my_rsr.py b/akvo/rsr/views/my_rsr.py
--- a/akvo/rsr/views/my_rsr.py
+++ b/akvo/rsr/views/my_rsr.py
@@ -7,7 +7,6 @@
 see < http://www.gnu.org/licenses/agpl.html >.
 """
 
-from django.conf import settings
 from django.contrib.auth.decorators import login_required
 from django.contrib.auth.models import Group
 from django.core.exceptions import PermissionDenied
@@ -17,6 +16,7 @@
 from django.shortcuts import render, render_to_response
 from django.template import RequestContext
 
+from akvo.rsr.reports import FORMATS, REPORTS
 from ..forms import (PasswordForm, ProfileForm, UserOrganisationForm, UserAvatarForm,
                      SelectOrgForm, IatiExportForm)
 from ..filters import remove_empty_querydict_items
@@ -295,6 +295,36 @@ def my_iati(request):
     return render(request, 'myrsr/my_iati.html', context)
 
 
+@login_required
+def my_reports(request):
+    """My reports section."""
+    user = request.user
+
+    if not user.can_create_project():
+        raise PermissionDenied
+
+    organisations_data, projects_data = [], []
+    for employment in user.approved_employments():
+        org = employment.organisation
+        organisations_data.append({'id': org.pk,
+                                   'name': '{0} ({1})'.format(org.name, org.long_name)})
+        for project in org.all_projects():
+            if project.pk not in [project_data['id'] for project_data in projects_data]:
+                projects_data.append({'id': project.pk,
+                                      'name': '{0} (id: {1})'.format(project.title,
+                                                                     str(project.pk))})
+
+    context = {
+        'reports_data': json.dumps(REPORTS),
+        'organisations_data': json.dumps(organisations_data),
+        'projects_data': json.dumps(projects_data),
+        'formats_data': json.dumps(FORMATS),
+        'user_data': json.dumps({'is_admin': user.is_superuser or user.is_admin})
+    }
+
+    return render(request, 'myrsr/my_reports.html', context)
+
+
 @login_required
 def user_management(request):
     """Directory of users connected to the user."""
diff --git a/akvo/urls.py b/akvo/urls.py
--- a/akvo/urls.py
+++ b/akvo/urls.py
@@ -114,6 +114,9 @@
     url(r'^myrsr/iati/$',
         'akvo.rsr.views.my_rsr.my_iati', name='my_iati'),
 
+    url(r'^myrsr/reports/$',
+        'akvo.rsr.views.my_rsr.my_reports', name='my_reports'),
+
     url(r'^myrsr/user_management/$',
         'akvo.rsr.views.my_rsr.user_management', name='user_management'),
 


Test patch: