Skip to content

Commit 171a4a4

Browse files
committed
Merge branch 'master' into releases
2 parents e7fd350 + 9f3e346 commit 171a4a4

31 files changed

+145
-182
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
*.py[cod]
22

3+
.DS_Store
4+
35
# C extensions
46
*.so
57

@@ -36,4 +38,5 @@ nosetests.xml
3638

3739
sessions/
3840
logs/*.log
41+
static/upload/
3942
peewee.db

app.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ def GET(self,url):
181181
if session.logged_in == False:
182182
if m.User.is_setup() == False:
183183
#we have 0 users, ask to add a new one
184-
return render.fullpageindex("Please Create a user",render.createuser())
184+
return render.fullpageindex("Please Create a user",render.createuser(),"")
185185
else:
186186
#show login page
187-
return render.fullpageindex("Please Login to Continue",render.login())
187+
return render.fullpageindex("Please Login to Continue",render.login(),"")
188188
else:
189189
images = m.Image.get_all()
190-
return render.fullpageindex("Logged in as %s" % session.dispname,render.admin(images))
190+
return render.fullpageindex("Logged in as %s" % session.dispname,render.admin(images),render.bottom_admin())
191191

192192
def POST(self,url):
193193
global t_globals
@@ -199,7 +199,7 @@ def POST(self,url):
199199

200200
admin_url = "/admin/%s" % blog_data().adminurl
201201
#ok they found the magic url, good
202-
data = web.input()
202+
data = web.input(nifile={})
203203
method = data.get("method","malformed")
204204
if session.logged_in == False:
205205
#the only thing you can do here is try to login or create a user
@@ -449,7 +449,7 @@ def POST(self):
449449

450450
class Credits:
451451
def GET(self):
452-
return render.fullpageindex("Credits and Attribution",render.makecredits(m.Image.get_all()))
452+
return render.fullpageindex("Credits and Attribution",render.makecredits(m.Image.get_all()),"")
453453

454454

455455

config.py

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
STAT_UPDATES = 60 * 60
2020
####END USER EDITABLE####
2121

22+
valid_upload_ext = [".png",".jpg",".jpeg",".gif",".ico"]
23+
2224
logging.info("emailing errors to %s using server: %s:%s" % (ERROR_EMAIL_ADDR,SMTP_SERVER,SMTP_PORT))
2325

2426

model.py

+58-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import logging
23
logger = logging.getLogger("")
34
import hashlib
@@ -63,7 +64,25 @@ def update_from_input(data):
6364
try:
6465
imageid = data["uimageid"]
6566
image = Image.get(Image.id==int(imageid))
66-
url = data["uiurl"]
67+
68+
#check if a new image was uploaded
69+
#if it is, delete old image, save new image, set new url variable
70+
print data
71+
if "nifile" in data and len(data["nifile"].value) > 0:
72+
#yes new image, delete old
73+
old_file = image.url
74+
logger.debug("User uploaded new file, removing old: %s" % old_file)
75+
if os.path.isfile(old_file):
76+
os.remove(old_file)
77+
else:
78+
logger.debug("Couldn't remove: %s", old_file)
79+
#save new file
80+
resl,msg = save_image(data,update=True)
81+
if resl == None:
82+
return (resl,msg)
83+
else:
84+
image.url = "static/upload/%s" % resl
85+
6786
alt = data["uialt"]
6887
title = data["uititle"]
6988
author = data["uiauthor"]
@@ -76,7 +95,6 @@ def update_from_input(data):
7695
traceback.print_exc()
7796
return (None,"Sorry there was an error: %s" % e.message)
7897

79-
image.url = url
8098
image.alt = alt
8199
image.title = title
82100
image.author = author
@@ -87,8 +105,14 @@ def update_from_input(data):
87105

88106
@staticmethod
89107
def new_from_input(data):
108+
109+
resl,msg = save_image(data)
110+
if resl == None:
111+
return (resl,msg)
112+
113+
#if we fall down here, image saved successfully, resl = image_name for url
90114
try:
91-
url = data["niurl"]
115+
url = "static/upload/%s" % resl
92116
alt = data["nialt"]
93117
title = data["nititle"]
94118
author = data["niauthor"]
@@ -574,8 +598,8 @@ def recur_del(comment):
574598
@staticmethod
575599
def get_comments(postid,show_mod):
576600
if show_mod == False:
577-
count = Comment.select().where(Comment.post == postid & Comment.status == 0).order_by(Comment.rank.asc()).count()
578-
comments = Comment.select().where(Comment.post == postid & Comment.status == 0).order_by(Comment.rank.asc())
601+
count = Comment.select().where(Comment.post == postid).where(Comment.status == 0).order_by(Comment.rank.asc()).count()
602+
comments = Comment.select().where(Comment.post == postid).where(Comment.status == 0).order_by(Comment.rank.asc())
579603
else:
580604
count = Comment.select().where(Comment.post == postid).order_by(Comment.rank.asc()).count()
581605
comments = Comment.select().where(Comment.post == postid).order_by(Comment.rank.asc())
@@ -689,7 +713,7 @@ def update_stats():
689713
return
690714

691715
tp = Post.select(Post.id).count()
692-
tc = Comment.select(Comment.id).count()
716+
tc = Comment.select(Comment.id).where(Comment.status == 0).count()
693717
ta = Post.select(Post.author).distinct().count()
694718
#all_tags returns a list of tuples [(tag,cnt),(tag,cnt)]
695719
popular_tagstr = ""
@@ -841,3 +865,31 @@ def crypt_password_before_save(model_class, instance, created):
841865
instance.salt = create_salt(instance.email)
842866
instance.crypted_password = crypt_password(instance.password,
843867
instance.salt)
868+
869+
870+
def save_image(data,update=False):
871+
#get and save image data
872+
if "nifile" not in data:
873+
return (None, "Image file not found!")
874+
#image stuff
875+
try:
876+
image_name = data["nifile"].filename
877+
#remove bad crap
878+
image_name = re.sub('[^\w\-_\. ]', '_', image_name)
879+
#verify file is good
880+
f_ext = os.path.splitext(image_name)[1].lower()
881+
if f_ext not in config.valid_upload_ext:
882+
return(None,"Invalid image type: %s not allowed!" % f_ext)
883+
884+
#verify file doesn't exist
885+
if update == False and os.path.exists("static/upload/%s" % image_name):
886+
return (None, "Image %s already exists. Use Edit image." % image_name)
887+
888+
f_out = open("static/upload/%s" % image_name,'wb')
889+
f_out.write(data["nifile"].file.read())
890+
f_out.close()
891+
except Exception,e:
892+
traceback.print_exc()
893+
return (None,"Problem processing image upload: %s" % e.message)
894+
895+
return (image_name,"Good")

static/css/styles-basic.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ img.avatar {
172172
border-radius: 10px;
173173
}
174174
img.credit {
175-
width: 150px;
175+
width: auto;
176176
height: auto;
177177
}
178178
.image {

static/img/about-me.png

-195 KB
Binary file not shown.

static/img/avatar.png

-13.1 KB
Binary file not shown.

static/img/bike.png

-34.6 KB
Binary file not shown.

static/img/cat.png

-38.9 KB
Binary file not shown.

static/img/hands-big.png

-191 KB
Binary file not shown.

static/img/hands.png

-36.6 KB
Binary file not shown.
File renamed without changes.

static/img/smartguy.png

-67 KB
Binary file not shown.

static/img/violin.png

-37.7 KB
Binary file not shown.

static/js/app-admin.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//JS for the Admin page
22

33
//
4-
54
$(document).ready(function(){
65
//Load posts when user clicks button
76
$('#manageposts').on('click',function(e) {

static/js/app.js

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
//Set the hidden reply-to field when a user clicks on the reply-to field
55
//also set the title
66
$(document).ready(function(){
7+
//load all the tooltips (if any)
8+
$('[rel=tooltip]').tooltip();
9+
710
$('.replyto').on('click',function(e) {
811
r_to = $(this).attr('commentid');
912
r_title = $('#ctitle'+r_to).html();

static/upload/.gitkeep

Whitespace-only changes.

templates/about.html

+2-37
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,13 @@
11
$def with(me)
2-
<!DOCTYPE html>
3-
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
4-
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
5-
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
6-
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
72
$if me == None:
83
$ name = "Nobody"
94
$ about = "<p>This blog hasn't been configured yet!</p>"
105
$else:
116
$ name = me.name
127
$ about = me.about
13-
<head>
14-
<meta charset="utf-8">
15-
<title>About $:(name)</title>
16-
<meta name="description" content="">
17-
<meta name="viewport" content="width=device-width">
188

19-
<!-- Bootstrap styles -->
20-
<link rel="stylesheet" href="static/css/vendor/bootstrap/bootstrap.css">
21-
<link rel="stylesheet" href="static/css/vendor/bootstrap/bootstrap-theme.css">
22-
<link rel="stylesheet" type="text/css" href="static/css/app.css">
9+
$:render('top', "About " + name)
2310

24-
<!-- Font-Awesome -->
25-
<link rel="stylesheet" href="static/css/vendor/font-awesome/font-awesome.css">
26-
27-
<!-- Google Webfonts -->
28-
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,600|PT+Serif:400,400italic' rel='stylesheet' type='text/css'>
29-
30-
<!-- Styles -->
31-
<link rel="stylesheet" href="static/css/styles-basic.css" id="theme-styles">
32-
33-
<!--[if lt IE 9]>
34-
<link rel="stylesheet" href="css/ie8.css">
35-
<script src="static/js/vendor/google/html5-3.6-respond-1.1.0.min.js"></script>
36-
<![endif]-->
37-
38-
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
39-
40-
<script>window.jQuery || document.write('<script src="static/js/vendor/jquery/jquery-1.9.1.min.js"><\/script>')</script>
41-
42-
<script src="/static/js/app.js"></script>
43-
44-
</head>
4511
<body>
4612
$:render('header','About',None,None)
4713

@@ -123,8 +89,7 @@ <h2>Contact</h2>
12389
</div>
12490
</footer>
12591

126-
<script src="static/js/vendor/bootstrap/bootstrap.min.js"></script>
127-
<script src="static/js/vendor/modernizr/modernizr.js"></script>
92+
$:render('bottom')
12893

12994
</body>
13095
</html>

templates/admin.html

+5-8
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,14 @@ <h3 class="panel-title"> New Post </h3>
119119
<h3 class="panel-title"> New Image</h3>
120120
</div>
121121
<div class="panel-body" style="padding: 20px;">
122-
<form class="form-horizontal" method="post" action="">
122+
<form class="form-horizontal" enctype="multipart/form-data" method="post" action="">
123123
<input type="hidden" name="method" value="newimage">
124124
<div class="form-group">
125125
<div class="row">
126-
<div class="col-md-10">
127-
<label class="control-label" for="niurl">URL:</label>
128-
<input id="niurl" name="niurl" type="text" placeholder="static/images/name.png" class="form-control input-md">
129-
</div>
126+
<div class="col-md-6">
127+
<label class="control-label" for="nifile">Choose Image:</label>
128+
<input id="nifile" name="nifile" type="file" class="form-control input-md">
130129
</div>
131-
<div class="row">
132130
<div class="col-md-6">
133131
<label class="control-label" for="nialt">Alt Text:</label>
134132
<input id="nialt" name="nialt" type="text" placeholder="A Picture" class="form-control input-md">
@@ -141,7 +139,7 @@ <h3 class="panel-title"> New Image</h3>
141139
<div class="row">
142140
<div class="col-md-4">
143141
<label class="control-label" for="niauthor">Author</label>
144-
<input id="niauthor" name="niauthor" type="text" placeholder="Joh doe" class="form-control input-md">
142+
<input id="niauthor" name="niauthor" type="text" placeholder="John doe" class="form-control input-md">
145143
</div>
146144
<div class="col-md-4">
147145
<label class="control-label" for="nilink">Source Url:</label>
@@ -260,4 +258,3 @@ <h3 class="panel-title"> User Settings </h3>
260258
</div>
261259
</div>
262260

263-
<script src="/static/js/app-admin.js"></script>

templates/adminsingleimage.html

+13-6
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@
44
<h4 class="modal-title" id="myModalLabel">Editing Image #$(image.id) - "$(image.title)"</h4>
55
</div>
66
<div class="modal-body">
7-
<form class="form-horizontal" method="post" action="">
7+
<div class="row">
8+
<div class="col-md-5"> </div>
9+
<div class="col-md-2">
10+
<img src="/$image.url" class="img-responsive" alt="$image.alt">
11+
</div>
12+
<div class="col-md-5"> </div>
13+
</div>
14+
<form class="form-horizontal" enctype="multipart/form-data" method="post" action="">
815
<input type="hidden" name="method" value="editimage">
916
<input type="hidden" name="uimageid" value="$(image.id)">
1017
<div class="form-group">
1118
<div class="row">
12-
<div class="col-md-10">
13-
<label class="control-label" for="uiurl">URL:</label>
14-
<textarea id="uiurl" name="uiurl" class="form-control input-md ta-as-input" rows="1">$:(image.url)</textarea>
19+
<div class="col-md-6" rel="tooltip"
20+
data-original-title="If you choose a file here, your old file will be DELETED from the server.">
21+
<label class="control-label" for="nifile">New Image (Optional):</label>
22+
<input id="nifile" name="nifile" type="file" class="form-control input-md">
1523
</div>
16-
</div>
17-
<div class="row">
1824
<div class="col-md-6">
1925
<label class="control-label" for="uialt">Alt Text:</label>
2026
<input id="uialt" name="uialt" type="text" class="form-control input-md" value="$:(image.alt)">
@@ -54,6 +60,7 @@ <h4 class="modal-title" id="myModalLabel">Editing Image #$(image.id) - "$(image.
5460
</div>
5561
<script type="application/javascript">
5662
$$(document).ready(function(){
63+
$$('[rel=tooltip]').tooltip();
5764
$$('.ta-as-input').bind('keypress', function(e) {
5865
if ((e.keyCode || e.which) == 13) {
5966
e.preventDefault();

templates/adminsinglepost.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ <h4 class="modal-title" id="myModalLabel">Editing Post #$(post.id) - "$(post.tit
7676
$ options = ["Allowed","Moderated (Admin Approval)","Disabled"]
7777
<select id="upmod" name="upmod" class="form-control input-md">
7878
$for o in options:
79-
$if loop.index == post.moderate:
79+
$if loop.index0 == post.moderate:
8080
<option value="$(loop.index0)" selected>$o</option>
8181
$else:
8282
<option value="$(loop.index0)">$o</option>

templates/blogdetail.html

+3-37
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,7 @@
11
$def with(blogpost,comment_count,comments,next_post,prev_post,logged_in)
2-
<!DOCTYPE html>
3-
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
4-
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
5-
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
6-
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
7-
<head>
8-
<meta charset="utf-8">
9-
<title>$:(blogpost.title) - Blog</title>
10-
<meta name="description" content="">
11-
<meta name="viewport" content="width=device-width">
122

13-
<!-- Bootstrap styles -->
14-
<link rel="stylesheet" href="static/css/vendor/bootstrap/bootstrap.css">
15-
<link rel="stylesheet" href="static/css/vendor/bootstrap/bootstrap-theme.css">
16-
<link rel="stylesheet" type="text/css" href="static/css/app.css">
3+
$:render('top', blogpost.title +" - Blog")
174

18-
<!-- Font-Awesome -->
19-
<link rel="stylesheet" href="static/css/vendor/font-awesome/font-awesome.css">
20-
21-
<!-- Google Webfonts -->
22-
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,600|PT+Serif:400,400italic' rel='stylesheet' type='text/css'>
23-
24-
<!-- Styles -->
25-
<link rel="stylesheet" href="static/css/styles-basic.css" id="theme-styles">
26-
27-
<!--[if lt IE 9]>
28-
<link rel="stylesheet" href="css/ie8.css">
29-
<script src="static/js/vendor/google/html5-3.6-respond-1.1.0.min.js"></script>
30-
<![endif]-->
31-
32-
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
33-
34-
<script>window.jQuery || document.write('<script src="static/js/vendor/jquery/jquery-1.9.1.min.js"><\/script>')</script>
35-
36-
<script src="/static/js/app.js"></script>
37-
38-
</head>
395
<body>
406
$:render('header','Blog',blogpost.category,blogpost.subcategory)
417

@@ -162,7 +128,7 @@ <h1>$:(blogpost.title)</h1>
162128
</div>
163129
</footer>
164130

165-
<script src="static/js/vendor/bootstrap/bootstrap.min.js"></script>
166-
<script src="static/js/vendor/modernizr/modernizr.js"></script>
131+
$:render('bottom')
132+
167133
</body>
168134
</html>

templates/bottom.html

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script src="/static/js/vendor/jquery/jquery-1.9.1.min.js"></script>
2+
<script src="/static/js/vendor/bootstrap/bootstrap.min.js"></script>
3+
<script src="/static/js/vendor/modernizr/modernizr.js"></script>
4+
<script src="/static/js/app.js"></script>

templates/bottom_admin.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script src="/static/js/app-admin.js"></script>

0 commit comments

Comments
 (0)