Posts

Showing posts from December, 2020

Adding Menu to Single Movie Template

Image
<!--templates/dashboard/movie.html--> {% extends 'dashboard/index.html' %} {% block head %} {{ super() }} <link href="/static/styles/dashboard/movie.css" rel="stylesheet"> <script src="/static/scripts/dashboard/movie.js"></script> {% endblock %} {% block content %} <form id='movie' action='/dashboard/movie/' method="POST" > {% if 'movie' in data %} <input id='movie-title' value="{{ data['movie'][3] }}" name="ftitle" type="text" placeholder="ចំណង​ជើងភាពយន្ត" required /> <textarea name="fcontent" id="editor" >{{ data['movie'][5] }}</textarea> {% else: %} <input id='movie-title' value="" ...

Creating Movie Category Template

Image
#controllers/country.py import config, copy, lib from flask import render_template, redirect, session from models.moviedb import Moviedb class Country(): def __init__(self): self.lib = lib.Lib() self.moviedb = Moviedb() def get_movie(self, label): vdict = copy.deepcopy(config.vdict) vdict['site_title'] = '​ប្រភេទ​ភាពយន្ត' session['page'] = 0 session['label'] = label vdict['movies'] = self.moviedb.select(vdict['country_max_movie'], label=label) vdict['thumbs'] = self.lib.get_thumbs(vdict['movies'], 5, type='movie') return render_template('country.html', data=vdict) def load_movie(self): vdict = copy.deepcopy(config.vdict) session['page'] += 1 vdict['movies'] = self.moviedb.select(vdict['country_max_movie'], page=session['page'], label=session['label']) vdict['thumbs'] = self.lib.get_thumbs(vdict[...

Adding Single Movies to Homepage

Image
#controllers/home.py import config, copy, lib from flask import render_template, redirect from models.moviedb import Moviedb class Home(): def __init__(self): self.lib = lib.Lib() self.moviedb = Moviedb() def get_youtube(self): self.vdict = copy.deepcopy(config.vdict) self.get_movie() return render_template('index.html', data=self.vdict) def get_movie(self, type=None): self.vdict['movies'] = self.moviedb.select(self.vdict['home_max_movie']) self.vdict['thumbs'] = self.lib.get_thumbs(self.vdict['movies'], 5, type='movie') <!--templates/index.html--> {% extends "base.html" %} {% block head %} {{ super() }} <link href="/static/styles/index.css" rel="stylesheet" > <link href="/static/styles/movie.css" rel="stylesheet" > <script src="/static/scripts/index.js"></script> <script src="/static/scripts/movie....

Adding Frontend Single Movie Template

Image
#controllers/movie.py import config, copy, lib from flask import render_template, redirect from models.moviedb import Moviedb from models.userdb import Userdb class Movie(): def __init__(self): self.lib = lib.Lib() self.userdb = Userdb() self.moviedb = Moviedb() def get_movie(self, id): vdict = copy.deepcopy(config.vdict) vdict['site_title'] = '​ភាពយន្ត​ទោល' vdict['movies'] = self.moviedb.select(vdict['random_max_post'], random=id) vdict['thumbs'] = self.lib.get_thumbs(vdict['movies'], 5, type='movie') vdict['movie'] = self.moviedb.select(id=id) date = (vdict['movie'][6]).strftime('%d/%m/%Y') time = (vdict['movie'][7]).strftime('%H:%M:%S') vdict['datetime'] = (date, time) vdict['author'] = self.userdb.select(username=vdict['movie'][8]) return render_template('movie.html', data=vdict) #models/use...

Adding Single Movie CRUD Functionality

