Adding Setting Functionality
#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[2] vdict['book_max_post'] = setting[3] vdict['blog_title'] = setting[4] vdict['blog_description'] = setting[5] vdict['secret_key'] = setting[6]
#controllers/dashboard/setting.py import config, copy, uuid, datetime, importlib from flask import render_template, session, redirect, request from lib import Lib from models.dashboard.settingdb import Settingdb class Setting(): def __init__(self): self.lib = Lib() self.settingdb = Settingdb() def get_set(self): vdict = copy.deepcopy(config.vdict) vdict['blog_title'] = 'កំណត់ទំរង់លក្ខណៈ' if (request.method == "POST") and ('logged-in' in session): max_post = request.form['fmax-post'] max_category = request.form['fmax-category'] max_post_category = request.form['fmax-post-category'] max_book = request.form['fbook-post'] blog_title = request.form['fblog-title'] blog_description = request.form['fblog-description'] secret_key = request.form['fsecret-key'] if self.settingdb.select(): self.settingdb.update(max_post, max_category, max_post_category, max_book, blog_title, blog_description, secret_key) else: self.settingdb.insert(max_post, max_category, max_post_category, max_book, blog_title, blog_description, secret_key) importlib.reload(config) vdict['setting'] = self.settingdb.select() return render_template('dashboard/setting.html', data=vdict) elif 'logged-in' in session: setting = self.settingdb.select() if setting: vdict['setting'] = setting return render_template('dashboard/setting.html', data=vdict) else: return redirect('/login/')
<!--templates/dasboard/setting.html--> {% extends 'dashboard/dashboard.html' %} {% block head %} {{ super() }} <link href="/static/styles/setting.css" rel="stylesheet" > {% endblock %} {% block content %} <form id='setting' action='/dashboard/setting/' method="POST" > <a>ចំនួនការផ្សាយក្នុងទំព័រគ្រប់គ្រង:</a><input value="{{ data['setting'][0] }}" name="fmax-post" type="text" required /> <a>ចំនួនជំពូកក្នុងទំព័រគ្រប់គ្រង:</a><input value="{{ data['setting'][1] }}" type="text" name="fmax-category" required /> <a>ចំនួនការផ្សាយក្នុងជំពូកនិមួយៗ:</a><input value="{{ data['setting'][2] }}" type="text" name="fmax-post-category" required /> <a>ចំនួនសៀវភៅនៅទំព័រមុខ:</a><input type='text' value="{{ data['setting'][3] }}" name="fbook-post" required /> <a>ចំណងជើងគេហទំព័រ:</a><input type='text' value="{{ data['setting'][4] }}" name="fblog-title" required /> <a>សេចក្តីអធិប្បាយគេហទំព័រ:</a><input type='text' value="{{ data['setting'][5] }}" name="fblog-description" required /> <a>កូដសំងាត់:</a><input type='text' value="{{ data['setting'][6] }}" name="fsecret-key" required /> <a></a><input id="submit" class="bottom-widget" type="submit" value="ចុះផ្សាយ"> </div> </form> <div id="message">{{ data['message'] }}</div> {% endblock %} {% block item_listing %} {% endblock %}
/*static/styles/setting.css*/ #setting{ display: grid; grid-template-columns: 30% 40%; padding: 20px; grid-gap: 5px; align-items: center; } #setting a{ text-align: right; } #setting input{ font: 14px/1.5 Vidaloka, OdorMeanChey; padding:2px; } #setting input{ padding: 5px; }
GitHub: "https://github.com/Sokhavuth/E-Learning
Heroku: https://khmerweb-elearning.herokuapp.com/
Comments
Post a Comment