handlers.py
author Tero Marttila <terom@fixme.fi>
Mon, 09 Feb 2009 00:24:13 +0200
changeset 50 f13cf27a360b
parent 49 aaa62c8e5bd5
child 51 07ca28f3a9f2
permissions -rw-r--r--
implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
29
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
"""
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
    Our URL action handlers
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
"""
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
46
185504387370 reduce to irclogs.qmsk.net site
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
     5
from qmsk.web import http, template
40
71ab68f31a1c the handlers work now
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
     6
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
     7
import urls, channels, helpers
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
     8
41
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
     9
# load templates from here
47
3d59c9eeffaa fix template path
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    10
templates = template.TemplateLoader("templates",
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    11
    h               = helpers,
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    12
    urls            = urls,
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    13
    channel_list    = channels.channel_list,
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    14
)
40
71ab68f31a1c the handlers work now
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    15
29
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
def index (request) :
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
    """
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
        The topmost index page, display a list of available channels, perhaps some general stats
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
    """
40
71ab68f31a1c the handlers work now
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    20
    
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    21
    return templates.render_to_response("index",
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    22
        req             = request,
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    23
    )
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    24
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    25
def channel_select (request, channel) :
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    26
    """
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    27
        Redirect to the appropriate channel_view
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    28
    """
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    29
   
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    30
    return http.Redirect(urls.channel_view.build(request, channel=channel.id))
29
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    32
def channel_view (request, channel, count, formatter) :
29
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
    """
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
        The main channel view page, display the most important info, and all requisite links
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    35
    """
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    36
    
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    37
    # get latest events
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    38
    lines = channel.source.get_latest(count)
43
fc11c4e86a82 implement channel_view count, the query stuff, css, layout all need some cleanup :(
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
    39
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    40
    # format
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    41
    lines = formatter.format_html(lines)
43
fc11c4e86a82 implement channel_view count, the query stuff, css, layout all need some cleanup :(
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
    42
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    43
    return templates.render_to_response("channel_view",
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    44
        req             = request,
41
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    45
        channel         = channel,
43
fc11c4e86a82 implement channel_view count, the query stuff, css, layout all need some cleanup :(
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
    46
        count           = count,
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    47
        formatter       = formatter,
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    48
        lines           = lines,
40
71ab68f31a1c the handlers work now
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    49
    )
71ab68f31a1c the handlers work now
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    50
41
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    51
def channel_last (request, channel, count, format) :
29
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    52
    """
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    53
        Display the last x lines of channel messages in various formats
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    54
    """
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    55
41
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    56
    if format == 'txt' :
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    57
        # XXX: formatting
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    58
#        return http.Response('\n'.join(str(channel.source.get_latest(count))), 'text/plain')
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    59
         pass
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    60
41
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    61
    else :
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    62
        raise http.ResponseError("Unknown filetype %r" % format)
29
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    63
50
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    64
def channel_date (request, channel, date, formatter) :
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    65
    """
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    66
        Display all log data for the given date
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    67
    """
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    68
    
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    69
    # XXX: fix date timezone
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    70
    import pytz
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    71
    date = date.replace(tzinfo=pytz.utc)
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    72
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    73
    # get latest events
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    74
    lines = channel.source.get_date(date)
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    75
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    76
    # format
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    77
    lines = formatter.format_html(lines)
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    78
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    79
    return templates.render_to_response("channel_date",
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    80
        req             = request,
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    81
        channel         = channel,
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    82
        formatter       = formatter,
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    83
        date            = date,
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    84
        lines           = lines,
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    85
    )
f13cf27a360b implement more LogSource features (logs for date, cleanup last_logs), implement irssi parser, formatter, other misc. stuff
Tero Marttila <terom@fixme.fi>
parents: 49
diff changeset
    86
49
aaa62c8e5bd5 add search form to menu, remove styling from inputs/selects other than the submit button
Tero Marttila <terom@fixme.fi>
parents: 47
diff changeset
    87
def channel_search (request, channel, q) :
36
02d4040d5946 start working on some nify URL parsing
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    88
    """
02d4040d5946 start working on some nify URL parsing
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    89
        Display the search form for the channel for GET, or do the search for POST
02d4040d5946 start working on some nify URL parsing
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    90
    """
02d4040d5946 start working on some nify URL parsing
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    91
02d4040d5946 start working on some nify URL parsing
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    92
    pass
02d4040d5946 start working on some nify URL parsing
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    93