Image
#controllers/dashboard/movie.py import config, copy, lib, datetime, uuid from flask import render_template, session, request, redirect from models.userdb import Userdb from models.moviedb import Moviedb class Movie(): def __init__(self): self.userdb = Userdb() self.lib = lib.Lib() self.moviedb = Moviedb() def get_post(self): vdict = copy.deepcopy(config.vdict) vdict['site_title'] = "ទំព័រ​ភាពយន្តទោល" vdict['datetime'] = self.lib.get_timezone() session['page'] = 0 if (request.method == "POST") and ('logged-in' in session): vid = request.form['fvid'] type = request.form['ftype'] title = request.form['ftitle'] content = request.form['fcontent'] country = request.form['fcountry'] date = request.form['fdate'] time = request.form['ftime'] author = session['logged-in'] try: d...

Adding User Crud Functionality

Image
#controllers/dashboard/user.py import config, copy, lib, datetime from flask import render_template, session, request, redirect from models.userdb import Userdb class User(): def __init__(self): self.userdb = Userdb() self.lib = lib.Lib() def signup(self): vdict = copy.deepcopy(config.vdict) vdict['site_title'] = "ទំព័រ​អ្នក​ប្រើប្រាស់" vdict['datetime'] = self.lib.get_timezone() session['page'] = 0 if request.method == "POST": username = request.form['fusername'] content = request.form['fcontent'] password = request.form['fpassword'] role = request.form['frole'] date = request.form['fdate'] time = request.form['ftime'] email = request.form['femail'] if not email: vdict['message'] = 'ចាំបាច់​ត្រូវ​មាន​ E-MAIL!' return render_template('dashboard/user.html', data=v...

Creating Dashboard Areas

Image
#routes/dashboard.py from flask_classful import FlaskView, route from controllers.dashboard.signup import Signup from controllers.dashboard.index import Index class Dashboard(FlaskView): def __init__(self): super().__init__() self.signup = Signup() self.index = Index() @route('/') def dashboard_index(self): return self.index.index() @route('/logout/') def logout(self): return self.index.logout() @route('/signup/', methods={'GET', 'POST'}) def dashboard_signup(self): return self.signup.signup() #templates/dashboard/index.py import config, copy, lib from flask import render_template, request, session, redirect from models.userdb import Userdb class Index(): def __init__(self): self.userdb = Userdb() def index(self): vdict = copy.deepcopy(config.vdict) vdict['site_title'] = "ទំព័រ​គ្រប់គ្រង" if 'logged-in' in session: return render_template(...

Adding Login Functionality

Image
#routes/index.py import config, copy from flask import render_template from flask_classful import FlaskView, route from controllers.login import Login class Index(FlaskView): def __init__(self): super().__init__() self.login = Login() @route('/') def index(self): vdict = copy.deepcopy(config.vdict) return render_template('index.html', data=vdict) @route('/login/', methods=['GET', 'POST']) def check_user(self): return self.login.check_user() #controllers/login.py import config, copy, lib from flask import render_template, redirect, request, session from datetime import datetime from models.userdb import Userdb class Login(): def __init__(self): self.userdb = Userdb() def set_root(self): vlib = lib.Lib() vdatetime = vlib.get_timezone() date = datetime.strptime(vdatetime[0], "%d/%m/%Y") time = datetime.strptime(vdatetime[1], '%H:%M:%S') self.userdb.insert('...

Connecting to YouTube Channel

Image
#main.py from flask import Flask from routes.index import Index app = Flask(__name__) index = Index() index.register(app, route_base='/') if __name__ == '__main__': app.run(debug=True) #routes/index.py from flask import render_template from flask_classful import FlaskView, route class Index(FlaskView): def __init__(self): super().__init__() @route('/') def index(self): return render_template('index.html', data={'siteTitle':'ទូរទស្សន៍​យើង'}) <!--templates/index.html--> {% extends "base.html" %} {% block head %} {{ super() }} <link href="/static/styles/index.css" rel="stylesheet" > <script src="/static/scripts/index.js"></script> {% endblock %} {% block channel %} <div class="channel region"> <div class="channel-outer"> <iframe src="https://www.youtube.com/embed/videoseries?list=UUHwYHdX37UUt6d9...

