From 2e707935f118fe244ab82b920f81f04561a264d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Hennecart?= Date: Mon, 22 Jul 2019 12:56:38 +0000 Subject: [PATCH] [REF] website_slides_forum: improve integration into eLeaning application MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PURPOSE eLearning should have its own application in manager. Indeed this is becoming a big application and having it embedded inside Website application is not enough anymore. It should also hold updated and easy-to-use menus, navigation, actions and views in backend. SPECIFICATIONS Add menu after Courses * Forum * Forums: add columns to list view: Posts (questions count), Views (sum of views of each post), Answers (sum of child_count on each post), Favorites (sum of favourite_count on each post) * Posts: add columns to list view: Views / Answers / Favourites Add menu entry inside Reporting * Forum: graph view on forum.post model Area chart: # Posts created by months, color=forum LINKS Task 1978729 PR #35061 Co-Authored-By: Thibault Delavallée Co-Authored-By: Jérémy Hennecart --- addons/website_forum/models/forum.py | 24 +++++++++ addons/website_forum/views/forum.xml | 9 +++- addons/website_slides_forum/__manifest__.py | 4 +- .../views/forum_views.xml | 54 +++++++++++++++++++ .../views/website_slides_menu_views.xml | 23 ++++++++ 5 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 addons/website_slides_forum/views/forum_views.xml create mode 100644 addons/website_slides_forum/views/website_slides_menu_views.xml diff --git a/addons/website_forum/models/forum.py b/addons/website_forum/models/forum.py index 2092008b5ca..6d20822b89d 100644 --- a/addons/website_forum/models/forum.py +++ b/addons/website_forum/models/forum.py @@ -80,6 +80,12 @@ class Forum(models.Model): help='After posting the user will be proposed to share its question ' 'or answer on social networks, enabling social network propagation ' 'of the forum content.') + # posts statistics + post_ids = fields.One2many('forum.post', 'forum_id', string='Posts') + total_posts = fields.Integer('Post Count', compute='_compute_slides_statistics') + total_views = fields.Integer('Views Count', compute='_compute_slides_statistics') + total_answers = fields.Integer('Answers Count', compute='_compute_slides_statistics') + total_favorites = fields.Integer('Favorites Count', compute='_compute_slides_statistics') count_posts_waiting_validation = fields.Integer(string="Number of posts waiting for validation", compute='_compute_count_posts_waiting_validation') count_flagged_posts = fields.Integer(string='Number of flagged posts', compute='_compute_count_flagged_posts') # karma generation @@ -120,6 +126,24 @@ class Forum(models.Model): karma_post = fields.Integer(string='Ask questions without validation', default=100) karma_moderate = fields.Integer(string='Moderate posts', default=1000) + @api.depends('post_ids.state', 'post_ids.views', 'post_ids.child_count', 'post_ids.favourite_count') + def _compute_slides_statistics(self): + result = dict((cid, dict(total_posts=0, total_views=0, total_answers=0, total_favorites=0)) for cid in self.ids) + read_group_res = self.env['forum.post'].read_group( + [('forum_id', 'in', self.ids), ('state', 'in', ('active', 'close'))], + ['forum_id', 'views', 'child_count', 'favourite_count'], + groupby=['forum_id'], + lazy=False) + for res_group in read_group_res: + cid = res_group['forum_id'][0] + result[cid]['total_posts'] += res_group.get('__count', 0) + result[cid]['total_views'] += res_group.get('views', 0) + result[cid]['total_answers'] += res_group.get('child_count', 0) + result[cid]['total_favorites'] += res_group.get('favourite_count', 0) + + for record in self: + record.update(result[record.id]) + def _compute_count_posts_waiting_validation(self): for forum in self: domain = [('forum_id', '=', forum.id), ('state', '=', 'pending')] diff --git a/addons/website_forum/views/forum.xml b/addons/website_forum/views/forum.xml index 4e8cfc61e63..8c5a9c126d0 100644 --- a/addons/website_forum/views/forum.xml +++ b/addons/website_forum/views/forum.xml @@ -17,6 +17,10 @@ + + + + @@ -43,7 +47,7 @@ - +