Exemplo n.º 1
0
    def __init__(self, tracker):
        self._tracker_type = tracker.type
        self._tracker_name = tracker.name

        self.id = ''
        self.time = 0.0
        self.desc = ''
        self.reporter = User(name='unknown', email='unknown')
        self.owner = User(name='unknown', email='unknown')
        self.priority = ''
        self.priority_number = 5  # 1 - 5
        self.severity = ''
        self.severity_number = 5  # 1 - 5
        self.status = ''
        self.resolution = ''
        self.project_name = ''
        self.component_name = ''
        self.version = ''
        self.project_id = None
        self.project = None
        self.deadline = ''
        self.opendate = None
        self.changeddate = None
        self.dependson = {}
        self.blocked = {}
        self.url = '#'
        self.labels = []
Exemplo n.º 2
0
    def _annually_report(self, year):
        year_start = datetime.date(year, 1, 1)
        year_end = datetime.date(year, 12, 31)
        excuses_error = None
        config_obj = ApplicationConfig.get_current_config()
        query = DBSession.query('uid', 'date', 'presence').from_statement("""
        SELECT p.user_id as "uid",
               date_trunc('day', p.ts) as "date",
               MIN(p.ts) as "presence"
        FROM presence_entry p
        WHERE p.ts >= :year_start AND
              p.ts <= :year_end
        GROUP BY p.user_id, date_trunc('day', p.ts)
        """).params(year_start=year_start, year_end=year_end)
        data = query.all()
        users = User.query.filter(User.is_active==True)\
                          .filter(User.is_not_client())\
                          .filter(User.is_not_freelancer())\
                          .order_by(User.name).all()

        _excuses = excuses.presence()

        data = self._group_by_user_monthly(data, _excuses)
        stats = self._prepare_statistics(data)

        return dict(
            data=data,
            users=users,
            stats=stats,
            today=datetime.datetime.today(),
            year_start=year_start,
            deltazero=deltazero,
            late_limit=config_obj.monthly_late_limit,
            excuses_error=excuses_error,
        )
Exemplo n.º 3
0
    def get(self):
        check_role = self.request.GET.get('role')
        if not check_role or check_role == 'None':
            pivot_q = self.session.query(User.id, User.name, User.start_work, User.stop_work, User.roles)\
                                .filter(User.is_not_client())\
                                .filter(User.is_active==True)\
                                .order_by(User.name)
        else:
            pivot_q = self.session.query(User.id, User.name, User.start_work, User.stop_work, User.roles)\
                                .filter(User.is_not_client())\
                                .filter(User.is_active==True)\
                                .filter(User.roles.op('&&')('{%s}'%(check_role)))\
                                .order_by(User.name)

        users = {}
        for s in pivot_q:
            if s.start_work:
                users.setdefault(s.start_work.year, [0]*24)[s.start_work.month-1] += 1
            if s.stop_work:
                users.setdefault(s.stop_work.year, [0]*24)[s.stop_work.month-1+12] += 1
        role = User.ROLES
        return dict(
            start=users,
            roles=role,
            check=check_role,
            quarters_sum=self._quarters_sum,
            link_with_year=self._create_link_with_year,
            link_with_month=self._create_link_with_month,
            link_with_quarter=self._create_link_with_quarter,
        )
Exemplo n.º 4
0
    def get(self):
        check_role = self.request.GET.get('role')
        if not check_role or check_role == 'None':
            pivot_q = self.session.query(User.id, User.name, User.start_work, User.stop_work, User.roles)\
                                .filter(User.is_not_client())\
                                .filter(User.is_active==True)\
                                .order_by(User.name)
        else:
            pivot_q = self.session.query(User.id, User.name, User.start_work, User.stop_work, User.roles)\
                                .filter(User.is_not_client())\
                                .filter(User.is_active==True)\
                                .filter(User.roles.op('&&')('{%s}'%(check_role)))\
                                .order_by(User.name)

        users = {}
        for s in pivot_q:
            if s.start_work:
                users.setdefault(s.start_work.year,
                                 [0] * 24)[s.start_work.month - 1] += 1
            if s.stop_work:
                users.setdefault(s.stop_work.year,
                                 [0] * 24)[s.stop_work.month - 1 + 12] += 1
        role = User.ROLES
        return dict(
            start=users,
            roles=role,
            check=check_role,
            quarters_sum=self._quarters_sum,
            link_with_year=self._create_link_with_year,
            link_with_month=self._create_link_with_month,
            link_with_quarter=self._create_link_with_quarter,
        )
Exemplo n.º 5
0
    def get(self):
        res = User.query.filter(User.is_active == True).filter(User.is_not_client()).order_by(User.name).all()

        users = [user for user in res if not user.freelancer]
        freelancers = [user for user in res if user.freelancer]

        clients = []
        if self.request.has_perm("admin"):
            clients = User.query.filter(User.is_active == True).filter(User.is_client()).order_by(User.name).all()

        return dict(users=users, freelancers=freelancers, clients=clients)
Exemplo n.º 6
0
    def __iter__(self):
        if self.empty:
            yield '', u'-- None --'
        query = DBSession.query(User.id, User.name).filter(User.is_not_client()).filter(User.is_active==True).order_by(User.name)
        for id, name in query:
            yield str(id), name

        if self.inactive:
            yield '', ' '*8
            query = DBSession.query(User.id, User.name).filter(User.is_not_client()).filter(User.is_active==False).order_by(User.name)
            for id, name in query:
                yield str(id), name
