handlers.py
author Tero Marttila <terom@fixme.fi>
Wed, 11 Feb 2009 22:24:55 +0200
changeset 111 95c0c49d76aa
parent 108 d0aca7894fc5
child 112 090192b64d7e
permissions -rw-r--r--
implement prev/next_date in LogSource
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
54
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
     5
import datetime, calendar, pytz
51
07ca28f3a9f2 use improved URLConfig/URLType
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
     6
46
185504387370 reduce to irclogs.qmsk.net site
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
     7
from qmsk.web import http, template
40
71ab68f31a1c the handlers work now
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
     8
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
     9
import urls, channels, helpers
53
8103d18907a0 add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
    10
import preferences as prefs
8103d18907a0 add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
    11
from preferences import preferences
96
d30c88e89a7e move the LogSearchIndex open from handlers to log_search, and make it lazy
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    12
import config, log_search
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    13
41
9585441a4bfb working basic logs stuff
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    14
# load templates from here
47
3d59c9eeffaa fix template path
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    15
templates = template.TemplateLoader("templates",
54
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
    16
    _helper_class   = helpers.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
    17
    urls            = urls,
73
5a7188bf2894 split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
    18
    channel_list    = config.LOG_CHANNELS,
5a7188bf2894 split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
    19
    config          = config,
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    20
)
40
71ab68f31a1c the handlers work now
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    21
108
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    22
# return a http.Response for the given text in the given format
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    23
def _render_type (request, channel, lines, type) :
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    24
    """
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    25
        Render the given LogLines as a http.Response in the given format, which is one of:
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    26
            html    - XXX: not supported
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    27
            txt     - Plaintext
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    28
            png     - PNG image
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    29
            rss     - RSS feed
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    30
    """
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    31
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    32
    # load related preferences
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    33
    formatter = request.prefs['formatter']
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    34
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    35
    # we can render in various modes...
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    36
    if type in ('html', None) :
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    37
        xxx
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    38
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    39
    elif type == 'txt' :
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    40
        # plaintext
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    41
        lines = formatter.format_txt(lines)
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    42
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    43
        # build data
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    44
        data = '\n'.join(data for line, data in lines)
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    45
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    46
        return http.Response(data, 'text/plain')
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    47
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    48
    elif type == 'png' :
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    49
        # PNG image
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    50
        png_data = formatter.format_png(lines)
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    51
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    52
        return http.Response(png_data, 'image/png', charset=None)
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    53
    
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    54
    elif type == 'rss' :
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    55
        # RSS feed
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    56
        rss_data = formatter.format_rss(lines)
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    57
        
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    58
        # XXX: fix to render as unicode?
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    59
        return http.Response(rss_data, 'application/rss+xml', charset=None)
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    60
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    61
    else :
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    62
        raise http.ResponseError("Unrecognized type: %r" % (type, ))
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    63
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
    64
29
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    65
def index (request) :
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    66
    """
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    67
        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
    68
    """
40
71ab68f31a1c the handlers work now
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    69
    
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    70
    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
    71
        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
    72
    )
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    73
59
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    74
# XXX: fix this namespace crap
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    75
@preferences.handler()
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    76
def preferences_ (request) :
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    77
    """
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    78
        Preferences editor
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    79
    """
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    80
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    81
    # POST?
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    82
    if request.is_post() :
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    83
        # update any modified preferences
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    84
        for pref in preferences.pref_list :
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    85
            # get+parse new POST'd value
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    86
            # XXX: this doesn't postprocess
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    87
            new_value = pref.parse(request.get_post(pref.name))
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    88
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    89
            # update if changed
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    90
            if new_value != request.prefs[pref] :
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    91
                request.prefs.set(pref.name, new_value)
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    92
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    93
    # render
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    94
    return templates.render_to_response("preferences",
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    95
        req             = request,
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    96
        prefs           = request.prefs,
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    97
        preferences     = prefs,
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    98
        timezones       = pytz.common_timezones,
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    99
    )
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   100
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   101
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
   102
    """
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   103
        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
   104
    """
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
   105
   
