Creating Posting Page
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!--views/dashboard/home.tpl-->
%include('./dashboard/partials/header.tpl')
 
<style>
  #content{
    min-height: 350px;
    background: white;
    padding: 0;
    box-sizing: border-box;
  }
 
  #content .ck-editor__editable {
    min-height: 350px !important;
  }
 
  #content #post-title{
    width: 100%;
    box-sizing: border-box;
    padding: 5px 10px;
    font: 16px/1.5 Koulen;
    opacity: .4;
  }
 
  #content #bottombar{
    background: #ebebeb;
    padding: 5px;
    border: 1px solid #bebbbb;
  }
 
  #content #bottombar .bottom-widget{
    font: 14px/1.5 OdorMeanChey;
    height: 30px;
  }
 
  #content #bottombar input:hover{
    cursor: pointer;
  }
 
  #content #bottombar #category{
    min-width: 80px;
  }
 
  #content #post-date, #content #post-time{
    height: 24px !important;
    font:bold 14px/1.5 'Lucida Sans' !important;
    width: 100px;
  }
 
  #content #video{
    min-width: 70px;
  }
</style>
 
<div  id='main' class='main region'>
 
  %include('./dashboard/partials/sidebar.tpl')
 
  <section id='content' class='content'>
     
    <form action="/posting" method="post">
      <input id="post-title" name="post-title" type="text" placeholder="ចំណង​ជើង" />
      <textarea name="content" id="editor"></textarea>
      <div id="bottombar">
        <input class="bottom-widget" type="submit" value="ចុះ​ផ្សាយ">
        <select class="bottom-widget" id="category" name="category">
          <option>News</option>
          <option>Python</option>
          <option>Node.js</option>
          <option>PHP</option>
        </select>
        <input id="post-date" value="{{data['datetime'][0]}}" class="bottom-widget" type="text" name="post-date" />
        <input id="post-time" value="{{data['datetime'][1]}}" class="bottom-widget" type="text" name="post-time" />
        <input id="video" class="bottom-widget" type="button" value="VIDEO" />
      </div>
    </form>
    <script src="/static/scripts/ckeditor/config.js"></script>
 
  </section><!--content-->
</div><!--main-->
 
%include('./dashboard/partials/footer.tpl')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#controllers/login.py
import config
from pytz import timezone
from datetime import datetime
from bottle import route, template, request, response, redirect
 
def checkLogin(username, password):
  if (username == 'Guest') and (password == 'password'):
    return True
  else:
    return False
 
def getTimeZone():
  khtz = timezone('Asia/Phnom_Penh')
  date = datetime.now().astimezone(tz=khtz).strftime('%d-%m-%Y')
  time = datetime.now().astimezone(tz=khtz).strftime('%H:%M')
  return (date, time)
 
@route('/login', method="POST")
def user():
  username = request.forms.get('fusername')
  password = request.forms.get('fpassword')
 
  if checkLogin(username, password):
    response.set_cookie("logged-in", username, secret='some-secret-key')
   
  redirect('/login')
 
 
@route('/login')
def login():
  username = request.get_cookie("logged-in", secret='some-secret-key')
  if username:
    config.kargs['blogTitle'] = "ទំព័រ​គ្រប់គ្រង"
    config.kargs['datetime'] = getTimeZone()
    return template('dashboard/home', data=config.kargs)
  else:
    return template('login', data=config.kargs)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
ClassicEditor
        .create( document.querySelector( '#editor' ), {
          toolbar: ['fontfamily', 'fontsize', 'fontcolor', 'bold', 'italic',
          'bulletedList', 'indent', 'outdent', 'numberedList', 'link', 'blockQuote',
          'code', 'codeblock', 'imageinsert', 'mediaembed', 'undo', 'redo' ],
          fontFamily: {
            options: [
              'ឧត្តមាន​ជ័យ, OdorMeanChey', 'អក្សរដៃ, HandWriting',
              'គូលេន, Koulen', 'ក្រូច​ឆ្នារ, Limonf3',
              'បាយ័ន, Bayon', 'ក្រសាំង, Rooster',
              'មូល, Moul',
              'Arial, Helvetica, sans-serif',
              'Courier New, Courier, monospace',
              'Georgia, serif',
              'Lucida Sans Unicode, Lucida Grande, sans-serif',
              'Tahoma, Geneva, sans-serif',
              'Times New Roman, Times, serif',
              'Trebuchet MS, Helvetica, sans-serif',
              'Verdana, Geneva, sans-serif',
            ],
            supportAllValues: true
          },
           
          fontSize: {
            options: [
                9,
                11,
                13,
                'default',
                17,
                19,
                21
            ],
            supportAllValues: true
          },
        })
        .catch( error => {
          console.error( error );
        });

GitHub: https://github.com/Sokhavuth/kwblog
Heroku: https://khmerweb-kwblog.herokuapp.com/