Roundup Tracker

Following code was sent to me by Marcus Priesch. I modified it for Roundup 0.8. I am assuming you have added a Date field called 'deadline' to your 'issue' class.

This customization is structured as follows: A file called '_generic.calendar.html' in the 'html' folder of your tracker home, a file called 'datehelp.py' in the 'extensions' folder of your tracker home, and code to display the link in your item template.

To display the link for the DateHelp in your item template use following tag: '<span tal:content="structure python:utils.date_help(request, context.deadline)"/>' Put the tag in your 'issue.item.html' template.

The 'utils.date_help' call has following arguments:

- *request*: The request object. Just leave this.

- *item*: The name of the property you wish to modify. Should probably be of the form 'context.property'

- *width*: (optional) The width of the popup window, default=300

- *height*: (optional) The height of the popup window, default=200

- *label*: (optional) The link text to display, default="(cal)"

- *form*: (optional) The form to write the selected date back to, default="itemSynopsis"

In the html folder of your tracker home add a file called '_generic.calendar.html' with following contents::

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
     <head>
      <link rel="stylesheet" type="text/css" href="@@file/style.css" />
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8;" />
      <title tal:content="string:Roundup Calendar"></title>
      &lt;disabled script language="Javascript"
              type="text/javascript"
              tal:content="structure string:
              // this is the name of the field in the original form that we're working on
              form  = window.opener.document.${request/form/form/value};
              field = '${request/form/property/value}';" &gt;
      &lt;disabled /script&gt;
     </head>
     <body class="body"
           tal:content="structure python:utils.html_calendar (request)">
     </body>
    </html>

In the extensions folder of your tracker home add a file called 'datehelp.py' with following contents::

    from roundup import date
    import calendar
    import time
    
    r_date = date
    
    def date_help ( request
                  , item
                  , width    = 300
                  , height   = 200
                  , label    = "(cal)"
                  , form     = "itemSynopsis"
                  ) :
        """dump out the link to a calendar pop-up window
    
        item: HTMLProperty e.g.: context.deadline
        """
        if item.isset () :
            date = "&date=%s" % item
        else :
            date = ""
        return ( """<a class="classhelp" """
                 """href="javascript:help_window """
               """('%s?@template=calendar"""
                 """&property=%s"""
                 """&form=%s%s', %d, %d)">%s</a>"""
                 % ( request.classname
                   , item._name
                   , form
                   , date
                   , width
                   , height
                   , label
                   )
               )
    # end def date_help
    
    def html_calendar (request) :
        """returns a html calendar.
    
        `request`  the roundup.request object
                   - @template : name of the template
                   - form      : name of the form to store back the date
                   - property  : name of the property of the form to store
                                 back the date
                   - date      : current date
                   - display   : when browsing, specifies year and month
    
        html will simply be a table.
        """
        print request.form
        date_str  = request.form.getfirst ("date", ".")
        display   = request.form.getfirst ("display", date_str)
        template  = request.form.getfirst ("@template", "calendar")
        form      = request.form.getfirst ("form")
        property  = request.form.getfirst ("property")
        curr_date = r_date.Date (date_str) # to highlight
        display   = r_date.Date (display)  # to show
        year      = display.year
        month     = display.month
        day       = display.day
    
        # for navigation
        date_prev_month = display + r_date.Interval ("-1m")
        date_next_month = display + r_date.Interval ("+1m")
        date_prev_year  = display + r_date.Interval ("-1y")
        date_next_year  = display + r_date.Interval ("+1y")
    
        res      = []
        res.append ("""<table class="calendar">""")
    
        base_link = "%s?@template=%s&property=%s&form=%s&date=%s" % \
                    (request.classname, template, property, form, curr_date)
    
        # navigation
        # month
        res.append (""" <tr>""")
        res.append ("""  <td>""")
        res.append ("""   <table width="100%" class="calendar_nav">""")
        res.append ("""    <tr>""")
        link = base_link + "&display=%s" % date_prev_month
        res.append ("""     <td><a href="%s">&lt;</a></td>""" % link)
        res.append ("""     <td>%s</td>""" % calendar.month_name [month])
        link = base_link + "&display=%s" % date_next_month
        res.append ("""     <td><a href="%s">&gt;</a></td>""" % link)
        # spacer
        res.append ("""     <td width="100%"></td>""")
        # year
        link = base_link + "&display=%s" % date_prev_year
        res.append ("""     <td><a href="%s">&lt;</a></td>""" % link)
        res.append ("""     <td>%s</td>""" % year)
        link = base_link + "&display=%s" % date_next_year
        res.append ("""     <td><a href="%s">&gt;</a></td>""" % link)
        res.append ("""    </tr>""")
        res.append ("""   </table>""")
        res.append ("""  </td>""")
        res.append (""" </tr>""")
    
        # the calendar
        res.append (""" <tr>""")
        res.append ("""  <td>""")
        res.append ("""   <table class="calendar_display">""")
        res.append ("""    <tr class="weekdays">""")
        for day_ in calendar.weekheader (3).split () :
            res.append \
                   ("""     <td>%s</td>""" % day_)
        res.append ("""    </tr>""")
    
        for week_ in calendar.monthcalendar (year, month) :
            res.append \
                   ("""    <tr>""")
            for day_ in week_ :
                link = "javascript:form[field].value = '%d-%02d-%02d'; " \
                                  "window.close ();" % (year, month, day_)
                print curr_date, day_, month, year
                if day_  == curr_date.day   and \
                   month == curr_date.month and \
                   year  == curr_date.year :
                    # highlight
                    style = "today"
                else :
                    style = ""
                if day_ :
                    res.append \
                   ("""     <td class="%s"><a href="%s">%s</a></td>""" %
                              (style, link, day_))
                else :
                    res.append \
                   ("""     <td></td>""")
            res.append \
                   ("""    </tr>""")
        res.append ("""   </table>""")
        res.append ("""  </tb>""")
        res.append (""" </tr>""")
        res.append ("""</table>""")
        return "\n".join (res)
    # end def html_calendar
    
    def init(instance):
        instance.registerUtil('date_help', date_help)
        instance.registerUtil('html_calendar', html_calendar)