Skip to content

Commit 8eed655

Browse files
OwnerOwner
authored andcommitted
new post, login/logout, style changes
1 parent da4c8e3 commit 8eed655

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2642
-2199
lines changed

antiquated/index (copy).php

Lines changed: 0 additions & 55 deletions
This file was deleted.

antiquated/index.php.bak.php

Lines changed: 0 additions & 82 deletions
This file was deleted.

antiquated/index.php.bak2

Lines changed: 0 additions & 52 deletions
This file was deleted.

blog_class.py

100644100755
Lines changed: 89 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import post_class, comment_class
1+
import post_class, comment_class, image_class
22
import re, os, cherrypy
33

44
class Blog(object):
@@ -8,10 +8,18 @@ def __init__(self, author = "Anonymous", url = "http://127.0.0.1"):
88
self.url = url
99
self.getPosts()
1010

11+
def isAuth(self):
12+
if cherrypy.session.get('authenticated') == True:
13+
return True
14+
else:
15+
return False
16+
1117
def getPosts(self):
1218
self.posts = []
1319
expression = re.compile('\d*')
14-
for file in os.listdir(os.getcwd() + '/posts/'):
20+
post_filenames = os.listdir(os.getcwd() + '/posts/')
21+
post_filenames.sort(reverse=True)
22+
for file in post_filenames:
1523
if expression.match(file) != None:
1624
currentPost = post_class.Post()
1725
filehandle = open('posts/' + file, 'r')
@@ -22,76 +30,134 @@ def getPosts(self):
2230

2331
def index(self):
2432
page = []
25-
header = open('theme/header.php', 'r')
26-
page.append(header.read())
27-
header.close()
33+
# read header
34+
try:
35+
header = open('theme/header.html', 'r')
36+
page.append(header.read())
37+
finally:
38+
header.close()
39+
40+
if self.isAuth():
41+
page.append('<div class="createnew">+</div>')
2842

43+
# iterate through post list
2944
for post in self.posts:
3045
page.append(post.createPost())
3146

32-
footer = open('theme/footer.php', 'r')
33-
page.append(footer.read())
34-
footer.close()
47+
# read footer
48+
try:
49+
footer = open('theme/footer.html', 'r')
50+
page.append(footer.read())
51+
finally:
52+
footer.close()
53+
54+
# join the pieces into a single string and return
3555
page = '\n\n'.join(page)
3656
return page
3757
index.exposed = True
3858

3959
def about(self):
40-
f = open('pages/about.html', 'r')
41-
contents = f.read()
42-
f.close()
60+
try:
61+
f = open('pages/about.html', 'r')
62+
contents = f.read()
63+
finally:
64+
f.close()
4365
return contents
4466
about.exposed = True
4567

4668
def resume(self):
47-
f = open('pages/resume.html', 'r')
48-
contents = f.read()
49-
f.close()
69+
try:
70+
f = open('pages/resume.html', 'r')
71+
contents = f.read()
72+
finally:
73+
f.close()
5074
return contents
5175
resume.exposed = True
5276

5377
def post(self, id):
54-
header = open('theme/header.php', 'r')
55-
yield header.read()
56-
header.close()
78+
try:
79+
header = open('theme/header.html', 'r')
80+
yield header.read()
81+
finally:
82+
header.close()
5783

5884
for post in self.posts:
5985
if post.date == id:
6086
yield post.createPost(True)
6187
break
6288

63-
footer = open('theme/footer.php', 'r')
64-
yield footer.read()
65-
footer.close()
89+
try:
90+
footer = open('theme/footer.html', 'r')
91+
yield footer.read()
92+
finally:
93+
footer.close()
6694
post.exposed = True
6795

6896
def ajaxedit(self, id, width, height):
97+
if not self.isAuth():
98+
raise cherrypy.HTTPRedirect('/')
99+
69100
for post in self.posts:
70101
if post.date == id:
71102
return post.createEditor(width, height)
72103
ajaxedit.exposed = True
73104

105+
def loginwidget(self):
106+
try:
107+
f = open('theme/loginwidget.html')
108+
yield f.read()
109+
finally:
110+
f.close()
111+
loginwidget.exposed = True
112+
113+
def login(self, username, password):
114+
if username == 'paul' and password == 'ponies':
115+
cherrypy.session['authenticated'] = True
116+
raise cherrypy.HTTPRedirect('/')
117+
login.exposed = True
118+
119+
def logout(self):
120+
cherrypy.session.clear()
121+
raise cherrypy.HTTPRedirect('/')
122+
logout.exposed = True
123+
74124
@cherrypy.tools.staticdir(root=os.getcwd(), dir='files')
75125
def files(self):
76126
yield '<h2>Browsing directory /files</h2>\n'
77127
for dirpath, dirnames, filenames in os.walk(os.getcwd()+'/files'):
78128
filenames.sort()
79-
# yield dirnames
80-
# for dirname in dirnames:
81-
# yeild '<a href="/files/%s">%s</a><br>' % (dirname, dirname)
82129
for filename in filenames:
83130
yield '<a href="/files/%s">%s</a><br>' % (filename, filename)
84131
files.exposed = True
85132

86133
def edit(self, post_title, post_body, post_date):
134+
if not self.isAuth():
135+
raise cherrypy.HTTPRedirect('/')
87136
for post in self.posts:
88137
if post.date == post_date:
89138
post.editPost(post_title, post_body)
90139
return 'Updated.'
140+
141+
# if it is not an existing post, then save it as a new post.
142+
post = post_class.Post()
143+
post.editPost(post_title, post_body)
144+
# add that post to the post cache
145+
self.getPosts()
146+
return 'New Post Saved.'
147+
#raise cherrypy.HTTPRedirect('/')
91148
edit.exposed = True
92149

93150
def ajaxget(self, id):
151+
if not self.isAuth():
152+
raise cherrypy.HTTPRedirect('/')
94153
for post in self.posts:
95154
if post.date == id:
96155
return post.createPost(False)
97156
ajaxget.exposed = True
157+
158+
def ajaxnewpost(self, width, height):
159+
if not self.isAuth():
160+
raise cherrypy.HTTPRedirect('/')
161+
post = post_class.Post(title='New Post', body='This is a new post')
162+
return post.createEditor(width, height)
163+
ajaxnewpost.exposed = True

blog_class.pyc

2.19 KB
Binary file not shown.

comment_class.pyc

66 Bytes
Binary file not shown.

files

Lines changed: 0 additions & 1 deletion
This file was deleted.

files-real/photos

Lines changed: 0 additions & 1 deletion
This file was deleted.

files-real/ponies.html

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)