Commits

Ashley Felton committed ef2334f

Basic temp logging page set up.

Comments (0)

Files changed (6)

temper/static/favicon.ico

Added
New image

temper/static/img/raspi_logo.png

Added
New image

temper/templates/base.html

         <div class="navbar navbar-inverse navbar-fixed-top">
             <div class="navbar-inner">
                 <div class="container">
-                    <a class="brand" href="#">
-                        <i class="icon-gift icon-large"></i>  Giiifts
+                    <a class="brand" href="/">
+                        <img class="logo_img" src="/static/img/raspi_logo.png" style="width:40px; margin-bottom:-15px; margin-top:-10px;">
+                        RasPi Server
                     </a>
                     <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                         <span class="icon-bar"></span>
                     </a>
                     <div class="nav-collapse collapse">
                         <ul class="nav">
-                            <li{% if home_page %} class="active"{% endif %}><a href="#home">Home</a></li>
-                            <li{% if about_page %} class="active"{% endif %}><a href="#about">About</a></li>
+                            <li{% if home_page %} class="active"{% endif %}><a href="/">Home</a></li>
+                            <li{% if temp_page %} class="active"{% endif %}><a href="/temps">Temp Logger</a></li>
                         </ul>
                     </div><!--/.nav-collapse -->
                 </div>
 
         <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
         <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/js/bootstrap.min.js"></script>
+        {% block extra_js %}{% endblock %}
     </body>
 </html>

temper/templates/index.html

 {% extends "base.html" %}
 
 {% block body %}
-<!-- Main hero unit for a primary marketing message or call to action -->
-<div class="hero-unit">
-    <h1>Hello, world!</h1>
-    <h2>{{ log_date }}</h2>
-    <p>This is a template for a simple marketing or informational website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
-    <p><a class="btn btn-primary btn-large">Learn more &raquo;</a></p>
-</div>
-
-<!-- Example row of columns -->
-<div class="row">
-    <div class="span4">
-        <h2>Heading</h2>
-        <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
-        <p><a class="btn" href="#">View details &raquo;</a></p>
-    </div>
-    <div class="span4">
-        <h2>Heading</h2>
-        <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
-        <p><a class="btn" href="#">View details &raquo;</a></p>
-    </div>
-    <div class="span4">
-        <h2>Heading</h2>
-        <p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
-        <p><a class="btn" href="#">View details &raquo;</a></p>
+<div class="row-fluid">
+    <div class="span12">
+        <h1>Hello, world!</h1>
+        <p>This is the landing page for my Raspberry Pi web server.</p>
     </div>
 </div>
-
-
 {% endblock %}

temper/templates/temp_graph.html

+{% extends "base.html" %}
+
+{% block body %}
+<div class="row-fluid">
+    <div class="span12">
+        <h1>Temperature log</h1>
+        <div id="graph-placeholder" style="width: 600px; height: 400px;"></div>
+    </div>
+</div>
+{% endblock %}
+
+{% block extra_js %}
+<script src="//cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js"></script>
+<script src="//cdnjs.cloudflare.com/ajax/libs/flot/0.7/jquery.flot.min.js"></script>
+<script type="text/javascript">
+    var temps_li = {{ temps_li|safe }};
+    // Interate over the array and convert times to milliseconds.
+    $.each(temps_li, function() {
+        d = Date.parse(this[0]).getTime();
+        this[0] = d;
+    });
+    // Create the graph.
+    $.plot($("#graph-placeholder"), [temps_li], {xaxis: {mode: "time"}});
+</script>
+{% endblock %}
+import json
 from flask import request, render_template
 from temper import app, utils
 from datetime import datetime
 
 
+@app.route('/favicon.ico')
+def favicon():
+    return app.send_static_file('favicon.ico')
 
 @app.route('/')
 def index():
     temps_list = utils.read_log()
-    return render_template('index.html')
+    return render_template('index.html', home_page=True)
 
-@app.route('/<int:year>/<int:month>/<int:day>')
+@app.route('/temps/')
+def log_date_today():
+    temps_li = utils.read_log(datetime.today())
+    return render_template('temp_graph.html', log_date=log_date, temps_li=json.dumps(temps_li))
+
+@app.route('/temps/<int:year>/<int:month>/<int:day>')
+def log_date(year, month, day):
+    log_date = '{0}-{1}-{2}'.format(year, month, day)
+    log_date = datetime.strptime(log_date, '%Y-%m-%d')
+    temps_li = utils.read_log(log_date)
+    return render_template('temp_graph.html', log_date=log_date, temps_li=json.dumps(temps_li))
+
+'''
+@app.route('/api/temps/<int:year>/<int:month>/<int:day>')
 def log_date(year, month, day):
     log_date = '{0}-{1}-{2}'.format(year, month, day)
     log_date = datetime.strptime(log_date, '%Y-%m-%d')
     return render_template('index.html', log_date=log_date)
+'''