Exemplo n.º 7
0
    def get(self):
        check_role = self.request.GET.get('role')
        get_year =  self.request.GET.get('year')
        get_month = self.request.GET.get('month')
        get_stop_work = self.request.GET.get('stop')
        get_quaters = self.request.GET.get('q')
        is_get = True if check_role or get_month or get_stop_work or get_year else False
        users=[]
        if get_year:
            year = int(get_year)
            if get_month:

                month = int(get_month)
                day_of_week, days_in_month = calendar.monthrange(year, month)
                start_date = datetime.date(year, month, 1)
                stop_date = datetime.date(year, month, days_in_month)
            elif get_quaters:
                quater = int(get_quaters)
                day_of_week, days_in_month = calendar.monthrange(year, quater*3)
                start_date = datetime.date(year, ((quater-1)*3)+1, 1)
                stop_date = datetime.date(year, quater*3, days_in_month)
            else:
                start_date = datetime.date(year, 1, 1)
                stop_date = datetime.date(year, 12, 31)

            if (not check_role or check_role == 'None') and not get_stop_work:
                users = User.query.filter(User.is_not_client())\
                                  .filter(User.start_work >= start_date)\
                                  .filter(User.start_work <= stop_date)\
                                  .order_by(User.name).all()

            elif (not check_role or check_role == 'None') and get_stop_work:
                users = User.query.filter(User.is_not_client())\
                                  .filter(User.stop_work >= start_date)\
                                  .filter(User.stop_work <= stop_date)\
                                  .order_by(User.name).all()
            elif check_role and get_stop_work:
                users = User.query.filter(User.is_not_client())\
                                  .filter(User.stop_work >= start_date)\
                                  .filter(User.stop_work <= stop_date)\
                                  .filter(User.roles.op('&&')('{%s}'%(check_role)))\
                                  .order_by(User.name).all()
            elif check_role and not get_stop_work:
                users = User.query.filter(User.is_not_client())\
                                  .filter(User.start_work >= start_date)\
                                  .filter(User.start_work <= stop_date)\
                                  .filter(User.roles.op('&&')('{%s}'%(check_role)))\
                                  .order_by(User.name).all()

        return dict(
            users=users,
            is_get=is_get
        )
Exemplo n.º 8
0
    def get(self):
        check_role = self.request.GET.get('role')
        get_year = self.request.GET.get('year')
        get_month = self.request.GET.get('month')
        get_stop_work = self.request.GET.get('stop')
        get_quaters = self.request.GET.get('q')
        is_get = True if check_role or get_month or get_stop_work or get_year else False
        users = []
        if get_year:
            year = int(get_year)
            if get_month:

                month = int(get_month)
                day_of_week, days_in_month = calendar.monthrange(year, month)
                start_date = datetime.date(year, month, 1)
                stop_date = datetime.date(year, month, days_in_month)
            elif get_quaters:
                quater = int(get_quaters)
                day_of_week, days_in_month = calendar.monthrange(
                    year, quater * 3)
                start_date = datetime.date(year, ((quater - 1) * 3) + 1, 1)
                stop_date = datetime.date(year, quater * 3, days_in_month)
            else:
                start_date = datetime.date(year, 1, 1)
                stop_date = datetime.date(year, 12, 31)

            if (not check_role or check_role == 'None') and not get_stop_work:
                users = User.query.filter(User.is_not_client())\
                                  .filter(User.start_work >= start_date)\
                                  .filter(User.start_work <= stop_date)\
                                  .order_by(User.name).all()

            elif (not check_role or check_role == 'None') and get_stop_work:
                users = User.query.filter(User.is_not_client())\
                                  .filter(User.stop_work >= start_date)\
                                  .filter(User.stop_work <= stop_date)\
                                  .order_by(User.name).all()
            elif check_role and get_stop_work:
                users = User.query.filter(User.is_not_client())\
                                  .filter(User.stop_work >= start_date)\
                                  .filter(User.stop_work <= stop_date)\
                                  .filter(User.roles.op('&&')('{%s}'%(check_role)))\
                                  .order_by(User.name).all()
            elif check_role and not get_stop_work:
                users = User.query.filter(User.is_not_client())\
                                  .filter(User.start_work >= start_date)\
                                  .filter(User.start_work <= stop_date)\
                                  .filter(User.roles.op('&&')('{%s}'%(check_role)))\
                                  .order_by(User.name).all()

        return dict(users=users, is_get=is_get)
Exemplo n.º 9
0
    def __iter__(self):
        if self.empty:
            yield '', u'-- None --'
        query = DBSession.query(User.id,
                                User.name).filter(User.is_not_client()).filter(
                                    User.is_active == True).order_by(User.name)
        for id, name in query:
            yield str(id), name

        if self.inactive:
            yield '', ' ' * 8
            query = DBSession.query(User.id, User.name).filter(
                User.is_not_client()).filter(User.is_active == False).order_by(
                    User.name)
            for id, name in query:
                yield str(id), name
