Skip to content

Commit

Permalink
'Alias' is added.
Browse files Browse the repository at this point in the history
  • Loading branch information
alg0002 committed May 30, 2011
1 parent 198e58d commit 7a39aa5
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 22 deletions.
88 changes: 75 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
DIRECTORY_INDEX='index.html'
# Display count per page
COUNT_PER_PAGE=20
# Others
NO_NAME='(No name)'

class Content(db.Model):
# key_name = 'e'+path
Expand Down Expand Up @@ -73,14 +75,21 @@ def get(self):
if self.returnfile(c):
return
elif c.entitytype=='alias':
c=get_content(c.aliastarget)
if c and (c.public or users.is_current_user_admin()):
if c.entitytype=='text':
if self.returntext(c):
return
elif c.entitytype=='file':
if self.returnfile(c):
return
if c.aliastarget and c.aliastarget.startswith('http://'):
from google.appengine.api import urlfetch
result=urlfetch.fetch(url=c.aliastarget)
self.response.headers["Content-Type"]=result.headers["Content-Type"]
self.response.out.write(result.content)
return
else:
c=get_content(c.aliastarget)
if c and (c.public or users.is_current_user_admin()):
if c.entitytype=='text':
if self.returntext(c):
return
elif c.entitytype=='file':
if self.returnfile(c):
return
self.error(404)
def returntext(self,c):
if c.contenttype:
Expand All @@ -101,9 +110,38 @@ def returntext(self,c):
self.response.out.write(c.textcontent)
return True
def returnfile(self,c):
b=c.blobcontent
if c.contenttype:
self.response.headers["Content-Type"]=c.contenttype
self.response.out.write(c.blobcontent)
w=self.request.get(u'w')
h=self.request.get(u'h')
if w.isdigit():
w=int(w)
else:
w=0
if h.isdigit():
h=int(h)
else:
h=0
if w>0 or h>0:
from google.appengine.api import images
img=images.Image(b)
if w>0 and h>0:
img.resize(width=w,height=h)
elif w>0:
img.resize(width=w)
else:
img.resize(height=h)
imgtypes={'image/jpeg':images.JPEG,
'image/png' :images.PNG,
# images.WEBP,
'image/bmp' :images.BMP,
'image/gif' :images.GIF,
'image/x-icon':images.ICO,
'image/tiff':images.TIFF,
}
b=img.execute_transforms(output_encoding=imgtypes[c.contenttype])
self.response.out.write(b)
return True

