handlers.py
changeset 54 b65a95eb9f6b
parent 53 8103d18907a0
child 55 5667d2bbdc50
equal deleted inserted replaced
53:8103d18907a0 54:b65a95eb9f6b
     1 """
     1 """
     2     Our URL action handlers
     2     Our URL action handlers
     3 """
     3 """
     4 
     4 
     5 import pytz
     5 import datetime, calendar, pytz
     6 
     6 
     7 from qmsk.web import http, template
     7 from qmsk.web import http, template
     8 
     8 
     9 import urls, channels, helpers
     9 import urls, channels, helpers
    10 import preferences as prefs
    10 import preferences as prefs
    11 from preferences import preferences
    11 from preferences import preferences
    12 
    12 
    13 # load templates from here
    13 # load templates from here
    14 templates = template.TemplateLoader("templates",
    14 templates = template.TemplateLoader("templates",
    15     h               = helpers,
    15     _helper_class   = helpers.Helpers,
    16     urls            = urls,
    16     urls            = urls,
    17     channel_list    = channels.channel_list,
    17     channel_list    = channels.channel_list,
    18 )
    18 )
    19 
    19 
    20 def index (request) :
    20 def index (request) :
    31         Redirect to the appropriate channel_view
    31         Redirect to the appropriate channel_view
    32     """
    32     """
    33    
    33    
    34     return http.Redirect(urls.channel_view.build(request, channel=channel.id))
    34     return http.Redirect(urls.channel_view.build(request, channel=channel.id))
    35 
    35 
    36 @preferences.handler(prefs.Formatter)
    36 @preferences.handler(prefs.Formatter, prefs.Timezone)
    37 def channel_view (request, channel, count, formatter) :
    37 def channel_view (request, channel, count, formatter, timezone) :
    38     """
    38     """
    39         The main channel view page, display the most important info, and all requisite links
    39         The main channel view page, display the most important info, and all requisite links
    40     """
    40     """
    41     
    41     
    42     # get latest events
    42     # get latest events
    45     # lines
    45     # lines
    46     lines = formatter.format_html(lines)
    46     lines = formatter.format_html(lines)
    47 
    47 
    48     return templates.render_to_response("channel_view",
    48     return templates.render_to_response("channel_view",
    49         req             = request,
    49         req             = request,
       
    50         timezone        = timezone,
    50         channel         = channel,
    51         channel         = channel,
    51         count           = count,
    52         count           = count,
    52         formatter       = formatter,
    53         formatter       = formatter,
    53         lines           = lines,
    54         lines           = lines,
    54     )
    55     )
    64          pass
    65          pass
    65 
    66 
    66     else :
    67     else :
    67         raise http.ResponseError("Unknown filetype %r" % format)
    68         raise http.ResponseError("Unknown filetype %r" % format)
    68 
    69 
    69 def channel_calendar (request, channel) :
    70 @preferences.handler(prefs.Timezone)
       
    71 def channel_calendar (request, channel, year, month, timezone) :
    70     """
    72     """
    71         Display a list of avilable logs for some days
    73         Display a list of avilable logs for some month
    72     """
    74     """
    73 
    75 
    74     pass
    76     # current date as default
       
    77     now = timezone.localize(datetime.datetime.now())
       
    78 
       
    79     # target year/month
       
    80     target = timezone.localize(datetime.datetime(
       
    81         year    = year if year else now.year,
       
    82         month   = month if month else now.month,
       
    83         day     = 1
       
    84     ))
       
    85 
       
    86     # get set of days available
       
    87     days = channel.source.get_month_days(target)
       
    88 
       
    89     # display calendar
       
    90     return templates.render_to_response("channel_calendar",
       
    91         req             = request,
       
    92         timezone        = timezone,
       
    93         channel         = channel,
       
    94         calendar        = calendar.Calendar(),
       
    95         month           = target.date(),
       
    96         days            = days,
       
    97     )
    75 
    98 
    76 @preferences.handler(prefs.Formatter, prefs.Timezone)
    99 @preferences.handler(prefs.Formatter, prefs.Timezone)
    77 def channel_date (request, channel, date, formatter, timezone) :
   100 def channel_date (request, channel, date, formatter, timezone) :
    78     """
   101     """
    79         Display all log data for the given date
   102         Display all log data for the given date
    88     # lines
   111     # lines
    89     lines = formatter.format_html(lines)
   112     lines = formatter.format_html(lines)
    90 
   113 
    91     return templates.render_to_response("channel_date",
   114     return templates.render_to_response("channel_date",
    92         req             = request,
   115         req             = request,
       
   116         timezone        = timezone,
    93         channel         = channel,
   117         channel         = channel,
    94         formatter       = formatter,
   118         formatter       = formatter,
    95         date            = date,
   119         date            = date,
    96         lines           = lines,
   120         lines           = lines,
    97     )
   121     )