Exemplo n.º 10
0
    def get(self):
        year = self.request.GET.get('year', datetime.date.today().year)
        users = User.query.filter(User.is_not_client()).filter(
            User.is_active == True).filter(User.freelancer == False).all()

        used_entries = self.session.query('user_id', 'days').from_statement("""
            SELECT t.user_id, sum(t.time)/8 as days
            FROM time_entry t
            WHERE deleted = false AND
                  t.project_id = 86 AND
                  date_part('year', t.date) = :year
            GROUP BY user_id
        """).params(year=year).all()

        used = defaultdict(lambda: 0)
        for u in used_entries:
            used[u[0]] = u[1]

        applications = m.Absence.get_for_year(year)

        return dict(
            users=users,
            mandated=Leave.get_for_year(year),
            used=used,
            applications=applications,
            year=int(year),
            serialize_url=h.serialize_url,
            str=str,
        )
Exemplo n.º 11
0
 def __init__(self, key, bug_id, status, description, tracker):
     self.id = bug_id
     self.status = status
     self.desc = description
     self.resolved = self.status in JiraFetcher.RESOLVED_STATUSES
     self.url = tracker.url + '/browse/{}'.format(key)
     self.owner = User(name='unknown')
Exemplo n.º 12
0
    def get(self):
        year = self.request.GET.get('year', datetime.date.today().year)
        users = User.query.filter(User.is_not_client()).filter(User.is_active==True).filter(User.freelancer==False).all()

        used_entries = self.session.query('user_id', 'days').from_statement("""
            SELECT t.user_id, sum(t.time)/8 as days
            FROM time_entry t
            WHERE deleted = false AND
                  t.project_id = 86 AND
                  date_part('year', t.date) = :year
            GROUP BY user_id
        """).params(year=year).all()

        used = defaultdict(lambda: 0)
        for u in used_entries:
            used[u[0]] = u[1]

        applications = m.Absence.get_for_year(year)

        return dict(
            users=users,
            mandated=Leave.get_for_year(year),
            used=used,
            applications=applications,
            year=int(year),
            serialize_url=h.serialize_url,
            str=str,
        )
Exemplo n.º 13
0
 def __init__(self, bug_id, status, description, tracker):
     self.id = bug_id
     self.status = status
     self.desc = description
     self.resolved = self.status in ('CLOSED', 'RESOLVED', 'VERIFIED')
     self.url = tracker.url + '/show_bug.cgi?id=%s' % bug_id
     self.owner = User(name='unknown')
Exemplo n.º 14
0
 def _get_not_full_time_employees(self):
     users = User.query\
                 .filter(User.is_active==True)\
                 .filter(User.is_not_client())\
                 .filter(User.start_full_time_work==None)\
                 .order_by(User.name)
     users = users.all()
     return users
Exemplo n.º 15
0
 def _get_not_full_time_employees(self):
     users = User.query\
                 .filter(User.is_active==True)\
                 .filter(User.is_not_client())\
                 .filter(User.start_full_time_work==None)\
                 .order_by(User.name)
     users = users.all()
     return users
Exemplo n.º 16
0
    def __iter__(self):
        if self.first_empty:
            yield '', ''*8
        query = DBSession.query(User.id, User.name)\
                              .filter(User.is_not_client())\
                              .filter(User.is_active==True)\
                              .order_by(User.name)
        for client_id, client_name in query:
            yield str(client_id), client_name

        if self.inactive:
            yield '', ' '*8
            query = DBSession.query(User.id, User.name)\
                                  .filter(User.is_not_client())\
                                  .filter(User.is_active==False)\
                                  .order_by(User.name)
            for id, name in query:
                yield str(id), name
Exemplo n.º 17
0
    def get(self):
        users = (
            User.query.filter(User.is_active == True)
            .filter(User.is_not_client())
            .filter(User.freelancer == False)
            .order_by(User.name)
        )

        return [{"id": u.id, "name": u.name, "img": u.avatar_url} for u in users]
Exemplo n.º 18
0
    def __iter__(self):
        if self.first_empty:
            yield '', '' * 8
        query = DBSession.query(User.id, User.name)\
                              .filter(User.is_not_client())\
                              .filter(User.is_active==True)\
                              .order_by(User.name)
        for client_id, client_name in query:
            yield str(client_id), client_name

        if self.inactive:
            yield '', ' ' * 8
            query = DBSession.query(User.id, User.name)\
                                  .filter(User.is_not_client())\
                                  .filter(User.is_active==False)\
                                  .order_by(User.name)
            for id, name in query:
                yield str(id), name
Exemplo n.º 19
0
    def get(self):
        full = self.request.GET.get('full') == '1'
        inactive = self.request.GET.get('inactive') == '1'

        users = User.query.order_by(User.name)

        if not (self.request.has_perm('can_see_inactive_users') and inactive):
            users = users.filter(User.is_active==True)

        if full:
            return dict(
                users=[u.to_dict(full=True) for u in users],
            )
        else:
            users = users.filter(User.is_not_client())\
                         .filter(User.is_not_freelancer())
            return dict(
                users=[u.to_dict() for u in users],
            )
Exemplo n.º 20
0
    def get(self):
        year = self.request.GET.get('year', datetime.date.today().year)
        users = User.query.filter(User.is_not_client())\
                          .filter(User.is_active==True)\
                          .filter(User.is_not_freelancer())
        users = users.all()

        used = Leave.get_used_for_year(year)
        applications = m.Absence.get_for_year(year)

        return dict(
            users=users,
            mandated=Leave.get_for_year(year),
            used=used,
            applications=applications,
            year=int(year),
            serialize_url=h.serialize_url,
            str=str,
        )
