Beispiel #1
0
    def get(self):
        date_str = self.request.GET.get('date')
        date = datetime.datetime.strptime(date_str, '%d.%m.%Y')
        user_id = self.request.GET.get('user_id')
        if self.request.user.id == int(user_id):
            return HTTPFound(self.request.url_for('/times/list', date=date_str))

        if not self.request.has_perm('view') and user_id != self.request.user.id:
            return HTTPForbidden()

        user = User.query.get(user_id)
        if user is None:
            return HTTPNotFound()

        entries = self._get_time_entries(date, user_id)
        form = TimeEntryForm()

        total_sum = sum(entry.time for (tracker, entry) in entries if not entry.deleted)

        return dict(
            date=date, form=form,
            entries=entries,
            user=user,
            prev_date=previous_day(date), next_date=next_day(date),
            total_sum=total_sum,
            can_modify=self.request.has_perm('admin'),
        )
Beispiel #2
0
    def get(self):
        date = datetime.datetime.strptime(self.request.GET.get('date'), '%d.%m.%Y')
        start_date = datetime.datetime.combine(date, day_start)
        end_date = datetime.datetime.combine(date, day_end)
        entries_p = self.session.query(User.id, User.name, func.min(PresenceEntry.ts), func.max(PresenceEntry.ts))\
                              .filter(User.id==PresenceEntry.user_id)\
                              .filter((User.location=="poznan") | (User.location==None))\
                              .filter(PresenceEntry.ts>=start_date)\
                              .filter(PresenceEntry.ts<=end_date)\
                              .group_by(User.id, User.name)\
                              .order_by(User.name)

        entries_w = self.session.query(User.id, User.name, func.min(PresenceEntry.ts), func.max(PresenceEntry.ts))\
                              .filter(User.id==PresenceEntry.user_id)\
                              .filter(User.location=="wroclaw")\
                              .filter(PresenceEntry.ts>=start_date)\
                              .filter(PresenceEntry.ts<=end_date)\
                              .group_by(User.id, User.name)\
                              .order_by(User.name)

        return dict(
            entries_p=((user_id, user_name, start, stop, start.time() > hour_9) for (user_id, user_name, start, stop) in entries_p),
            entries_w=((user_id, user_name, start, stop, start.time() > hour_9) for (user_id, user_name, start, stop) in entries_w),
            date=date,
            prev_date=previous_day(date),
            next_date=next_day(date),
            excuses=excuses.presence(),
            justification=excuses.presence_status(date, self.request.user.id),
        )
Beispiel #3
0
    def get(self):
        date_str = self.request.GET.get('date')
        date = datetime.datetime.strptime(date_str, '%d.%m.%Y')
        user_id = self.request.GET.get('user_id')
        if self.request.user.id == int(user_id):
            return HTTPFound(self.request.url_for('/times/list',
                                                  date=date_str))

        user = User.query.get(user_id)
        if user is None:
            return HTTPNotFound()

        entries = self._get_time_entries(date, user_id)
        form = TimeEntryForm()

        total_sum = sum(entry.time for (tracker, entry) in entries
                        if not entry.deleted)

        return dict(
            date=date,
            form=form,
            entries=entries,
            user=user,
            prev_date=previous_day(date),
            next_date=next_day(date),
            total_sum=total_sum,
            can_modify=self.request.has_perm('can_edit_users_timeentry'),
        )
Beispiel #4
0
    def get(self):
        date_str = self.request.GET.get('date')
        date = datetime.datetime.strptime(date_str, '%d.%m.%Y')

        entries = self._get_time_entries(date)

        total_sum = sum(entry.time for (tracker, entry) in entries
                        if not entry.deleted)
        form = TimeEntryForm()

        needs_justification = False
        for tracker, timeentry in entries:
            if timeentry.modified_ts.date() > timeentry.date:
                needs_justification = True

        return dict(
            date=date,
            entries=entries,
            form=form,
            user=self.request.user,
            prev_date=previous_day(date),
            next_date=next_day(date),
            total_sum=total_sum,
            needs_justification=needs_justification,
            justification_status=excuses.wrongtime_status(
                date, self.request.user.id),
            can_modify=user_can_modify_timeentry(self.request.user, date),
        )
Beispiel #5
0
 def _get_month_days(self, start, end):
     """
     calculetes worked days (from begining of month to today, from today to end of month)
     """
     today = datetime.date.today()
     days_worked = h.get_working_days(start, h.previous_day(today))
     days_left = h.get_working_days(today, end)
     return days_worked, days_left
Beispiel #6
0
 def _get_month_days(self, start, end):
     """
     calculetes worked days (from begining of month to today, from today to end of month)
     """
     today = datetime.date.today()
     days_worked = h.get_working_days(start, h.previous_day(today))
     days_left = h.get_working_days(today, end)
     return days_worked, days_left
