Beispiel #1
0
    def yearview(self, year): # pragma: no cover
        '''Generates the HTML table for the yearview page. It iterates
        through the entire set of tracking entries for a given year.

        :param year: The year in which the yearview should be generated from.
        :type year: :class:`int`
        :rtype :class:`str`
        '''
        cachestr = "yearview:%s%s" % (self.id, year)
        cached_result = cache.get(cachestr)
        if cached_result:
            cache_log.debug("Returning cache for: %s" % cachestr)
            return cached_result
        entries = TrackingEntry.objects.filter(user_id=self.id,
                                               entry_date__year=year)
        basehtml = self.year_as_whole(year)
        for entry in entries:
            basehtml[entry.entry_date.month-1][entry.entry_date.day] = \
                basehtml[entry.entry_date.month-1][entry.entry_date.day].format(
                c=entry.daytype, function="")
        table_string = ''.join([''.join(subrow) for subrow in basehtml])
        tmpl = get_template("fragments/yearview.html")
        ctx = Context({
            "yearbox": generate_year_box(int(year), id="cmb_yearbox"),
            "comments": self.get_comments(year),
            "balances": ((k, v) for k, v in sorted(self.get_balances(year).items())),
            })
        table_string += tmpl.render(ctx)
        result = '<table id="holiday-table"><th colspan=999>%s</th>' \
                 % self.name() + table_string
        cache_log.debug(
            "Setting cache for %s: %s" % (cachestr, cache.set(cachestr, result))
        )
        return result
Beispiel #2
0
    def get_holiday_balance(self, year):
        '''Calculates the holiday balance for the employee

        This method loops over all :class:`TrackingEntry` entries
        attached to the user instance which are in the year passed in,
        taking each entries day_type and looking that up in a value
        map.

        Values can be:

        1) Holiday: Remove a day
        2) Work on Public Holiday: Add two days
        3) Return for working Public Holiday: Remove a day
        4) Day on Demand: Remove a day
        5) Work on Saturday: Add a day


        :param year: The year in which the holiday balance should be
                     calculated from
        :type year: :class:`int`
        :rtype: :class:`Integer`

        '''
        cachestr = "holidaybalance:%s%s" % (self.id, year)
        cache_result = cache.get(cachestr)
        if cache_result: # pragma: no cover
            return int(cache_result)
        tracking_days = TrackingEntry.objects.filter(user_id=self.id,
                                                     entry_date__year=year)

        holiday_value_map = {
            'HOLIS': -1,
            'PUWRK': 2,
            'RETRN': -1,
            'DAYOD': -1,
            'SATUR': 1
            }

        holiday_balance = self.holiday_balance
        for entry in tracking_days:
            holiday_balance += holiday_value_map.get(entry.daytype, 0)
        cache_log.debug(
            "Setting cache for %s: %s" % (
                cachestr, cache.set(cachestr, str(holiday_balance))
            )
        )
        return holiday_balance
Beispiel #3
0
    def get_holiday_balance(self, year):
        '''Calculates the holiday balance for the employee

        This method loops over all :class:`TrackingEntry` entries
        attached to the user instance which are in the year passed in,
        taking each entries day_type and looking that up in a value
        map.

        Values can be:

        1) Holiday: Remove a day
        2) Work on Public Holiday: Add two days
        3) Return for working Public Holiday: Remove a day
        4) Day on Demand: Remove a day
        5) Work on Saturday: Add a day


        :param year: The year in which the holiday balance should be
                     calculated from
        :type year: :class:`int`
        :rtype: :class:`Integer`

        '''
        cachestr = "holidaybalance:%s%s" % (self.id, year)
        cache_result = cache.get(cachestr)
        if cache_result:  # pragma: no cover
            return int(cache_result)
        tracking_days = TrackingEntry.objects.filter(user_id=self.id,
                                                     entry_date__year=year)

        holiday_value_map = {
            'HOLIS': -1,
            'PUWRK': 2,
            'RETRN': -1,
            'DAYOD': -1,
            'SATUR': 1
        }

        holiday_balance = self.holiday_balance
        for entry in tracking_days:
            holiday_balance += holiday_value_map.get(entry.daytype, 0)
        cache_log.debug("Setting cache for %s: %s" %
                        (cachestr, cache.set(cachestr, str(holiday_balance))))
        return holiday_balance
