Yang Zhang avatar Yang Zhang committed 0ec3ac6

user can see others' started topic

Comments (0)

Files changed (8)

 from application import create_app,connect_db
 from configure import configure
 from models import User, Topic, Comment
-app = create_app(database_uri = 'db', configure=configure)
+
+DATABASE = 'db'
+app = create_app(database_uri = DATABASE , configure=configure)
 manager = Manager(app)
 
 @manager.command
     print "hello"
 
 @manager.command
+def create_table():
+    'create table'
+    g.db = connect_db()
+    c = g.db.cursor()
+    c.executescript(open('forum.sql').read())
+    g.db.commit()
+    
+@manager.command
 def make_data():
     'make some fake data for testing'
     g.db = connect_db()
         nickname = User.password_generate()
         user = User(email,nickname,"")
         user.save()
-        for t in xrange(100):
+        for t in xrange(50):
             temptopic = Topic(User.password_generate(),User.password_generate())
             temptopic.posterid = user.id
             temptopic.post()
-            for k in xrange(100):
+            user.toggle_star_topicid(temptopic.id)
+            for k in xrange(60):
                 c = Comment(User.password_generate(), temptopic.id)
                 c.userid = user.id
                 c.save()
 }
 
 #footer{
+margin-top: 20px;
 border-top:1px solid #D4D4D4;
 text-align:center;
 

templates/index.html

             
         {%else%}
         {% set total_page = (counter.topic_number-1)//15+1 %}
-        <ul class="pager">
+        <ul class="pager span11">
           
             {%if current_page ==1%}
             <li class="previous disabled">

templates/show_topic_list.html

 {%extends 'base.html'%}
 
 {%block content%}
-<div class='container'><div class='container-box span8 offset2'>
+<div class='container'>
+<div class='container-box span8 offset2'>
+    {%block sub_header%}
+    <h3><a href='/user/{{user.id}}'>{{user.nickname}}</a>创建的主题</h3>
+    {%endblock%}
 
     {% from 'macro/topiclist.html' import make_list %}
-    {{make_list(created_topic)}}
+    {{make_list(topic_list)}}
 
 
     <div class="row-fluid">
-        {%if created_topic|length==0%}
+        {%if topic_list|length==0%}
             <label style='text-align: center;'>该栏目暂时没有主题...</label>
-            
+
         {%else%}
         {% set total_page = (counter-1)//15+1 %}
-        <ul class="pager">
-          
+        <ul class="pager span11">
+
             {%if current_page ==1%}
             <li class="previous disabled">
             <a href="javascript:void(0)">&larr; 上一页</a>
             <a href="{{page_url}}/{{current_page-1}}">&larr; 上一页</a>
             </li>
             {%endif%}
-            
+
           {%if current_page ==total_page%}
               <li class="next disabled">
                 <a href="javascript:void(0)">下一页 &rarr;</a>
             <a href="javascript:void(0)">{{current_page}} / {{total_page}}</a>
           </li>
         </ul>
-        
-            
+
+
         {%endif%}
     </div>
 
 </div></div>
-{%if user%}
 
-<div class='container-box' id='topic-post'>
-    <div class='row-fluid'>
-    <legend>新主题</legend>
-    <form action='/ua/post' method='post' id='topic-form' class='span9 offset1'>
-        <input id='topic-post-title'type="text" name='title'placeholder="标题" class="span12" spellcheck="false" />
-         <div id="wmd-button-bar"></div>
-        <textarea id='wmd-input'class="span12" name='content'rows="8" placeholder="内容"></textarea>
-        <input type="submit" id='signupsubmmit' onclick='return topic_submit();'class='btn pull-right' value='创建' />
-    </form>
-    </div>
-</div>
-{%endif%}
 
 {%endblock%}
 

templates/topic.html

         
         <div>
         {%if topic.content%}
-            <h5 style='word-wrap: break-word;'>
+            <label style='word-wrap: break-word;'>
             {{topic.content}}
-            </h5>
+            </label>
         {%endif%}
         </div>
         

templates/user.html

                 {% from 'macro/topiclist.html' import make_list %}
                 {{make_list(stared_topic)}}
                 {%if stared_topic|length ==5%}
-                <a class='muted span12'href='/' style='text-align:center'>查看更多</a>
+                <a class='muted span12'href='{{user.id}}/star_topics' style='text-align:center'>查看更多</a>
                 {%endif%}
             {%else%}
                 <label style='text-align:center'>该用户暂未收藏任何主题</label>

templates/user_started_topics.html

+{%extends 'show_topic_list.html'%}
+{%block sub_header%}
+<h3><a href='/user/{{user.id}}'>{{user.nickname}}</a>收藏的主题</h3>
+{%endblock%}
 
 @user.route('/<int:userid>/star_topics')
 @user.route('/<int:userid>/star_topics/<int:page>/')
-def show_user_star_topics(page=1):
-    pass
+def show_user_star_topics(userid,page=1):
+    user = User.get_user_by_id(userid)
+    page_url = url_for("user.show_user_star_topics", userid= userid)
+    stared_topic = Topic.get_topic_stared_byuserid(userid, limit=15, offset = page-1)
+    if('user' in session):
+        Topic.check_list_toggled_byuser(session['user'].id,stared_topic)
+    return render_template('user_started_topics.html',
+                        user = user,
+                        topic_list = stared_topic, 
+                        counter=user.created_topic_counter, 
+                        page_url = page_url,
+                        current_page = page)
 
 @user.route('/<int:userid>/created_topics')
 @user.route('/<int:userid>/created_topics/<int:page>/')
     page_url = url_for("user.show_user_created_topics", userid= userid)
     created_topic = Topic.get_topic_created_byuserid(userid, limit=15,offset = page-1)
     return render_template('show_topic_list.html',
-                        created_topic = created_topic, 
+                        user = user,
+                        topic_list = created_topic, 
                         counter=user.created_topic_counter, 
                         page_url = page_url,
                         current_page = page)
 
 @user.route('/<int:userid>/comments')
 @user.route('/<int:userid>/comments/<int:page>/')
-def show_user_comments(page=1):
+def show_user_comments(userid,page=1):
     pass
 
 
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.