Beispiel #7
0
    def get(self):
        date = self.request.GET.get('date')
        if date:
            date = datetime.datetime.strptime(date, '%d.%m.%Y')
        else:
            date = datetime.date.today()
        start_date = datetime.datetime.combine(date, day_start)
        end_date = datetime.datetime.combine(date, day_end)

        def get_entries(city):
            if city in ['wroclaw', 'poznan']:
                return self.session.query(User.id, User.name, func.min(PresenceEntry.ts), func.max(PresenceEntry.ts))\
                              .filter(User.id == PresenceEntry.user_id)\
                              .filter((User.location == city) | (User.location == None))\
                              .filter(PresenceEntry.ts >= start_date)\
                              .filter(PresenceEntry.ts <= end_date)\
                              .group_by(User.id, User.name)\
                              .order_by(User.name)

        def get_lates(city):
            if city in ['wroclaw', 'poznan']:
                return self.session.query(User.id, User.name, Late.late_start, Late.late_end)\
                            .filter(User.id == Late.user_id)\
                            .filter(User.location == city)\
                            .filter(Late.date == date)\
                            .order_by(User.name)

        def get_absence(city):
            if city in ['wroclaw', 'poznan']:
                return self.session.query(User.id, User.name)\
                            .filter(User.id == Absence.user_id)\
                            .filter(User.location == city)\
                            .filter(Absence.date_start <= date)\
                            .filter(Absence.date_end >= date)\
                            .order_by(User.name)

        return dict(
            date=date,
            prev_date=h.previous_day(date),
            next_date=h.next_day(date),
            excuses=excuses.presence(),
            justification=excuses.presence_status(date, self.request.user.id),
            city=[
                dict(
                    name=u'Poznań',
                    entries=((user_id, user_name, start, stop, start.time() > hour_9) for (user_id, user_name, start, stop) in get_entries('poznan')),
                    late=get_lates('poznan'),
                    absence=get_absence('poznan'),
                ),
                dict(
                    name=u'Wrocław',
                    entries=((user_id, user_name, start, stop, start.time() > hour_9) for (user_id, user_name, start, stop) in get_entries('wroclaw')),
                    late=get_lates('wroclaw'),
                    absence=get_absence('wroclaw'),
                 ),
            ],
        )
Beispiel #8
0
    def get(self):
        date = self.request.GET.get('date')
        if date:
            date = datetime.datetime.strptime(date, '%d.%m.%Y')
        else:
            date = datetime.date.today()
        start_date = datetime.datetime.combine(date, day_start)
        end_date = datetime.datetime.combine(date, day_end)

        def get_entries(city):
            return DBSession.query(User.id, User.name, func.min(PresenceEntry.ts), func.max(PresenceEntry.ts))\
                          .filter(User.id == PresenceEntry.user_id)\
                          .filter((User.location == city) | (User.location == None))\
                          .filter(PresenceEntry.ts >= start_date)\
                          .filter(PresenceEntry.ts <= end_date)\
                          .group_by(User.id, User.name)\
                          .order_by(User.name)

        def get_lates(city):
            return DBSession.query(User.id, User.name, Late.late_start, Late.late_end)\
                        .filter(User.id == Late.user_id)\
                        .filter(User.location == city)\
                        .filter(Late.date == date)\
                        .order_by(User.name)

        def get_absence(city):
            return DBSession.query(User.id, User.name)\
                        .filter(User.id == Absence.user_id)\
                        .filter(User.location == city)\
                        .filter(Absence.date_start <= date)\
                        .filter(Absence.date_end >= date)\
                        .order_by(User.name)

        locations = []
        for name, (fullname, shortcut) in self.request.user.get_locations():
            presences = dict(
                shortcut=shortcut,
                name=fullname,
                entries=((user_id, user_name, start, stop,
                          start.time() > hour_9)
                         for (user_id, user_name, start,
                              stop) in get_entries(name)),
                late=get_lates(name),
                absence=get_absence(name),
            )
            locations.append(presences)

        return dict(
            date=date,
            prev_date=h.previous_day(date),
            next_date=h.next_day(date),
            excuses=excuses.presence(),
            justification=excuses.presence_status(date, self.request.user.id),
            locations=locations,
        )
Beispiel #9
0
 def pending(self):
     """ returns a list of pending entries """
     result = []
     yesterday = previous_day(datetime.date.today())
     cron_url = config['CRON_URL']
     with PickleStore(self.file_path) as store:
         for date, action_name in store.get_pending(yesterday,
                                                    self.actions.keys()):
             result.append(
                 ('%s%s' % (cron_url, self.actions[action_name](date)),
                  partial(self.update, date, action_name)))
     return result
