Server IP : 127.0.0.2 / Your IP : 3.17.156.98 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /opt/odoo/addons/website_rating_project_issue/controllers/ |
Upload File : |
# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from werkzeug.exceptions import NotFound import datetime from odoo import http from odoo.http import request class WebsiteRatingProject(http.Controller): @http.route(['/project/rating/'], type='http', auth="public", website=True) def index(self, **kw): projects = request.env['project.project'].sudo().search([('rating_status', '!=', 'no'), ('website_published', '=', True)]) values = {'projects': projects} return request.render('website_rating_project_issue.index', values) @http.route(['/project/rating/<int:project_id>'], type='http', auth="public", website=True) def page(self, project_id=None, **kw): user = request.env.user project = request.env['project.project'].sudo().browse(project_id) # to avoid giving any access rights on projects to the public user, let's use sudo # and check if the user should be able to view the project (project managers only if it's unpublished or has no rating) if not ((project.rating_status<>'no') and project.website_published) and not user.sudo(user).has_group('project.group_project_manager'): raise NotFound() values = { 'project': project, 'task_data': self._calculate_rating(project.id, "project.task"), 'issue_data': self._calculate_rating(project.id, "project.issue"), } return request.render('website_rating_project_issue.project_rating_page', values) def _calculate_rating(self, project_id, model_name): # Calculate rating for Tasks and Issues records = request.env[model_name].sudo().search([('project_id', '=', project_id)]) domain = [('res_model', '=', model_name), ('res_id', 'in', records.ids), ('consumed', '=', True)] ratings = request.env['rating.rating'].search(domain, order="id desc", limit=100) yesterday = (datetime.date.today() - datetime.timedelta(days=-1)).strftime('%Y-%m-%d 23:59:59') stats = {} for x in (7, 30, 90): todate = (datetime.date.today() - datetime.timedelta(days=x)).strftime('%Y-%m-%d 00:00:00') domdate = domain + [('create_date', '<=', yesterday), ('create_date', '>=', todate)] stats[x] = {1: 0, 5: 0, 10: 0} rating_stats = request.env['rating.rating'].read_group(domdate, [], ['rating']) total = reduce(lambda x, y: y['rating_count'] + x, rating_stats, 0) for rate in rating_stats: stats[x][rate['rating']] = float("%.2f" % (rate['rating_count'] * 100.0 / total)) return {'ratings': ratings, 'stats': stats}