Adding Categorizing Functionality to Navigation Widget
#index.py
from flask import render_template
from flask_classful import FlaskView, route
from models.postdb import Postdb
class Index(FlaskView):
@route('/')
def index(self):
self.postdb = Postdb()
vdict = self.postdb.get_post()
return render_template('index.html', data=vdict)
@route('/post/<id>/')
def get_single_post(self, id):
self.postdb = Postdb()
vdict = self.postdb.get_post(id)
return render_template('post.html', data=vdict)
@route('/category/<cat>/')
def get_post_category(self, cat):
self.postdb = Postdb()
vdict = self.postdb.get_post(cat=cat)
return render_template('index.html', data=vdict)
#models/post.py
import config, copy, lib, requests
from flask import render_template
from flask_classful import FlaskView, route
class Postdb():
def get_post(self, id='', cat=''):
vdict = copy.deepcopy(config.vdict)
if id:
URL = "https://www.googleapis.com/blogger/v3/blogs/"+vdict['blog-id']+"/posts/"+id
PARAMS = {"key":vdict['api-key']}
r = requests.get(url = URL, params = PARAMS)
data = r.json()
vdict['post'] = data
vdict['id'] = id
elif cat:
vdict['cat'] = cat
self.vlib = lib.Lib()
vdict['date'] = self.vlib.set_date()
return vdict
<!--templates/index.html-->
{% extends "base.html" %}
{% block head %}
{{ super() }}
<script src="/static/scripts/index.js"></script>
<link href="/static/styles/index.css" rel="stylesheet">
{% endblock %}
{% block panel %}
{% if 'cat' in data %}
<script>
index.label = '{{ data["cat"] }}';
</script>
{% endif %}
<div id="panel" class="panel region"></div>
<div class="navigation region">
<img onclick="index.navPrevious()" src="/static/images/left.png" />
<img id="nav-home" onclick="index.navHome()" src="/static/images/home.png" />
<img onclick="index.navNext()" src="/static/images/right.png" />
</div>
{% endblock %}
{% block ad %}
<div class="ad region">
<img src="/static/images/ad.jpg" />
</div>
<div style="clear: both;"></div>
{% endblock %}
{% block content %}
<div id='content'>
<div id="channel">
<div id="screen">
<div id='kvid-screen' width="100%"></div>
</div>
<div id="kdownloadButton"></div>
<div id="kplaylistPanel"></div>
<div id="next-page">
<a class="new-vid" onclick="index.previousPageKD()"><< ៥០ កំរងវីដេអូ</a>
<a class="new-vid" onclick="index.home()">កំរងវីដេអូដើម</a>
<a class="new-vid" onclick="index.nextPageKD()"> កំរងវីដេអូ ៥០ >></a>
</div>
</div>
</div>
{% endblock %}
GitHub: "https://github.com/Sokhavuth/newspaper
Heroku: https://khmerweb-newspaper.herokuapp.com/

Comments
Post a Comment