Exemplo n.º 21
0
    def get(self):
        year = self.request.GET.get('year', datetime.date.today().year)
        users = User.query.filter(User.is_not_client())\
                          .filter(User.is_active==True)\
                          .filter(User.is_not_freelancer())
        users = users.all()

        used = Leave.get_used_for_year(year)
        applications = m.Absence.get_for_year(year)

        return dict(
            users=users,
            mandated=Leave.get_for_year(year),
            used=used,
            applications=applications,
            year=int(year),
            serialize_url=h.serialize_url,
            str=str,
        )
Exemplo n.º 22
0
    def _annually_report(self, year):
        year_start = datetime.date(year, 1, 1)
        year_end = datetime.date(year, 12, 31)
        excuses_error = None
        config_obj = ApplicationConfig.get_current_config()
        entries = DBSession.query('user_id', 'date').from_statement("""
        SELECT date_trunc('day', s.date) as date, s.user_id as user_id
        FROM time_entry s
        WHERE DATE(s.modified_ts) > s.date AND
              s.date >= :year_start AND
              s.date <= :year_end
        GROUP BY date_trunc('day', s.date), s.user_id
        """).params(year_start=year_start, year_end=year_end)

        users = User.query.filter(User.is_active==True)\
                          .filter(User.is_not_client())\
                          .order_by(User.is_freelancer(), User.name)

        entries_grouped = {}
        _excuses = excuses.wrongtime()

        for user_id, date in entries:
            month = date.month - 1
            entry = entries_grouped.setdefault(user_id, [0] * 12)
            if date.strftime('%Y-%m-%d') not in _excuses.get(user_id,
                                                             {}).keys():
                entry[month] += 1

        stats = {}

        for user_id, entry in entries_grouped.iteritems():
            stats_entry = stats.setdefault(user_id, [0])
            stats_entry[0] = sum(entry)

        return dict(
            entries=entries_grouped,
            stats=stats,
            users=users,
            year_start=year_start,
            limit=config_obj.monthly_incorrect_time_record_limit,
            excuses_error=excuses_error,
        )
Exemplo n.º 23
0
    def _annually_report(self, year):
        year_start = datetime.date(year, 1, 1)
        year_end = datetime.date(year, 12, 31)
        excuses_error = None
        config_obj = ApplicationConfig.get_current_config()
        entries = DBSession.query('user_id', 'date').from_statement("""
        SELECT date_trunc('day', s.date) as date, s.user_id as user_id
        FROM time_entry s
        WHERE DATE(s.modified_ts) > s.date AND
              s.date >= :year_start AND
              s.date <= :year_end
        GROUP BY date_trunc('day', s.date), s.user_id
        """).params(year_start=year_start, year_end=year_end)

        users = User.query.filter(User.is_active==True)\
                          .filter(User.is_not_client())\
                          .order_by(User.is_freelancer(), User.name)

        entries_grouped = {}
        _excuses = excuses.wrongtime()

        for user_id, date in entries:
            month = date.month - 1
            entry = entries_grouped.setdefault(user_id, [0]*12)
            if date.strftime('%Y-%m-%d') not in _excuses.get(user_id, {}).keys():
                entry[month] += 1

        stats = {}

        for user_id, entry in entries_grouped.iteritems():
            stats_entry = stats.setdefault(user_id, [0])
            stats_entry[0] = sum(entry)

        return dict(
            entries=entries_grouped,
            stats=stats,
            users=users,
            year_start=year_start,
            limit=config_obj.monthly_incorrect_time_record_limit,
            excuses_error=excuses_error,
        )
Exemplo n.º 24
0
    def get(self):
        users = User.query.filter(User.is_active==True)\
                          .filter(User.is_not_client())\
                          .filter(User.freelancer==False)\
                          .order_by(User.name).all()
        freelancers = User.query.filter(User.is_active==True)\
                                .filter(User.is_not_client())\
                                .filter(User.freelancer==True)\
                                .order_by(User.name).all()

        clients = []
        if self.request.has_perm('admin'):
            clients = User.query.filter(User.is_active==True)\
                                .filter(User.is_client())\
                                .order_by(User.name).all()

        return dict(
            users=users,
            freelancers=freelancers,
            clients=clients,
        )
Exemplo n.º 25
0
    def __iter__(self):
        if self.empty:
            yield "", u"-- None --"
        query = (
            self.session.query(User.id, User.name)
            .filter(not_(User.is_client()))
            .filter(User.is_active == True)
            .order_by(User.name)
        )
        for id, name in query:
            yield str(id), name

        if self.inactive:
            yield "", " " * 8
            query = (
                self.session.query(User.id, User.name)
                .filter(User.is_client())
                .filter(User.is_active == False)
                .order_by(User.name)
            )
            for id, name in query:
                yield str(id), name
Exemplo n.º 26
0
    def get(self):
        users = User.query.filter(User.is_active==True)\
                          .filter(User.is_not_client())\
                          .filter(User.freelancer==False)\
                          .order_by(User.name).all()
        freelancers = User.query.filter(User.is_active==True)\
                                .filter(User.is_not_client())\
                                .filter(User.freelancer==True)\
                                .order_by(User.name).all()

        clients = []
        if self.request.has_perm('admin'):
            clients = User.query.filter(User.is_active==True)\
                                .filter(User.is_client())\
                                .order_by(User.name).all()


        return dict(
            users=users,
            freelancers=freelancers,
            clients=clients,
        )