70
72edbbb414a7 merge channel_view and channel_last, adding a More link to channel_last.tmpl
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   106
    return http.Redirect(urls.channel.build(request, channel=channel))
29
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   107
59
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   108
@preferences.handler(prefs.formatter)
79
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   109
def channel_last (request, channel, count, formatter, type=None) :
29
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   110
    """
70
72edbbb414a7 merge channel_view and channel_last, adding a More link to channel_last.tmpl
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   111
        The main channel view page, displaying the most recent lines
29
b06ff4c05d42 start prototyping some site-based code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   112
    """
79
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   113
 
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
   114
    # 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
   115
    lines = channel.source.get_latest(count)
79
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   116
   
108
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   117
    # type?
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   118
    if type :
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   119
        # other format
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   120
        return _render_type(request, channel, lines, type)
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   121
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   122
    else :
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   123
        # format HTML
79
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   124
        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
   125
108
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   126
        # render page
79
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   127
        return templates.render_to_response("channel_last",
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   128
            req             = request,
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   129
            prefs           = request.prefs,
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   130
            channel         = channel,
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   131
            count           = count,
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   132
            lines           = lines,
43ac75054d5c image formatting \o/
Tero Marttila <terom@fixme.fi>
parents: 78
diff changeset
   133
        )
40
71ab68f31a1c the handlers work now
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
   134
78
85345abbd46a implement pagination for channel_link
Tero Marttila <terom@fixme.fi>
parents: 77
diff changeset
   135
@preferences.handler(prefs.formatter, prefs.timezone, prefs.count)
85345abbd46a implement pagination for channel_link
Tero Marttila <terom@fixme.fi>
parents: 77
diff changeset
   136
def channel_link (request, channel, timestamp, formatter, timezone, count) :
72
5ade0288f2ec implement line-links as UTC timestamps
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   137
    """
5ade0288f2ec implement line-links as UTC timestamps
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   138
        Display channel_date for specific UTC timestamp
5ade0288f2ec implement line-links as UTC timestamps
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   139
    """
5ade0288f2ec implement line-links as UTC timestamps
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   140
5ade0288f2ec implement line-links as UTC timestamps
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   141
    # convert timestamp to user's timezone
5ade0288f2ec implement line-links as UTC timestamps
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   142
    timestamp = timestamp.astimezone(timezone)
5ade0288f2ec implement line-links as UTC timestamps
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   143
78
85345abbd46a implement pagination for channel_link
Tero Marttila <terom@fixme.fi>
parents: 77
diff changeset
   144
    # get correct day's correct page of lines
85345abbd46a implement pagination for channel_link
Tero Marttila <terom@fixme.fi>
parents: 77
diff changeset
   145
    page, max, lines = channel.source.get_date_paged(timestamp, count)
72
5ade0288f2ec implement line-links as UTC timestamps
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   146
108
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   147
    # type?
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   148
    if type :
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   149
        # special type
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   150
        return _render_type(request, channel, lines, type)
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   151
    
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   152
    else :
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   153
        # format HTML
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   154
        lines = formatter.format_html(lines)
72
5ade0288f2ec implement line-links as UTC timestamps
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   155
108
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   156
        # render
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   157
        return templates.render_to_response("channel_date",
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   158
            req             = request,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   159
            prefs           = request.prefs,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   160
            channel         = channel,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   161
            date            = timestamp,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   162
            page            = page,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   163
            count           = count,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   164
            max             = max,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   165
            lines           = lines,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   166
        )
72
5ade0288f2ec implement line-links as UTC timestamps
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   167
59
8ec729c5d998 ugly, but working, preferences editor
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   168
@preferences.handler(prefs.timezone)
54
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   169
def channel_calendar (request, channel, year, month, timezone) :
51
07ca28f3a9f2 use improved URLConfig/URLType
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
   170
    """
54
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   171
        Display a list of avilable logs for some month
51
07ca28f3a9f2 use improved URLConfig/URLType
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
   172
    """