Beispiel #10
0
 def pending(self):
     """ returns a list of pending entries """
     result = []
     yesterday = previous_day(datetime.date.today())
     cron_url = config['CRON_URL']
     with PickleStore(self.file_path) as store:
         for date, action_name in store.get_pending(yesterday, self.actions.keys()):
             result.append(
                     ('%s%s' % (cron_url, self.actions[action_name](date)),
                      partial(self.update, date, action_name))
             )
     return result
Beispiel #11
0
    def get(self):
        date = self.request.GET.get('date')
        if date:
            date = datetime.datetime.strptime(date, '%d.%m.%Y')
        else:
            date = datetime.date.today()
        start_date = datetime.datetime.combine(date, day_start)
        end_date = datetime.datetime.combine(date, day_end)

        def get_entries(city):
            return DBSession.query(User.id, User.name, func.min(PresenceEntry.ts), func.max(PresenceEntry.ts))\
                          .filter(User.id == PresenceEntry.user_id)\
                          .filter((User.location == city) | (User.location == None))\
                          .filter(PresenceEntry.ts >= start_date)\
                          .filter(PresenceEntry.ts <= end_date)\
                          .group_by(User.id, User.name)\
                          .order_by(User.name)

        def get_lates(city):
            return DBSession.query(User.id, User.name, Late.late_start, Late.late_end)\
                        .filter(User.id == Late.user_id)\
                        .filter(User.location == city)\
                        .filter(Late.date == date)\
                        .order_by(User.name)

        def get_absence(city):
            return DBSession.query(User.id, User.name)\
                        .filter(User.id == Absence.user_id)\
                        .filter(User.location == city)\
                        .filter(Absence.date_start <= date)\
                        .filter(Absence.date_end >= date)\
                        .order_by(User.name)

        locations = []
        for name, (fullname, shortcut) in self.request.user.get_locations():
            presences = dict(
                shortcut=shortcut,
                name=fullname,
                entries=((user_id, user_name, start, stop, start.time() > hour_9) for (user_id, user_name, start, stop) in get_entries(name)),
                late=get_lates(name),
                absence=get_absence(name),
            )
            locations.append(presences)

        return dict(
            date=date,
            prev_date=h.previous_day(date),
            next_date=h.next_day(date),
            excuses=excuses.presence(),
            justification=excuses.presence_status(date, self.request.user.id),
            locations=locations,
        )
Beispiel #12
0
    def get(self):
        date = datetime.datetime.strptime(self.request.GET.get('date'), '%d.%m.%Y')

        start_date = datetime.datetime.combine(date, day_start)
        end_date = datetime.datetime.combine(date, day_end)
        entries = self.session.query(User, PresenceEntry)\
                              .filter(PresenceEntry.user_id==User.id)\
                              .filter(PresenceEntry.ts>=start_date)\
                              .filter(PresenceEntry.ts<=end_date)\
                              .order_by(PresenceEntry.ts)
        return dict(
            entries=entries,
            date=date,
            prev_date=previous_day(date), next_date=next_day(date)
        )
Beispiel #13
0
    def get(self):
        date = self.request.GET.get("date")
        if date:
            date = datetime.datetime.strptime(date, "%d.%m.%Y")
        else:
            date = datetime.date.today()

        start_date = datetime.datetime.combine(date, day_start)
        end_date = datetime.datetime.combine(date, day_end)
        entries = (
            DBSession.query(User, PresenceEntry)
            .filter(PresenceEntry.user_id == User.id)
            .filter(PresenceEntry.ts >= start_date)
            .filter(PresenceEntry.ts <= end_date)
            .order_by(PresenceEntry.ts)
        )
        return dict(entries=entries, date=date, prev_date=h.previous_day(date), next_date=h.next_day(date))
Beispiel #14
0
    def get(self):
        date_str = self.request.GET.get('date')
        date = datetime.datetime.strptime(date_str, '%d.%m.%Y')

        entries = self._get_time_entries(date)

        total_sum = sum(entry.time for (tracker, entry) in entries if not entry.deleted)
        form = TimeEntryForm()

        needs_justification = False
        for tracker, timeentry in entries:
            if timeentry.modified_ts.date() > timeentry.date:
                needs_justification = True

        return dict(
            date=date, entries=entries, form=form,
            user=self.request.user,
            prev_date=previous_day(date), next_date=next_day(date),
            total_sum=total_sum,
            needs_justification=needs_justification,
            justification_status=excuses.wrongtime_status(date, self.request.user.id),
            can_modify=user_can_modify_timeentry(self.request.user, date),
        )