Esempio n. 1
0
    def get_users_stats(self, users_per_id):
        entity_length = len(users_per_id)
        if not entity_length:
            return

        # retrieve today's squad off members
        today = datetime.now()
        today_off = []
        today_requests = []
        requests = Request.get_active(self.session)
        for req in requests:
            if req.user.id not in users_per_id:
                continue
            today_requests.append(req)
            if req.user not in today_off:
                today_off.append(req.user)

        # retrieve active requests since 15 days ago
        date_from = today - relativedelta(days=15)

        all_reqs = []
        for user_id, user in list(users_per_id.items()):
            user_req = Request.by_user_future_approved(self.session, user,
                                                       date_from=date_from)
            all_reqs.extend(user_req)

        # compute current month squad presence percentages
        data_months = {}
        for req in all_reqs:
            for dt in req.dates:
                if dt.month not in data_months:
                    data_months[dt.month] = {}
                if dt.day not in data_months[dt.month]:
                    data_months[dt.month][dt.day] = []
                if req.user.login not in data_months[dt.month][dt.day]:
                    data_months[dt.month][dt.day].append(req.user.login)

        data_days_current = []
        labels = []
        start_date = today - timedelta(days=15)
        stop_date = today + timedelta(days=15)
        for x in daterange(start_date, stop_date):
            labels.append("'%s'" % x.strftime('%d/%m'))
            perc = ((entity_length - len(data_months.get(x.month, {}).get(x.day, []))) / float(entity_length) * 100)  # noqa
            perc = round(perc, 2)
            if x.isoweekday() in [6, 7]:
                perc = 0.0
            data_days_current.append(perc)

        labels = '[%s]' % ','.join(labels)
        return {'users_per_id': users_per_id,
                'data_days_current': data_days_current,
                'today_requests': today_requests,
                'labels': labels,
                'today': today,
                'today_off': today_off,
                'today_off_length': len(today_off),
                'entity_length': entity_length,
                }
Esempio n. 2
0
    def render(self):
        if not self.user:
            return self.redirect()

        _ = self.request.translate

        self.user.rtt = self.user.get_rtt_usage(self.session)

        holidays = get_holiday(self.user)

        ret_dict = {'types': [], 'holidays': holidays, 'sudo_users': [],
                    'futures_pending': [], 'futures_approved': []}

        vacation_types = VacationType.by_country(self.session,
                                                 self.user.country)
        for vac in vacation_types:
            if vac.visibility and self.user.role not in vac.visibility:
                continue
            ret_dict['types'].append({'name': _(vac.name), 'id': vac.id})

        if self.user.is_admin:
            ret_dict['sudo_users'] = User.for_admin(self.session, self.user)

        futures_pending = [timestamp
                           for req in
                           Request.by_user_future_pending(self.session,
                                                          self.user)
                           for timestamp in req.timestamps]
        ret_dict['futures_pending'] = futures_pending
        futures_approved = [timestamp
                            for req in
                            Request.by_user_future_approved(self.session,
                                                            self.user)
                            for timestamp in req.timestamps]
        ret_dict['futures_approved'] = futures_approved

        exception_info_tooltip = """\
This type is for events which are not covered by other types: \
wedding, funeral, etc.

Providing a reason for this request is mandatory.
"""
        ret_dict['exception_info_tooltip'] = _(exception_info_tooltip)

        if self.request.matched_route:
            matched_route = self.request.matched_route.name
            ret_dict.update({
                'matched_route': matched_route,
                'csrf_token': self.request.session.get_csrf_token()})
            return ret_dict

        ret_dict.update({'csrf_token': self.request.session.get_csrf_token()})
        return ret_dict
Esempio n. 3
0
    def render(self):
        if not self.user:
            return self.redirect()

        _ = self.request.translate

        holidays = get_holiday(self.user)

        ret_dict = {'types': [], 'holidays': holidays, 'sudo_users': [],
                    'futures_pending': [], 'futures_approved': []}

        vacation_types = VacationType.by_country(self.session,
                                                 self.user.country)
        for vac in vacation_types:
            if vac.visibility and self.user.role not in vac.visibility:
                continue
            # disable RTT for user with feature flag disable_rtt
            if vac.name == 'RTT' and self.user.has_feature('disable_rtt'):
                continue
            ret_dict['types'].append({'name': _(vac.name), 'id': vac.id})

        if self.user.is_admin:
            ret_dict['sudo_users'] = User.for_admin(self.session, self.user)
            managed_users = User.managed_users(self.session, self.user)
            if managed_users:
                ret_dict['sudo_users'].extend(managed_users)
            # special case where LU admin need to have RTT option
            rtt_vacation = VacationType.by_name(self.session, 'RTT')
            rtt_type = {'name': _('RTT'), 'id': rtt_vacation.id}
            if rtt_type not in ret_dict['types']:
                ret_dict['types'].append(rtt_type)
            # remove duplicate entries
            ret_dict['sudo_users'] = list(set(ret_dict['sudo_users']))

        # LU can use their CP if it was on a non working day
        ret_dict['recovered_cp'] = self.user.get_lu_holiday()

        futures_breakdown = [timestamp
                             for req in
                             Request.by_user_future_breakdown(self.session,
                                                              self.user)
                             for timestamp in req.timestamps]
        ret_dict['futures_breakdown'] = futures_breakdown
        futures_pending = [timestamp
                           for req in
                           Request.by_user_future_pending(self.session,
                                                          self.user)
                           for timestamp in req.timestamps]
        ret_dict['futures_pending'] = futures_pending
        futures_approved = [timestamp
                            for req in
                            Request.by_user_future_approved(self.session,
                                                            self.user)
                            for timestamp in req.timestamps]
        ret_dict['futures_approved'] = futures_approved

        exception_info_tooltip = """\
This type is for events which are not covered by other types: \
wedding, funeral, etc.

Providing a reason for this request is mandatory.
"""
        ret_dict['exception_info_tooltip'] = _(exception_info_tooltip)

        recovered_info_tooltip = """\
This type is for holidays which were on a non working day.

You can use them up to 3 months after their date to make a leave request.
Request must be only for 1 day at a time, and not partial (only Full).
"""
        ret_dict['recovered_info_tooltip'] = _(recovered_info_tooltip)

        if self.request.matched_route:
            matched_route = self.request.matched_route.name
            ret_dict.update({
                'matched_route': matched_route,
                'csrf_token': self.request.session.get_csrf_token()})
            return ret_dict

        ret_dict.update({'csrf_token': self.request.session.get_csrf_token()})
        return ret_dict