Exemplo n.º 27
0
    def _annually_report(self, year):
        year_start = datetime.date(year, 1, 1)
        year_end = datetime.date(year, 12, 31)
        excuses_error = None
        config_obj = ApplicationConfig.get_current_config()
        query = DBSession.query('uid', 'date', 'presence').from_statement("""
        SELECT p.user_id as "uid",
               date_trunc('day', p.ts) as "date",
               MIN(p.ts) as "presence"
        FROM presence_entry p
        WHERE p.ts >= :year_start AND
              p.ts <= :year_end
        GROUP BY p.user_id, date_trunc('day', p.ts)
        """).params(year_start=year_start, year_end=year_end)
        data = query.all()
        users = User.query.filter(User.is_active==True)\
                          .filter(User.is_not_client())\
                          .filter(User.is_not_freelancer())\
                          .order_by(User.name).all()

        _excuses = excuses.presence()


        data = self._group_by_user_monthly(data, _excuses)
        stats = self._prepare_statistics(data)

        return dict(
            data=data,
            users=users,
            stats=stats,

            today=datetime.datetime.today(),
            year_start=year_start,
            deltazero=deltazero,
            late_limit=config_obj.monthly_late_limit,
            excuses_error=excuses_error,
        )
Exemplo n.º 28
0
    def get(self):
        month_start, month_end = self._get_month()

        entries = self.session.query('user_id', 'date', 'time', 'late_count').from_statement("""
        SELECT t.user_id as "user_id", t.date as "date", (
            SELECT COALESCE(SUM(h.time), 0.0) FROM
            time_entry h
            WHERE h.user_id = t.user_id
            AND h.date = t.date
            AND h.deleted = FALSE
        ) as "time", (
            SELECT COUNT(*)
            FROM time_entry s
            WHERE s.user_id = t.user_id
            AND s.date = t.date
            AND DATE(s.modified_ts) > s.date
        ) as "late_count"
        FROM time_entry t
        WHERE t.date >= :month_start
          AND t.date <= :month_end
        GROUP BY t.user_id, t.date;
        """).params(month_start=month_start, month_end=month_end)
        if not self.request.has_perm('view'):
            users = [self.request.user] # TODO do we need to constrain entries also?
            locations= {
                self.request.user.location: ('', 1)
            }
        else:
            users_w = User.query.filter(User.is_not_client()) \
                                .filter(User.is_active==True) \
                                .filter(User.location=='wroclaw') \
                                .order_by(User.freelancer, User.name) \
                                .all()
            users_p = User.query.filter(User.is_not_client()) \
                                .filter(User.is_active==True) \
                                .filter(User.location=='poznan') \
                                .order_by(User.freelancer, User.name) \
                                .all()
            locations = {
                'wroclaw': [u'Wrocław', len(users_w)],
                'poznan': [u'Poznań', len(users_p)],
            }
            locations[self.request.user.location][1] -= 1
            if self.request.user.location == 'wroclaw':
                users = users_w
                users.extend(users_p)
            else:
                users = users_p
                users.extend(users_w)

        today = datetime.date.today()
        grouped = defaultdict(lambda: defaultdict(lambda: 0.0))
        late = defaultdict(lambda: defaultdict(lambda: False))
        sums = defaultdict(lambda: 0.0)
        daily_sums = defaultdict(lambda: 0.0)
        for user_id, date, time, late_count in entries:
            grouped[user_id][date] = time
            if date <= today:
                sums[user_id] += time
                daily_sums[date] += time
            late[user_id][date] = late_count > 0

        holidays = Holiday.all()
        count_of_required_month_hours = {}
        count_of_required_hours_to_today = {}

        for user in users:
            sftw = user.start_full_time_work or datetime.date(1970, 1, 1)

            if sftw > month_end:
                start_work = datetime.date(today.year+10, 1, 1)
            elif sftw < month_start:
                start_work = month_start
            else:
                start_work = sftw

            count_of_required_month_hours[user.id] = h.get_working_days(start_work, month_end) * 8
            count_of_required_hours_to_today[user.id] = h.get_working_days(start_work, today if today < month_end else month_end) * 8

        # move current user to the front of the list
        current_user_index = None
        for i, user in enumerate(users):
            if user.id == self.request.user.id:
                current_user_index = i

        users.insert(0, users.pop(current_user_index))

        return dict(
            entries=grouped, users=users, sums=sums, late=late, excuses=excuses.wrongtime(),
            daily_sums=daily_sums, monthly_sum=sum(daily_sums.values()),
            dates=__builtin__.list(dates_between(month_start, month_end)),
            is_holiday=lambda date: Holiday.is_holiday(date, holidays=holidays),
            month_start=month_start,
            prev_date=previous_month(month_start),
            next_date=next_month(month_start),
            today=today,
            count_of_required_month_hours=count_of_required_month_hours,
            count_of_required_hours_to_today=count_of_required_hours_to_today,
            locations=locations,
        )
