Example #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
Example #2
0
def overtime(request, who=None, year=None):
    auth_user = Tbluser.objects.get(
        id=request.session.get('user_id')
        )
    if not year:
        year = str(datetime.datetime.now().year)
    if not who:
        try:
            userid = auth_user.get_subordinates()[0].id
            return HttpResponseRedirect("/overtime/%s/%s/" % (userid, year))
        except (tblauth.DoesNotExist, IndexError):
            return HttpResponseRedirect("/user_edit/")

    # stop people from editing the URL to access agents outside their
    # span of control.
    try:
        target_user = auth_user.get_subordinates().get(id=who)
    except Tbluser.DoesNotExist:
        raise Http404

    # generate our year table.
    ot_table = target_user.overtime_view(year)
    # interpolate our values into it.
    ot_table = ot_table.format(employees_select=generate_employee_box(auth_user),
                               yearbox=generate_year_box(int(year), id="cmb_yearbox"),
                               c="EMPTY",
                               function="")
    return render_to_response("overtime.html",
                              {"ot_table": ot_table,
                               "year": year,
                               "eeid": who,
                               }, RequestContext(request))
Example #3
0
def overtime(request, who=None, year=None):
    auth_user = Tbluser.objects.get(id=request.session.get('user_id'))
    if not year:
        year = str(datetime.datetime.now().year)
    if not who:
        try:
            userid = auth_user.get_subordinates()[0].id
            return HttpResponseRedirect("/overtime/%s/%s/" % (userid, year))
        except (tblauth.DoesNotExist, IndexError):
            return HttpResponseRedirect("/user_edit/")

    # stop people from editing the URL to access agents outside their
    # span of control.
    try:
        target_user = auth_user.get_subordinates().get(id=who)
    except Tbluser.DoesNotExist:
        raise Http404

    # generate our year table.
    ot_table = target_user.overtime_view(year)
    # interpolate our values into it.
    ot_table = ot_table.format(
        employees_select=generate_employee_box(auth_user),
        yearbox=generate_year_box(int(year), id="cmb_yearbox"),
        c="EMPTY",
        function="")
    return render_to_response("overtime.html", {
        "ot_table": ot_table,
        "year": year,
        "eeid": who,
    }, RequestContext(request))
Example #4
0
    def yearview(self, year):
        '''
        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`
        '''
        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])
        table_string += '''
<tr>
  <td colspan=100>
    <table>
      <tr><th style="width:10%%">Year</th><td style="width:90%%">%s</td></tr>
      <tr><th>Agent</th><td>{employees_select}</td></tr>
      <tr>
        <th style="width:10%%">Comments</th>
        <td style="width:90%%">
          <ul>%s</ul>
        </td>
      </tr>
      <tr>
        <th>Total Balances</th>
        <td>
         <table>
          %s
         </table>
        </td>
      </tr>
    </table>
  </td>
</tr>
''' % (generate_year_box(int(year), id="cmb_yearbox"),
       ''.join(("<li>%s</li>" % entry) for entry in self.get_comments(year)),
       ''.join("<tr><th>%s</th><td>%s</td>"
               % (k, v) for k, v in sorted(self.get_balances(year).items()))
       )
        return '<table id="holiday-table"><th colspan=999>%s</th>' \
            % self.name() + table_string
Example #5
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