class ListHandler(webapp.RequestHandler):
Expand Down Expand Up @@ -162,8 +200,9 @@ def get(self):
elif c.entitytype=='alias':
self.redirect(ALIAS_PATH+'?target='+self.request.get('target'))
return
errormsg=self.request.get(u'errormsg')
path=os.path.join(os.path.dirname(__file__), 'template_admin.html')
self.response.out.write(template.render(path, {'CURRENT_PATH':EDIT_PATH,'LIST_PATH':LIST_PATH,'EDIT_PATH':EDIT_PATH,'UPLOAD_PATH':UPLOAD_PATH,'ALIAS_PATH':ALIAS_PATH,'SETTING_PATH':SETTING_PATH,'modify':c}))
self.response.out.write(template.render(path, {'CURRENT_PATH':EDIT_PATH,'LIST_PATH':LIST_PATH,'EDIT_PATH':EDIT_PATH,'UPLOAD_PATH':UPLOAD_PATH,'ALIAS_PATH':ALIAS_PATH,'SETTING_PATH':SETTING_PATH,'modify':c,'errormsg':errormsg}))
return
path=os.path.join(os.path.dirname(__file__), 'template_admin.html')
q=Content.all()
Expand Down Expand Up @@ -197,6 +236,8 @@ def post(self):
public=(self.request.get('public') == 'on'),
entitytype='text')
c.name=self.request.get('name')
if not c.name:
c.name=NO_NAME
c.encoding=self.request.get('encoding')
c.textcontent=self.request.get('content')
import mimetypes
Expand All @@ -210,6 +251,8 @@ def post(self):
else:
c.templatefile=None
c.description=self.request.get('description')
if not c.description:
c.description=''
c.setparentinfo()
c.put()
self.redirect(LIST_PATH)
Expand All @@ -225,7 +268,8 @@ def get(self):
c=get_content(self.request.get('target'))
else:
c=None
self.response.out.write(template.render(path, {'CURRENT_PATH':UPLOAD_PATH,'LIST_PATH':LIST_PATH,'EDIT_PATH':EDIT_PATH,'UPLOAD_PATH':UPLOAD_PATH,'ALIAS_PATH':ALIAS_PATH,'SETTING_PATH':SETTING_PATH,'modify':c}))
errormsg=self.request.get(u'errormsg')
self.response.out.write(template.render(path, {'CURRENT_PATH':UPLOAD_PATH,'LIST_PATH':LIST_PATH,'EDIT_PATH':EDIT_PATH,'UPLOAD_PATH':UPLOAD_PATH,'ALIAS_PATH':ALIAS_PATH,'SETTING_PATH':SETTING_PATH,'modify':c,'errormsg':errormsg}))
return
self.redirect(users.create_login_url(self.request.uri))
def post(self):
Expand Down Expand Up @@ -259,15 +303,29 @@ def post(self):
entitytype='file',
blobcontent=ffile,
lastupdate=datetime.datetime.now())
if not c.name:
c.name=NO_NAME
import mimetypes
mtype,stype=mimetypes.guess_type(c.path)
if mtype:
c.contenttype=str(mtype)
else:
c.contenttype=None
if c.path.endswith(".ico"):
c.contenttype="image/x-icon"
else:
c.contenttype=None
c.description=self.request.get('description')
if not c.description:
c.description=''
c.setparentinfo()
c.put()
try:
from google.appengine.runtime import apiproxy_errors
c.put()
except apiproxy_errors.RequestTooLargeError:
c.blobcontent=None
c.put()
self.redirect(UPLOAD_PATH+'?target='+c.path+'&errormsg=Too%20large%20file')
return
self.redirect(LIST_PATH)
return
self.redirect(users.create_login_url(self.request.uri))
Expand Down Expand Up @@ -310,8 +368,12 @@ def post(self):
public=(self.request.get('public') == 'on'),
entitytype='alias')
c.name=self.request.get('name')
if not c.name:
c.name=NO_NAME
c.aliastarget=self.request.get('aliastarget')
c.description=self.request.get('description')
if not c.description:
c.description=''
c.setparentinfo()
c.put()
self.redirect(LIST_PATH)
Expand Down
58 changes: 53 additions & 5 deletions template.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,62 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>{{ name }}</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{{ name }} - alglab.net</title>
<link rel="stylesheet" type="text/css" href="/default.css">
</head>
<body>
<div>{{ description }}</div>
<div>
<div id="navi">
<table>
<tr>
<td style="width:550px;">{{ description }}</td>
<td>
<form action="http://www.google.com/cse" method="get" style="margin-top:0em;margin-bottom:0em;">
<input type="hidden" name="cx" value="017470105403622007220:xfmsgzurk0u">
<input type="hidden" name="ie" value="UTF-8">
<input type="text" size="20" name="q" value="">
<input type="submit" value="検索" style="font-size:0.7em;">
</form>
</td>
</tr>
</table>
</div>
<div id="header">
<h1>alglab.net</h1>
</div>
<div id="middle">
<div id="main">
{{ text }}
</div>
<div style="font-size:0.75em; text-align:right;">
<p>{{ lastupdate|date:"Y/m/d H:i" }}</p>
<div id="sub">
<div id="ad">
<h5>広告</h5>
<p>
<!-- ad start -->
<script type="text/javascript"><!--
in_uid = '241937';
in_templateid = '11025';
in_charset = 'UTF-8';
in_group = 'DefaultGroup';
in_matchurl = '';
in_HBgColor = 'FFFFFF';
in_HBorderColor = 'B4D0DC';
in_HTitleColor = '3399FF';
in_HTextColor = '6F6F6F';
in_HUrlColor = '000080';
frame_width = '160';
frame_height = '600';
--></script>
<script type='text/javascript' src='http://cache.microad.jp/send0100.js'></script>
<p>マイクロアドBTパートナー登録は<a href="https://associate.microad.jp/associate/login?ID=241937" target="_blank">こちら</a>から</p>
<!-- ad end -->
</p>
</div>
</div>
</div>
<div id="footer">
最終更新:{{ lastupdate|date:"Y/m/d H:i" }}<br>
Copyright(C) 2010-2011 alglab.net, all rights reserved.<br><a href="./contact.html"><img src="./img/mail.png" alt="alg_dot_info_atmark_gmail_dot_com"></a>
</div>
</body>
</html>
14 changes: 10 additions & 4 deletions template_admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
padding: 2px;
border: 1px solid #99A8B0;
}
span.errormsg {
border: 0px;
color: #FF0000;
font-weight: bold;
}
span.current {
background-color: #CCE0FF;
}
Expand Down Expand Up @@ -156,6 +161,7 @@ <h1>Simple Site Manager For Google App Engine</h1>
</div>
</div>
<div id="main">
{% if errormsg %}<span class="errormsg">{{ errormsg }}</span>{% endif %}
{% ifequal CURRENT_PATH LIST_PATH %}
<div id="contentslist">
<h2>List of contents</h2>
Expand Down Expand Up @@ -190,9 +196,9 @@ <h2>Edit content</h2>
<tr><td>name:</td><td><input type="text" name="name"{% if modify %} value="{{ modify.name|escape }}"{% endif %}></td></tr>
{% if modify %}<tr><td>old path:</td><td><input type="text" name="oldpath" value="{{ modify.path|escape }}" readonly></td></tr>{% endif %}
<tr><td>{% if modify %}new {% endif %}path:</td><td><input type="text" name="path"{% if modify %} value="{{ modify.path|escape }}"{% endif %}></td></tr>
<tr><td>public:</td><td><input type="checkbox" name="public"{% if modify and modify.public %} checked{% endif %}></td></tr>
<tr><td>public:</td><td><input type="checkbox" name="public"{% if modify %}{% if modify.public %} checked{% endif %}{% else %} checked{% endif %}></td></tr>
<tr><td>encoding:</td><td><select name="encoding"><option{% ifequal modify.encoding 'UTF-8' %} selected{% endifequal %}>UTF-8</option><option{% ifequal modify.encoding 'Shift_JIS' %} selected{% endifequal %}>Shift_JIS</option><option{% ifequal modify.encoding 'EUC-JP' %} selected{% endifequal %}>EUC-JP</option><option{% ifequal modify.encoding 'ISO-2022-JP' %} selected{% endifequal %}>ISO-2022-JP</option></select></td></tr>
<tr><td>content:</td><td><textarea name="content" rows="15" cols="60">{% if modify %}{{ modify.textcontent|escape }}{% endif %}</textarea></td></tr>
<tr><td>text:</td><td><textarea name="content" rows="15" cols="60">{% if modify %}{{ modify.textcontent|escape }}{% endif %}</textarea></td></tr>
<tr><td>description:</td><td><input type="text" name="description"{% if modify %} value="{{ modify.description|escape }}"{% endif %}></td></tr>
<tr><td colspan="2"><input type="submit" value="{% if modify %}modify{% else %}add{% endif %}" onclick="return inputcheck(document.editcontent);"></td></tr>
</table>
Expand All @@ -208,7 +214,7 @@ <h2>Upload file</h2>
<tr><td>name:</td><td><input type="text" name="name"{% if modify %} value="{{ modify.name|escape }}"{% endif %}></td></tr>
{% if modify %}<tr><td>old path:</td><td><input type="text" name="oldpath" value="{{ modify.path|escape }}" readonly></td></tr>{% endif %}
<tr><td>{% if modify %}new {% endif %}path:</td><td><input type="text" name="path"{% if modify %} value="{{ modify.path|escape }}"{% endif %}></td></tr>
<tr><td>public:</td><td><input type="checkbox" name="public"{% if modify and modify.public %} checked{% endif %}></td></tr>
<tr><td>public:</td><td><input type="checkbox" name="public"{% if modify %}{% if modify.public %} checked{% endif %}{% else %} checked{% endif %}></td></tr>
<tr><td>file:</td><td><input type="file" name="file"></td></tr>
<tr><td>description:</td><td><input type="text" name="description"{% if modify %} value="{{ modify.description|escape }}"{% endif %}></td></tr>
<tr><td colspan="2"><input type="submit" value="upload" onclick="return inputcheck(document.uploadfile);"></td></tr>
Expand All @@ -225,7 +231,7 @@ <h2>Edit alias</h2>
<tr><td>name:</td><td><input type="text" name="name"{% if modify %} value="{{ modify.name|escape }}"{% endif %}></td></tr>
{% if modify %}<tr><td>old path:</td><td><input type="text" name="oldpath" value="{{ modify.path|escape }}" readonly></td></tr>{% endif %}
<tr><td>{% if modify %}new {% endif %}path:</td><td><input type="text" name="path"{% if modify %} value="{{ modify.path|escape }}"{% endif %}></td></tr>
<tr><td>public:</td><td><input type="checkbox" name="public"{% if modify and modify.public %} checked{% endif %}></td></tr>
<tr><td>public:</td><td><input type="checkbox" name="public"{% if modify %}{% if modify.public %} checked{% endif %}{% else %} checked{% endif %}></td></tr>
<tr><td>target path:</td><td><input type="text" name="aliastarget"{% if modify %} value="{{ modify.aliastarget|escape }}"{% endif %}></td></tr>
<tr><td>description:</td><td><input type="text" name="description"{% if modify %} value="{{ modify.description|escape }}"{% endif %}></td></tr>
<tr><td colspan="2"><input type="submit" value="{% if modify %}modify{% else %}add{% endif %}" onclick="return inputcheck(document.editalias);"></td></tr>
Expand Down

0 comments on commit 7a39aa5

Please sign in to comment.