Exemplo n.º 29
0
def callback(request):
    code = request.params.get('code', '')
    try:
        credentials = flow.step2_exchange(code)
    except FlowExchangeError:
        raise HTTPForbidden
    data = requests.get(USER_INFO_URI % credentials.access_token, verify=False)
    google_profile = data.json

    email = google_profile['email']

    EXTRA_EMAILS = request.registry.settings.get('GOOGLE_EXTRA_EMAILS',
                                                 '').split('\n')
    config = ApplicationConfig.get_current_config(allow_empty=True)
    freelancers = config.get_freelancers()
    clients_emails = Client.get_emails()
    if email.endswith('@%s' % request.registry.settings['COMPANY_DOMAIN']
                      ) or email in EXTRA_EMAILS:
        group = 'user'
    elif email in freelancers:
        group = 'freelancer'
    elif email in clients_emails:
        group = 'client'
    else:
        WARN_LOG(
            u"Forbidden acccess for profile:\n%s\n client's emails:\n%s\nfreelancer's emails:\n%s"
            % (google_profile, clients_emails, freelancers))
        return HTTPForbidden()

    session = request.db_session
    user = session.query(User).filter(User.email == email).first()
    if user is not None:
        if credentials.refresh_token:
            DEBUG(u'Adding refresh token %s for user %s' % (
                credentials.refresh_token,
                user.name,
            ))
            user.refresh_token = credentials.refresh_token
            session.add(user)
        DEBUG(u'Signing in existing user %s' % (user.name, ))
    else:
        LOG(u'Creating new user with name %s and email %s, group: %s' %
            (google_profile['name'], google_profile['email'], group))
        user = User(
            name=google_profile['name'],
            email=email,
            refresh_token=credentials.refresh_token or '',
            groups=[group],
        )

        session.add(user)
        session.flush()
    headers = remember(request, user.id)
    DEBUG(u'User %s set' % user.name)
    if group == 'client':
        location = request.url_for('/scrum/sprint/list')
    else:
        location = '/'
    return HTTPFound(
        location=location,
        headers=headers,
    )
Exemplo n.º 30
0
    def get(self):
        # Requested (or current) year
        year = self.request.GET.get('year')
        year = int(year) if year else datetime.date.today().year
        # Year start day and end day
        start = datetime.date(year, 1, 1)
        end = datetime.date(year, 12, 31)
        start_day = dict(
            day=start.day,
            dow=start.weekday(),
        )

        day_count, date_range, months = self.necessary_data(start, end)
        holidays = Holiday.query \
                          .filter(Holiday.date >= start) \
                          .all()

        # Users
        users_p = User.query.filter(User.is_not_client()) \
                            .filter(User.is_active==True) \
                            .filter(User.location=='poznan') \
                            .order_by(User.freelancer, User.name).all()
        users_w = User.query.filter(User.is_not_client()) \
                            .filter(User.is_active==True) \
                            .filter(User.location=='wroclaw') \
                            .order_by(User.freelancer, User.name).all()

        user_groups = [
            (u'Poznań', len(users_p)),
            (u'Wrocław', len(users_w)),
        ]

        reverse = False
        if self.request.user.location == 'wroclaw':
            user_groups.insert(0, user_groups.pop())
            reverse = True

        users_p.extend(users_w)

        # Leaves
        leave_mandated = Leave.get_for_year(start.year)
        leave_used = Leave.get_used_for_year(start.year)

        # Transform users to dictionary, group by city and order by leave days
        users = [
            dict(
                id=str(u.id),
                name=u.name,
                leave_mandated=leave_mandated[u.id][0],
                leave_used=leave_used[u.id],
                location=u.location,
            ) for u in users_p
        ]

        employees, students = [], []
        for user in users:
            if user['leave_mandated'] > 0:
                employees.append(user)
            else:
                students.append(user)

        users = employees + students
        # groupby location
        users = sorted(users, key=lambda u: u['location'], reverse=reverse)

        absences, absences_months = self.get_absences(start, end, users)
        lates = self.get_lates(start, end)
        absences_sum = (
            reduce(lambda s, u: s + u['leave_used'], users, 0),
            reduce(lambda s, u: s + u['leave_mandated'], users, 0),
        )

        data = {
            'users': users,
            'userGroups': user_groups,
            'year': start.year,
            'startDay': start_day,
            'dayCount': day_count,
            'months': months,
            'absences': absences,
            'absencesSum': absences_sum,
            'absencesMonths': absences_months,
            'lates': lates,
            'holidays': [h.date.strftime('%Y-%m-%d') for h in holidays],
        }

        return dict(
            data=json.dumps(data, ensure_ascii=False),
            year=start.year,
            v=self,
        )