Styling the Base Template

Image
#controllers/index.py from flask import render_template from flask_classful import FlaskView, route class Index(FlaskView): def __init__(self): super().__init__() @route('/') def index(self): return render_template('index.html', data={'siteTitle':'ទូរទស្សន៍​យើង'}) <!--templates/base.html--> <!DOCTYPE html> <html> <head> {% block head %} <meta charset="UTF-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>{{data['siteTitle']}}</title> <script src="/static/scripts/jQuery.js"></script> <script src='/static/scripts/base.js'></script> <link href="/static/styles/base.css" rel="stylesheet"> <link href="/static/fonts/setup.css" rel='stylesheet'> <link href=...

Boilerplate Code

Image
#main.py from flask import Flask from controllers.index import Index app = Flask(__name__) index = Index() index.register(app, route_base='/') if __name__ == '__main__': app.run(debug=True) #controllers/index.py from flask import render_template from flask_classful import FlaskView, route class Index(FlaskView): def __init__(self): super().__init__() @route('/') def index(self): return render_template('index.html', data={'blogTitle':'ទូរទស្សន៍​យើង'}) <!--templates/index.html--> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>{{data['blogTitle']}}</title> <script src="/static/scripts/jQuery.js"></script> <script src='/static/scripts/index.js'></script> <link href...

Adding Search Functionality

Image
#controllers/index.py import config, copy, json from flask import render_template, redirect, session, request from flask_classful import FlaskView, route from controllers.post import Post from controllers.page import Page from controllers.book import Book from controllers.user import User from controllers.search import Search class Index(FlaskView): def __init__(self): self.post = Post() self.page = Page() self.book = Book() self.user = User() self.search = Search() @route('/') def index(self): session['page'] = 0 vdict = self.post.get_post() vdict['books'] = self.book.get_post_book() return render_template('index.html', data=vdict) @route('/panel') def get_post(self): nav = request.args.get('nav', 0, type=str) if nav == 'previous': session['page'] += 1 elif nav == 'next...

Adding Search Functionality

Image
#controllers/dashboard/dashboard.py from flask import session from flask_classful import FlaskView, route from controllers.dashboard.category import Category from controllers.dashboard.post import Post from controllers.dashboard.page import Page from controllers.dashboard.book import Book from controllers.dashboard.upload import Upload from controllers.dashboard.user import User from controllers.dashboard.setting import Setting from controllers.dashboard.search import Search class Dashboard(FlaskView): def __init__(self): self.cat = Category() self.post = Post() self.page = Page() self.book = Book() self.upload = Upload() self.user = User() self.setting = Setting() self.search = Search() @route('/favicon.ico') def favicon(self): redirect('/static/images/site_logo.png') @route('/', methods=['GET', 'POST']) def index(self): session['page'] = 0 return self.post.get_post()...

Adding Setting Functionality

Image
#config.py from models.dashboard.settingdb import Settingdb vdict = {} vdict['message'] = '' vdict['page'] = 0 settingdb = Settingdb() setting = settingdb.select() if not setting: vdict['dashboard_max_post'] = 5 vdict['dashboard_max_category'] = 5 vdict['post_max_category'] = 20 vdict['book_max_post'] = 8 vdict['blog_title'] = "សាលារៀនពីចំងាយ" vdict['blog_description'] = "ចេះ​ពី​រៀន​ មាន​ពី​រក" vdict['secret_key'] = 'c89f675a9b7c74ffca5a44a0cf3e3acc' settingdb.insert(vdict['dashboard_max_post'], vdict['dashboard_max_category'], vdict['post_max_category'], vdict['book_max_post'], vdict['blog_title'], vdict['blog_description'], vdict['secret_key']) else: vdict['dashboard_max_post'] = setting[0] vdict['dashboard_max_category'] = setting[1] vdict['post_max_category'] = setting...