Commits

Puria Nafisi Azizi  committed 8beada4

Divided expired and active polls

  • Participants
  • Parent commits d309fbd

Comments (0)

Files changed (2)

File tgpolls/controllers/root.py

 class RootController(TGController):
     @expose('tgpolls.templates.index')
     def index(self):
-        polls = DBSession.query(Poll).order_by(Poll.uid.desc()).all()
-        return dict(polls=polls)
+        polls = DBSession.query(Poll).order_by(Poll.uid.desc()).filter(Poll.expiry > datetime.datetime.now()).all()
+        expired_polls = DBSession.query(Poll).filter(Poll.expiry < datetime.datetime.now()).all()
+        return dict(polls=polls, expired_polls=expired_polls)
 
     @require(predicates.in_group('managers'))
     @expose('tgpolls.templates.poll.new')

File tgpolls/templates/index.html

 <body>
     <h1>Polls</h1>
     <br />
-    <a href="${h.plug_url('tgpolls', '/new')}" class="btn btn-success pull-right">New poll</a>
+    <a href="${h.plug_url('tgpolls', '/new')}" py:if="request.identity" class="btn btn-success pull-right">New poll</a>
     <div py:for="poll in polls" class="tgpolls_poll_container">
         <h6>This poll will end at ${poll.expiry}</h6>
         <div class="tgpolls_poll">${h.call_partial('tgpolls.partials:poll_partial', poll=poll)}</div>
     </div>
+    <br/>
+    <div  py:if="request.identity">
+        <hr/>
+        <h1>Expired Polls</h1>
+        <div py:for="poll in expired_polls" class="tgpolls_poll_container">
+            <h6>This poll ended at ${poll.expiry}</h6>
+            <div class="tgpolls_poll">${h.call_partial('tgpolls.partials:poll_partial', poll=poll)}</div>
+        </div>
+    </div>
 </body>
 </html>