فهرست منبع

render results from get_tweets() to template

mk200789 10 سال پیش
والد
کامیت
9494aae1d8
2فایلهای تغییر یافته به همراه34 افزوده شده و 3 حذف شده
  1. 27 2
      hackathon_starter/hackathon/templates/hackathon/twitter_tweet.html
  2. 7 1
      hackathon_starter/hackathon/views.py

+ 27 - 2
hackathon_starter/hackathon/templates/hackathon/twitter_tweet.html

@@ -1,6 +1,31 @@
 <!DOCTYPE html>
 <html>
 <body>
-	{% include 'hackathon/base.html' %}
-	<h1 class="text-center"> {{ title }}</h1>
+    {% include 'hackathon/base.html' %}
+    <h1 class="text-center"> {{ title }}</h1> 
+    <div class="col-lg-12">      
+        <div class="table-responsive">
+            <table class="table table-bordered table-hover table-striped tablesorter">
+                <thead>
+                <tr>
+                <th class="header"> Who <i class="icon-sort"></i></th>
+                <th class="header"> Tweet <i class="icon-sort"></i></th>
+                <th class="header"> Retweets <i class="icon-sort"></i></th>
+                <th class="header"> Created <i class="icon-sort"></i></th>
+
+                </tr>
+            </thead>
+            <tbody>
+            {% for item in content %}
+                <tr>
+                    <td>{{ item.user.screen_name }}</td> 
+                    <td>{{ item.text }}</td>
+                    <td>{{ item.retweet_count}}</td>
+                    <td>{{ item.created_at}}</td>
+            {% endfor %}
+            </tbody>
+            </table>
+        </div>
+    </div>
+
 </html>

+ 7 - 1
hackathon_starter/hackathon/views.py

@@ -384,8 +384,14 @@ def twitter(request):
     return render(request, 'hackathon/twitter.html', context)
 
 def twitterTweets(request):
+    print getTwitter.is_authorized
+    if getTwitter.is_authorized:
+        content = getTwitter.get_tweets()
+    else:
+        twitter_url = getTwitter.get_authorize_url()
+        return HttpResponseRedirect(twitter_url)
 
-    context ={'title': 'twitter tweet'}
+    context ={'title': 'twitter tweet', 'content': content}
     return render(request, 'hackathon/twitter_tweet.html', context)    
 
 ##################