07ca28f3a9f2 use improved URLConfig/URLType
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
   173
54
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   174
    # current date as default
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   175
    now = timezone.localize(datetime.datetime.now())
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   176
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   177
    # target year/month
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   178
    target = timezone.localize(datetime.datetime(
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   179
        year    = year if year else now.year,
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   180
        month   = month if month else now.month,
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   181
        day     = 1
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   182
    ))
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   183
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   184
    # get set of days available
83
a34e9f56ddda improve parser resilience, improve get_month_days, add 'Channel' item to general menu
Tero Marttila <terom@fixme.fi>
parents: 82
diff changeset
   185
    days = set(channel.source.get_month_days(target))
54
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   186
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   187
    # display calendar
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   188
    return templates.render_to_response("channel_calendar",
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   189
        req             = request,
62
e7ca94b94a4e add prefs to render context, and remove old timezone/formatter from it
Tero Marttila <terom@fixme.fi>
parents: 59
diff changeset
   190
        prefs           = request.prefs,
54
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   191
        channel         = channel,
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   192
        calendar        = calendar.Calendar(),
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   193
        month           = target.date(),
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   194
        days            = days,
b65a95eb9f6b implement browse-by-date to show a nice calendar
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   195
    )
51
07ca28f3a9f2 use improved URLConfig/URLType
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
   196
76
cc3ab2c39ded fix off-by-one with search paginate, and implement basic pagination for channel_date
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   197
@preferences.handler(prefs.formatter, prefs.timezone, prefs.count)
108
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   198
def channel_date (request, channel, date, formatter, timezone, count, page=1, type=None) :
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
   199
    """
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
   200
        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
   201
    """
76
cc3ab2c39ded fix off-by-one with search paginate, and implement basic pagination for channel_date
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   202
53
8103d18907a0 add some user-preferences support (e.g. timezone, time formats)
Tero Marttila <terom@fixme.fi>
parents: 51
diff changeset
   203
    # fix date timezone
111
95c0c49d76aa implement prev/next_date in LogSource
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   204
    date = timezone.localize(date)
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
   205
78
85345abbd46a implement pagination for channel_link
Tero Marttila <terom@fixme.fi>
parents: 77
diff changeset
   206
    # get that day's events, either paged or not
76
cc3ab2c39ded fix off-by-one with search paginate, and implement basic pagination for channel_date
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   207
    if page :
cc3ab2c39ded fix off-by-one with search paginate, and implement basic pagination for channel_date
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   208
        page, max, lines = channel.source.get_date_paged(date, count, page)
cc3ab2c39ded fix off-by-one with search paginate, and implement basic pagination for channel_date
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   209
        
cc3ab2c39ded fix off-by-one with search paginate, and implement basic pagination for channel_date
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   210
    else :
cc3ab2c39ded fix off-by-one with search paginate, and implement basic pagination for channel_date
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   211
        lines = channel.source.get_date(date)
cc3ab2c39ded fix off-by-one with search paginate, and implement basic pagination for channel_date
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   212
        max = None
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
   213
108
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   214
    # type?
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   215
    if type :
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   216
        # special type
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   217
        return _render_type(request, channel, lines, type)
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   218
    
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   219
    else :
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   220
        # lines
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   221
        lines = formatter.format_html(lines)
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
   222
108
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   223
        # render page
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   224
        return templates.render_to_response("channel_date",
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   225
            req             = request,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   226
            prefs           = request.prefs,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   227
            channel         = channel,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   228
            date            = date,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   229
            page            = page,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   230
            count           = count,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   231
            max             = max,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   232
            lines           = lines,
111
95c0c49d76aa implement prev/next_date in LogSource
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   233
95c0c49d76aa implement prev/next_date in LogSource
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   234
            # for prev/next date
95c0c49d76aa implement prev/next_date in LogSource
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   235
            date_next       = channel.source.get_next_date(date),
95c0c49d76aa implement prev/next_date in LogSource
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   236
            date_prev       = channel.source.get_prev_date(date),
108
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   237
        )
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
   238