Beispiel #4
0
    def overtime_view(self, year):
        '''Generates the HTML table for the overtime_view page. It iterates
        through the entire set of tracking entries for a given year.

        :param year: The year in which the overtime should be generated from.
        :type year: :class:`int`
        :rtype :class:`str`

        '''
        cachestr = "overtime_view:%s%s" % (self.id, year)
        cached_result = cache.get(cachestr)
        if cached_result:
            cache_log.debug("Returning cache for: %s" % cachestr)
            return cached_result
        entries = TrackingEntry.objects.filter(user_id=self.id,
                                               entry_date__year=year)
        basehtml = self.year_as_whole(year)
        for entry in entries:  # pragma: no cover
            basehtml[entry.entry_date.month-1][entry.entry_date.day] = \
                basehtml[entry.entry_date.month-1][entry.entry_date.day].format(
                c=entry.overtime_class(),
                function="entry_date='%s'" % entry.entry_date)
        table_string = ''.join([''.join(subrow) for subrow in basehtml])
        # TODO: Template this.
        table_string += '''
<tr>
  <td colspan=100>
    <table>
      <tr>
        <th style="width:10%%">Year</th><td style="width:90%%">{yearbox}</td>
      </tr>
      <tr><th>Agent</th><td>{employees_select}</td></tr>
    </table>
  </td>
</tr>
'''
        result = '<table id="holiday-table"><th colspan=999>%s</th>' \
            % self.name() + table_string
        cache.set(cachestr, result)
        return result
Beispiel #5
0
    def overtime_view(self, year):
        '''Generates the HTML table for the overtime_view page. It iterates
        through the entire set of tracking entries for a given year.

        :param year: The year in which the overtime should be generated from.
        :type year: :class:`int`
        :rtype :class:`str`

        '''
        cachestr = "overtime_view:%s%s" % (self.id, year)
        cached_result = cache.get(cachestr)
        if cached_result:
            cache_log.debug("Returning cache for: %s" % cachestr)
            return cached_result
        entries = TrackingEntry.objects.filter(user_id=self.id,
                                               entry_date__year=year)
        basehtml = self.year_as_whole(year)
        for entry in entries: # pragma: no cover
            basehtml[entry.entry_date.month-1][entry.entry_date.day] = \
                basehtml[entry.entry_date.month-1][entry.entry_date.day].format(
                c=entry.overtime_class(),
                function="entry_date='%s'" % entry.entry_date)
        table_string = ''.join([''.join(subrow) for subrow in basehtml])
        # TODO: Template this.
        table_string += '''
<tr>
  <td colspan=100>
    <table>
      <tr>
        <th style="width:10%%">Year</th><td style="width:90%%">{yearbox}</td>
      </tr>
      <tr><th>Agent</th><td>{employees_select}</td></tr>
    </table>
  </td>
</tr>
'''
        result = '<table id="holiday-table"><th colspan=999>%s</th>' \
            % self.name() + table_string
        cache.set(cachestr, result)
        return result
Beispiel #6
0
    def yearview(self, year):  # pragma: no cover
        '''Generates the HTML table for the yearview page. It iterates
        through the entire set of tracking entries for a given year.

        :param year: The year in which the yearview should be generated from.
        :type year: :class:`int`
        :rtype :class:`str`
        '''
        cachestr = "yearview:%s%s" % (self.id, year)
        cached_result = cache.get(cachestr)
        if cached_result:
            cache_log.debug("Returning cache for: %s" % cachestr)
            return cached_result
        entries = TrackingEntry.objects.filter(user_id=self.id,
                                               entry_date__year=year)
        basehtml = self.year_as_whole(year)
        for entry in entries:
            basehtml[entry.entry_date.month-1][entry.entry_date.day] = \
                basehtml[entry.entry_date.month-1][entry.entry_date.day].format(
                c=entry.daytype, function="")
        table_string = ''.join([''.join(subrow) for subrow in basehtml])
        tmpl = get_template("fragments/yearview.html")
        ctx = Context({
            "yearbox":
            generate_year_box(int(year), id="cmb_yearbox"),
            "comments":
            self.get_comments(year),
            "balances":
            ((k, v) for k, v in sorted(self.get_balances(year).items())),
        })
        table_string += tmpl.render(ctx)
        result = '<table id="holiday-table"><th colspan=999>%s</th>' \
                 % self.name() + table_string
        cache_log.debug("Setting cache for %s: %s" %
                        (cachestr, cache.set(cachestr, result)))
        return result