Browse Source

Creating attributes to get page title change on different pages

jeremiewcz 2 years ago
parent
commit
59a663535c
3 changed files with 28 additions and 14 deletions
  1. 24
    13
      app/main/views.py
  2. 3
    0
      app/static/js/app.js
  3. 1
    1
      app/templates/main_pages/podcasts.html

+ 24
- 13
app/main/views.py View File

@@ -67,7 +67,7 @@ def index():
67 67
 @main.route('/about')
68 68
 @partial_content
69 69
 def about():
70
-    page = Page.query.filter_by(name='about').first_or_404()
70
+    page = Page.query.filter_by(id=2).first_or_404()
71 71
     return [ 'displayMain',
72 72
            { "content": render_template("main_pages/about.html",
73 73
                                         page=page) } ]
@@ -76,7 +76,7 @@ def about():
76 76
 @partial_content
77 77
 def contribute():
78 78
     # create a real "contribute" page
79
-    page = Page.query.filter_by(name='contribute').first_or_404()
79
+    page = Page.query.filter_by(id=1).first_or_404()
80 80
     return [ 'displayMain',
81 81
              { "content": render_template("main_pages/contribute.html",
82 82
                                           page=page) } ]
@@ -90,7 +90,6 @@ def contribute():
90 90
 def podcasts():
91 91
     page = request.args.get('page', 1, type=int)
92 92
     pagination = Podcast.query                         \
93
-        .join(Channel, Channel.id==Podcast.channel_id) \
94 93
         .order_by(Podcast.timestamp.desc())            \
95 94
         .paginate(page, per_page=10, error_out=False)
96 95
     podcasts = pagination.items
@@ -103,15 +102,17 @@ def podcasts():
103 102
 @main.route('/podcasts/<id>')
104 103
 @partial_content
105 104
 def podcast(id):
106
-    podcast = Podcast.query.filter_by(id = id).first()
105
+    podcast = Podcast.query.get(id)
107 106
     return [ 'displayMain',
108 107
              { "content": render_template("elem_pages/podcast.html",
109
-                                          elem=podcast) }]
108
+                                          elem=podcast),
109
+               "title": podcast.name,
110
+               "description" : podcast.description } ]
110 111
 
111 112
 @main.route('/podcasts/<id>/play')
112 113
 @partial_content_no_history
113 114
 def play(id):
114
-    podcast = Podcast.query.filter_by(id = id).first()
115
+    podcast = Podcast.query.get(id)
115 116
     return [ "player.load.bind(player)",
116 117
              { "link" : podcast.link,
117 118
                "title" : podcast.name } ]
@@ -127,16 +128,19 @@ def contributors():
127 128
     return [ 'displayMain',
128 129
              { "content": render_template("main_pages/contributors.html",
129 130
                                           contributors=Contributor.list(),
130
-                                          collectives=Collective.list(),
131
-                                         )}]
131
+                                          collectives=Collective.list()),
132
+               "title": podcast.name,
133
+               "description" : podcast.description }]
132 134
 
133 135
 @main.route('/contributors/<id>')
134 136
 @partial_content
135 137
 def contributor(id):
136
-    contributor = Contributor.query.filter_by(id = id).first()
138
+    contributor = Contributor.query.get(id)
137 139
     return [ 'displayMain',
138 140
              { "content": render_template("elem_pages/contributor.html",
139
-                                          elem=contributor) }]
141
+                                          elem=contributor),
142
+               "title": podcast.name,
143
+               "description" : podcast.description }]
140 144
 
141 145
 @main.route('/collectives/<id>')
142 146
 @partial_content
@@ -144,7 +148,9 @@ def collective(id):
144 148
     collective = Collective.query.filter_by(id = id).first()
145 149
     return [ 'displayMain',
146 150
              { "content": render_template("elem_pages/contributor.html",
147
-                                          elem=collective) }]
151
+                                          elem=collective),
152
+               "title": collective.name,
153
+               "description" : collective.description } ]
148 154
 
149 155
 #########################
150 156
 #  Blogs                #
@@ -155,13 +161,18 @@ def collective(id):
155 161
 def blogs():
156 162
     return [ 'displayMain',
157 163
              { "content": render_template("main_pages/blogs.html",
158
-                                          blog_posts = BlogPost.list(number=10) )} ]
164
+                                          blog_posts = BlogPost.list(number=10)),
165
+               "title": "Blogs",
166
+               "description": "Les articles de blog de Radio Rhino" } ]
159 167
 
160 168
 @main.route('/blogs/<id>')
161 169
 @partial_content
162 170
 def blog(id):
171
+
163 172
     return [ 'displayMain',
164
-             { "content": render_template("notimplemented.html") }]
173
+             { "content": render_template("main_page/blogs.html",
174
+                                          blog_post = BlogPost.query.list()),
175
+               "title": blog_post.name } ]
165 176
 
166 177
 #########################
167 178
 #  Agendas              #

+ 3
- 0
app/static/js/app.js View File

@@ -69,6 +69,9 @@ function loadContent(target) {
69 69
 
70 70
 function displayMain(data) {
71 71
     document.getElementsByTagName("main")[0].innerHTML = data["content"];
72
+    if data["title"] { document.getElementsByTagName("title")[0].innerHTML = data["title"];}
73
+    if data["description"] { document.getElementsByName("description")[0].innerHTML = data["description"]; }
74
+
72 75
 }
73 76
 
74 77
 function checkLive() {

+ 1
- 1
app/templates/main_pages/podcasts.html View File

@@ -19,7 +19,7 @@
19 19
             {% endif %}
20 20
         </div>
21 21
     </div>
22
-    <span class="license">{{ elem.timestamp|format_date }}</span>
22
+    <span class="license">{{ elem.date|format_date }}</span>
23 23
 
24 24
     {% if elem.collectives|length > 0 %}
25 25
     <p class="marg decal">Par

Loading…
Cancel
Save