Exemplo n.º 31
0
    def get(self):
        # Requested (or current) year
        year = self.request.GET.get('year')
        year = int(year) if year else datetime.date.today().year
        # Year start day and end day
        start = datetime.date(year, 1, 1)
        end = datetime.date(year, 12, 31)
        start_day = dict(
            day=start.day,
            dow=start.weekday(),
        )

        day_count, date_range, months = self.necessary_data(start, end)
        holidays = Holiday.query \
                          .filter(Holiday.date >= start) \
                          .all()

        # Users
        users = []
        user_groups = []
        for name, (fullname, shortcut) in self.request.user.get_locations():
            usersq = User.query.filter(User.is_not_client()) \
                               .filter(User.is_active==True) \
                               .filter(User.location==name) \
                               .order_by(User.is_freelancer(), User.name).all()
            users.extend(usersq)
            user_groups.append((fullname, len(usersq)))

        # Leaves
        leave_mandated = Leave.get_for_year(start.year)
        leave_used = Leave.get_used_for_year(start.year)

        # Transform users to dictionary, group by city and order by leave days
        users = [
            dict(
                id=str(u.id),
                name=u.name,
                leave_mandated=leave_mandated[u.id][0],
                leave_used=leave_used[u.id],
                location=u.location,
            ) for u in users
        ]

        users = sorted(
            users,
            key=lambda u: u['location'],
        )

        user_groups = sorted(
            user_groups,
            key=lambda u: u,
        )

        absences, absences_months = self.get_absences(start, end, users)
        lates = self.get_lates(start, end)
        absences_sum = (
            reduce(lambda s, u: s + u['leave_used'], users, 0),
            reduce(lambda s, u: s + u['leave_mandated'], users, 0),
        )

        data = {
            'users': users,
            'userGroups': user_groups,
            'year': start.year,
            'startDay': start_day,
            'dayCount': day_count,
            'months': months,
            'absences': absences,
            'absencesSum': absences_sum,
            'absencesMonths': absences_months,
            'lates': lates,
            'holidays': [h.date.strftime('%Y-%m-%d') for h in holidays],
        }

        return dict(
            data=json.dumps(data, ensure_ascii=False),
            year=start.year,
            v=self,
        )
Exemplo n.º 32
0
 def resolve_user(self, orig_login):
     login = orig_login.lower()
     if login in self.login_mapping:
         return self.login_mapping[login]
     else:
         return User(name=orig_login, email=orig_login)
Exemplo n.º 33
0
    def get(self):
        month_start, month_end = self._get_month()

        entries = (
            DBSession.query("user_id", "date", "time", "late_count")
            .from_statement(
                """
        SELECT t.user_id as "user_id", t.date as "date", (
            SELECT COALESCE(SUM(h.time), 0.0) FROM
            time_entry h
            WHERE h.user_id = t.user_id
            AND h.date = t.date
            AND h.deleted = FALSE
        ) as "time", (
            SELECT COUNT(*)
            FROM time_entry s
            WHERE s.user_id = t.user_id
            AND s.date = t.date
            AND DATE(s.modified_ts) > s.date
        ) as "late_count"
        FROM time_entry t
        WHERE t.date >= :month_start
          AND t.date <= :month_end
        GROUP BY t.user_id, t.date;
        """
            )
            .params(month_start=month_start, month_end=month_end)
        )

        if not self.request.has_perm("can_see_users_times"):
            users = [self.request.user]  # TODO do we need to constrain entries also?
            locations = {self.request.user.location: ("", 1)}
        else:
            location_names = self.request.user.get_locations()

            users = {}
            for name, (fullname, shortcut) in location_names:
                usersq = (
                    User.query.filter(User.is_not_client())
                    .filter(User.is_active == True)
                    .filter(User.location == name)
                    .order_by(User.is_freelancer(), User.name)
                )
                users[name] = usersq.all()

            locations = {name: [User.LOCATIONS[name][0], len(users)] for name, users in users.iteritems()}

            locations[self.request.user.location][1] -= 1

            ordered_users = []
            for name, (fullname, shortcut) in location_names:
                ordered_users.extend(users[name])

            users = ordered_users

        # move current user to the front of the list
        current_user_index = None
        for i, user in enumerate(users):
            if user.id == self.request.user.id:
                current_user_index = i

        users.insert(0, users.pop(current_user_index))

        today = datetime.date.today()
        grouped = defaultdict(lambda: defaultdict(lambda: 0.0))
        late = defaultdict(lambda: defaultdict(lambda: False))
        sums = defaultdict(lambda: 0.0)
        daily_sums = defaultdict(lambda: 0.0)
        for user_id, date, time, late_count in entries:
            grouped[user_id][date] = time
            if date <= today:
                sums[user_id] += time
                daily_sums[date] += time
            late[user_id][date] = late_count > 0

        holidays = Holiday.all()
        count_of_required_month_hours = {}
        count_of_required_hours_to_today = {}

        for user in users:
            sftw = user.start_full_time_work
            if sftw:
                if sftw > month_end:
                    start_work = datetime.date(today.year + 10, 1, 1)
                elif sftw < month_start:
                    start_work = month_start
                else:
                    start_work = sftw

                month_hours = h.get_working_days(start_work, month_end) * 8

                today_ = today if today < month_end else month_end
                hours_to_today = h.get_working_days(start_work, today_) * 8

                count_of_required_month_hours[user.id] = month_hours
                count_of_required_hours_to_today[user.id] = hours_to_today
            else:
                count_of_required_month_hours[user.id] = 0
                count_of_required_hours_to_today[user.id] = 0

        return dict(
            entries=grouped,
            users=users,
            sums=sums,
            late=late,
            excuses=excuses.wrongtime(),
            daily_sums=daily_sums,
            monthly_sum=sum(daily_sums.values()),
            dates=__builtin__.list(dates_between(month_start, month_end)),
            is_holiday=lambda date: Holiday.is_holiday(date, holidays=holidays),
            month_start=month_start,
            prev_date=previous_month(month_start),
            next_date=next_month(month_start),
            today=today,
            count_of_required_month_hours=count_of_required_month_hours,
            count_of_required_hours_to_today=count_of_required_hours_to_today,
            locations=locations,
        )