73
5a7188bf2894 split defined configuration constants into config, and implement search result pagination
Tero Marttila <terom@fixme.fi>
parents: 72
diff changeset
   239
@preferences.handler(prefs.formatter, prefs.count)
108
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   240
def channel_search (request, channel, formatter, count, q=None, page=1, max=1, type=None) :
36
02d4040d5946 start working on some nify URL parsing
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   241
    """
75
c5ce145fdd70 fix pagination to just use page numbers... less bugs
Tero Marttila <terom@fixme.fi>
parents: 74
diff changeset
   242
        Display the search form for the channel for GET, or do the search for POST.
36
02d4040d5946 start working on some nify URL parsing
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   243
    """
02d4040d5946 start working on some nify URL parsing
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   244
75
c5ce145fdd70 fix pagination to just use page numbers... less bugs
Tero Marttila <terom@fixme.fi>
parents: 74
diff changeset
   245
    # calculate skip offset from page/count
76
cc3ab2c39ded fix off-by-one with search paginate, and implement basic pagination for channel_date
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   246
    skip = (page - 1) * count
75
c5ce145fdd70 fix pagination to just use page numbers... less bugs
Tero Marttila <terom@fixme.fi>
parents: 74
diff changeset
   247
63
416560b82116 rudimentary search
Tero Marttila <terom@fixme.fi>
parents: 62
diff changeset
   248
    # got a search query?
416560b82116 rudimentary search
Tero Marttila <terom@fixme.fi>
parents: 62
diff changeset
   249
    if q :
74
1ab95857d584 handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
   250
        try :
1ab95857d584 handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
   251
            # do search
96
d30c88e89a7e move the LogSearchIndex open from handlers to log_search, and make it lazy
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   252
            lines = log_search.get_index().search_simple(channel, q, count, skip)
75
c5ce145fdd70 fix pagination to just use page numbers... less bugs
Tero Marttila <terom@fixme.fi>
parents: 74
diff changeset
   253
c5ce145fdd70 fix pagination to just use page numbers... less bugs
Tero Marttila <terom@fixme.fi>
parents: 74
diff changeset
   254
            # update max?
c5ce145fdd70 fix pagination to just use page numbers... less bugs
Tero Marttila <terom@fixme.fi>
parents: 74
diff changeset
   255
            if max and page > max :
c5ce145fdd70 fix pagination to just use page numbers... less bugs
Tero Marttila <terom@fixme.fi>
parents: 74
diff changeset
   256
                max = page
74
1ab95857d584 handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
   257
        
1ab95857d584 handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
   258
        except log_search.NoResultsFound :
108
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   259
            # no results
74
1ab95857d584 handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
   260
            lines = None
36
02d4040d5946 start working on some nify URL parsing
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   261
108
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   262
    else :
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   263
        # just display the search form
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   264
        lines = None
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   265
 
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   266
    # type?
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   267
    if type and lines :
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   268
        # special type
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   269
        return _render_type(request, channel, lines, type)
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   270
    
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   271
    else :
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   272
        # format lines to HTML if any
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   273
        if lines :
74
1ab95857d584 handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
   274
            # format
1ab95857d584 handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents: 73
diff changeset
   275
            lines = formatter.format_html(lines, full_timestamps=True)
63
416560b82116 rudimentary search
Tero Marttila <terom@fixme.fi>
parents: 62
diff changeset
   276
108
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   277
        # render page
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   278
        return templates.render_to_response("channel_search",
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   279
            req             = request,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   280
            prefs           = request.prefs,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   281
            channel         = channel,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   282
            search_query    = q,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   283
            count           = count,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   284
            page            = page,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   285
            skip            = skip,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   286
            max             = max,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   287
            lines           = lines,
d0aca7894fc5 split out helpers._render_type, and add support for ?type= to various other handlers... still needs more work, though
Tero Marttila <terom@fixme.fi>
parents: 96
diff changeset
   288
        )
63
416560b82116 rudimentary search
Tero Marttila <terom@fixme.fi>
parents: 62
diff changeset
   289