Anonymous avatar Anonymous committed 1058d7c

date lookup

Comments (0)

Files changed (7)

irc_reader/__init__.py

-from flask import Flask, render_template, request, current_app, url_for
+import markdown
+
+from flask import Flask, render_template, request, current_app, url_for, \
+    Markup
 
 from irc_reader.models import Channel, Message, db
 
                                page_url=page_url,
                                channel=channel)
 
+    @app.template_filter('markdown')
+    def _markdown(value):
+        """
+        Simple markup for IRC messages
+        """
+        return Markup(markdown.markdown(value))
+
+
+    @app.context_processor
+    def config():
+        return dict(config=app.config)
+
     return app
 

irc_reader/models.py

                    Message.message.like(search))
 
         return self.filter(q)
+
+    def dates(self):
+        """
+        Return unique list of dates for messages
+        """
+
+        return sorted(set(d[0] for d in self.values(Message.date)))
         
 class Message(db.Model):
     __tablename__ = "messages"
 
     query_class = MessageQuery
     
-    __mapper_args__ = {'order_by' : date.asc()}
+    __mapper_args__ = {'order_by' : date.desc()}
 
     def __str__(self):
         return "%s:%s" % (self.nick, self.message)

irc_reader/templates/channel.html

+{% extends "layout.html" %}
 {% from "_pagination.html" import paginate %}
-<html>
-    <body>
-        <ul>
+{% block content %}
+        <h2>{{ channel }}</h2>
+        <ul class="messages">
         {% for message in page_obj.items %}
-        <li>{{ message.date.strftime("%d-%m-Y %H:%M") }} {% if message.nick %} <strong><a href="{{ url_for('nick', nick=message.nick) }}">{{ message.nick }}</a></strong> {% endif %}{{ message.message }}</li>
+        {% if message.nick %}
+        <li>{{ message.date.strftime("%d-%m-%Y %H:%M") }} <strong><a href="{{ url_for('nick', nick=message.nick) }}">{{ message.nick }}</a></strong> {{ message.message|markdown }}</li>
+        {% else %}
+        <li>{{ message.date.strftime("%d-%m-%Y %H:%M") }}  <strong>{{ message.message|markdown }}</strong></li>
+        {% endif %}
         {% endfor %}
     </ul>
     {{ paginate(page_obj, page_url) }}
-    </body>
-</html>
+{% endblock %}

irc_reader/templates/layout.html

 <!DOCTYPE html>
 <html>
     <head>
-        <title>IRC Reader</title>
+        <title>{{ config.get('APP_TITLE', 'IRC Reader') }}</title>
         <link type="text/css" rel="stylesheet" href="/static/style.css">
     </head>
     <body>
         <div class="header">
-            <h1>IRC Reader</h1>
+            <h1>{{ config.get('APP_TITLE', 'IRC Reader') }}</h1>
             <form class="search" action="{{ url_for('search') }}" method="GET">
                 <input type="search" name="search" size="15">
             </form>

irc_reader/templates/nick.html

-
-<html>
-    <body>
-        <ul>
+{% extends "layout.html" %}
+{% from "_pagination.html" import paginate %}
+{% block content %}
+        <h2>&lt;{{ nick }}&gt;</h2>
+        <ul class="messages">
         {% for message in page_obj.items %}
-        <li>{{ message.date.strftime("%d-%m-Y %H:%M") }} {{ message.message }}</li>
+        <li><strong><a href="{{ url_for('channel', channel_id=message.channel_id) }}">{{ message.channel }}</a></strong>{{ message.date.strftime("%d-%m-%Y %H:%M") }}  {{ message.message }}</li>
         {% endfor %}
-        </ul>
-    </body>
-</html>
+    </ul>
+    {{ paginate(page_obj, page_url) }}
+{% endblock %}

irc_reader/templates/search.html

 {% extends "layout.html" %}
 {% from "_pagination.html" import paginate %}
 {% block content %}
-<ul class="messages">
-    {% for message in page_obj.items %}
-    <li>{{ message.date.strftime("%d-%m-Y %H:%M") }} {% if message.nick %} <strong><a href="{{ url_for('nick', nick=message.nick) }}">{{ message.nick }}</a></strong> {% endif %}{{ message.message }}</li>
+<h2>Search results for '{{ search }}'</h2>
+        <ul class="messages">
+        {% for message in page_obj.items %}
+        <li><strong><a href="{{ url_for('channel', channel_id=message.channel_id) }}">{{ message.channel }}</a></strong> <strong>{{ message.date.strftime("%d-%m-%Y %H:%M") }}</strong>  <strong><a href="{{ url_for('nick', nick=message.nick) }}">{{ message.nick }}</a></strong> {{ message.message }}</li>
         {% endfor %}
-</ul>
-{{ paginate(page_obj, page_url) }}
+    </ul>
+    {{ paginate(page_obj, page_url) }}
 {% endblock %}
 
         assert Message.query.search('tester').count() == 200
 
+    def test_dates(self):
+        
+        dates = Message.query.dates()
+
+        assert len(dates) == 1
+        
+        now = datetime.now()
+
+        date = dates[0]
+
+        assert date.year == now.year
+        assert date.month == now.month
+        assert date.day == now.day
+
+
 class TestViews(_TestCase):
 
     def test_index(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.