Exemplo n.º 34
0
    def get(self):
        # Requested (or current) year
        year = self.request.GET.get('year')
        year = int(year) if year else datetime.date.today().year
        # Year start day and end day
        start = datetime.date(year, 1, 1)
        end = datetime.date(year, 12, 31)
        start_day = dict(
            day=start.day,
            dow=start.weekday(),
        )

        day_count, date_range, months = self.necessary_data(start, end)
        holidays = Holiday.query \
                          .filter(Holiday.date >= start) \
                          .all()

        # Users
        users_p = User.query.filter(User.is_not_client()) \
                            .filter(User.is_active==True) \
                            .filter(User.location=='poznan') \
                            .order_by(User.freelancer, User.name).all()
        users_w = User.query.filter(User.is_not_client()) \
                            .filter(User.is_active==True) \
                            .filter(User.location=='wroclaw') \
                            .order_by(User.freelancer, User.name).all()
        
        user_groups = [
            (u'Poznań', len(users_p)),
            (u'Wrocław', len(users_w)),
        ]
        
        reverse = False
        if self.request.user.location == 'wroclaw':
            user_groups.insert(0, user_groups.pop())
            reverse = True

        users_p.extend(users_w) 

        # Leaves
        leave_mandated = Leave.get_for_year(start.year)
        leave_used = Leave.get_used_for_year(start.year)

        # Transform users to dictionary, group by city and order by leave days
        users = [dict(
                      id=str(u.id),
                      name=u.name,
                      leave_mandated=leave_mandated[u.id][0],
                      leave_used=leave_used[u.id],
                      location=u.location,
                     ) for u in users_p]
        
        
        employees, students = [], []
        for user in users:
            if user['leave_mandated'] > 0:
                employees.append(user)
            else:
                students.append(user)
        
        users = employees + students
        # groupby location
        users = sorted(
            users,
            key=lambda u: u['location'],
            reverse=reverse
        )
        
        absences, absences_months = self.get_absences(start, end, users)
        lates = self.get_lates(start, end)
        absences_sum = (
            reduce(lambda s, u: s + u['leave_used'], users, 0),
            reduce(lambda s, u: s + u['leave_mandated'], users, 0),
        )

        data = {
            'users': users,
            'userGroups': user_groups,
            'year': start.year,
            'startDay': start_day,
            'dayCount': day_count,
            'months': months,
            'absences': absences,
            'absencesSum': absences_sum,
            'absencesMonths': absences_months,
            'lates': lates,
            'holidays': [h.date.strftime('%Y-%m-%d') for h in holidays],
        }

        return dict(
            data=json.dumps(data, ensure_ascii=False),
            year=start.year,
            v=self,
        )
Exemplo n.º 35
0
 def _resolve_user(self, orig_login, login_mapping):
     return login_mapping.get(
         orig_login.lower(),
         User(name=orig_login, email=orig_login),
     )
Exemplo n.º 36
0
    def get(self):
        # Requested (or current) year
        year = self.request.GET.get('year')
        year = int(year) if year else datetime.date.today().year
        # Year start day and end day
        start = datetime.date(year, 1, 1)
        end = datetime.date(year, 12, 31)
        start_day = dict(
            day=start.day,
            dow=start.weekday(),
        )

        day_count, date_range, months = self.necessary_data(start, end)
        holidays = Holiday.query \
                          .filter(Holiday.date >= start) \
                          .all()

        # Users
        users = []
        user_groups = []
        for name, (fullname, shortcut) in self.request.user.get_locations():
            usersq = User.query.filter(User.is_not_client()) \
                               .filter(User.is_active==True) \
                               .filter(User.location==name) \
                               .order_by(User.is_freelancer(), User.name).all()
            users.extend(usersq)
            user_groups.append((fullname, len(usersq)))

        # Leaves
        leave_mandated = Leave.get_for_year(start.year)
        leave_used = Leave.get_used_for_year(start.year)

        # Transform users to dictionary, group by city and order by leave days
        users = [dict(
            id=str(u.id),
            name=u.name,
            leave_mandated=leave_mandated[u.id][0],
            leave_used=leave_used[u.id],
            location=u.location,
        ) for u in users]

        users = sorted(
            users,
            key=lambda u: u['location'],
        )

        user_groups = sorted(
            user_groups,
            key=lambda u: u,
        )

        absences, absences_months = self.get_absences(start, end, users)
        lates = self.get_lates(start, end)
        absences_sum = (
            reduce(lambda s, u: s + u['leave_used'], users, 0),
            reduce(lambda s, u: s + u['leave_mandated'], users, 0),
        )

        data = {
            'users': users,
            'userGroups': user_groups,
            'year': start.year,
            'startDay': start_day,
            'dayCount': day_count,
            'months': months,
            'absences': absences,
            'absencesSum': absences_sum,
            'absencesMonths': absences_months,
            'lates': lates,
            'holidays': [h.date.strftime('%Y-%m-%d') for h in holidays],
        }

        return dict(
            data=json.dumps(data, ensure_ascii=False),
            year=start.year,
            v=self,
        )