Commits

abernier committed e39e0ff

comments limited to n days after blog_post creation date

  • Participants
  • Parent commits acd26e9

Comments (0)

Files changed (6)

     'admin_name': 'Adam Bernier',
     'admin_email': 'adam.c.bernier@gmail.com',
     'base_url': 'http://adam-bernier.appspot.com',
+    'comment_open_days': 10,
     'description': "Adam's Blog",
-    'google_ajax_search': True,
-    'google_analytics': False,
-    'page_size': 5,
+    'google_ajax_search': False,
+    'google_analytics': True,
+    'page_size': 10,
     'site': 'adam-bernier.appspot.com',
 }
 

static/css/style.css

 p img.right { float: right; margin: 1.5em 0 1.5em 1.5em; }
 
 a:focus, 
-a:hover     { color: #66ee66; }
+a:hover     { color: #0000cc; background-color: #f0f0f0; }
 a           { color: #555555; border:none; text-decoration:none; border-bottom:#999 1px dotted; background-color:transparent; }
 /* no underline; use when img inside anchor tag */
 a.no_u      { border-bottom: none; }
 pre,code,tt { font-size: 90%;
               font-family: 'andale mono', 'lucida console', monospace; 
               line-height: 1.5; 
-              background-color: #F0F0F0; 
+              background-color: #f0f0f0; 
             } 
             /* font: 1em */
-hr          { height: 0; border-style: solid; border-width: 1px 0 0 0; border-color:#C0C0C0; }
+hr          { color: #fff; background-color: #fff; border: 1px dotted #c0c0c0; border-style: none none dotted; }
 
 /* Lists
 -------------------------------------------------------------- */
 }
 
 legend {
-      padding: 0 2px;
-      font-weight: bold;
+    padding: 0 2px;
+    font-weight: bold;
 }
 
 /* Tables
 -------------------------------------------------------------- */
 
 .small      { font-size: .8em; line-height: 1.875em; /*margin-bottom: 1.875em; */}
-.large      { font-size: 1.4em; line-height: 2.5em; font-weight: bold; /*margin-bottom: 1.25em; */}
+.large      { font-size: 1.4em; line-height: 2.0em; font-weight: bold; /*margin-bottom: 1.25em; */}
 .hide       { display: none; }
 .indented   { padding-left: 20px; }
 

templates/base.html

     //]]>
     </script>
     
+    {% if settings.google_analytics %}
+        <script type="text/javascript">
+
+          var _gaq = _gaq || [];
+          _gaq.push(['_setAccount', 'UA-16291963-3']);
+          _gaq.push(['_trackPageview']);
+
+          (function() {
+            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+          })();
+        </script>    
+    {% endif %}
   </head>
   <body>
     <div id="wrapper">
             <div>
                 <strong>some blogs I read:</strong>
             </div>
-            <span class="small">(sorted alphabetically)</span>
             {% for blog in blogroll %}
                 <div>
                     <a href="{{ blog.url }}">{{ blog.title }}</a>
         </div>
       </div>
     </div>
-
-{% if settings.google_analytics %}
-    <script type="text/javascript">
-        var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
-        document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
-    </script>
-    <script type="text/javascript">
-        try {
-            var pageTracker = _gat._getTracker("UA-16291963-1");
-            pageTracker._trackPageview();
-        } catch(err) {}
-    </script>
-{% endif %}
   </body>
 </html>
 

templates/index.html

         </a>
     </div>
     
-    {{ blog_post.content_html }}
-    <br />
-    
-    <div class="indented">
-        <a href="/post/{{ blog_post.key.id }}/{{ blog_post.uri }}#comment">
-        Add a comment</a>
-    </div>
-    
     <div class="indented quiet small">
         {% if blog_post.tags %}
             tags:
             | updated: {{ blog_post.updated|date:"Y-m-d" }}
         {% endif %}
     </div>
-    <br />
+    <hr />
     <br />
 {% endfor %}
 

templates/view.html

 </div>
 
 <hr />
+<br />
 
 <div>
   {% if comments %}
 </div>
     
 <div>
+{% if comments_open %}
     <form action="/post/{{ blog_post.key.id }}/{{ blog_post.uri }}" method="post">
     <fieldset>
     <legend><a href="#comment" name="comment">Add a comment</a></legend>
         <input type="hidden" name="blog_key" value="{{ blog_post.key }}" />
     </dd>
     </form>
+{% else %}
+    <blockquote>Comments are now closed for this post.</blockquote>
+{% endif %}
 </div>
 
 {% endblock %}
 #       MA 02110-1301, USA.
 
 from collections import defaultdict
-import os
+from datetime import date, datetime, timedelta
+import logging, os
 
 from google.appengine.api import mail
 from google.appengine.api import memcache
         query1.order('date')
         blog_comments = query1.fetch(100) # arbitrary max
         
+        max_comment_date = (blog_post.created + 
+            timedelta(days=config.SETTINGS['comment_open_days']))
+        if datetime.now() < max_comment_date:
+            comments_open = True
+        else:
+            comments_open = False
+        
         if blog_post:
             self.render('view.html', {
                 'blog_post': blog_post,
-                'comments': blog_comments #blog_post.blogcomment_set
+                'comments': blog_comments, #blog_post.blogcomment_set
+                'comments_open': comments_open
             })
 
     def post(self, id, blog_uri):