Commits

ben  committed b86166e

保存网页图片到sa3album

  • Participants
  • Parent commits 4d545cd
  • Tags 0.2.5

Comments (0)

Files changed (5)

             img =Image.add(album,name,mime,bf)
             return self.response.out.write("{success:true}")
         return self.response.out.write("{success:false}")
+    
+class ImageWebUploadHandler(AdminHandler):
+    def get(self):
+        u = self.request.get("u")
+        if u :
+            self.template_value['albums'] = Album.all()
+            self.template_value['u']=u
+            return self.render("upload-web2.html")
+        self.render("upload-web.html")
+        
+    def post(self):
+        album = self.request.get("album")
+        u = self.request.get("u")
+        des = self.request.get("des")
+       
+        result = urlfetch.fetch(u)
+        if result.status_code == 200:
+            album = Album.get_by_key_name(album)
+            bf = result.content
+            mime = getImageInfo(bf)[0]
+            if mime.find("image") <0:
+                raise Exception(u"不是正确的图片")
+            name = u.split("/")[-1] or "aaaa"+ mime.split("/")[-1]
+            img = Image.add(album,name,mime,bf,**{"description":des})
+            self.redirect(album.m_url)
         
 class ImageDelHandler(AdminHandler):
     def get(self):
                                         ('/a/upload/common/',CommonImageUploadHandler),
                                         ('/a/upload/',ImageUploadHandler),
                                         ('/a/upload5/',ImageHtml5UploadHandler),
+                                        ('/a/g/',ImageWebUploadHandler),
                                         ('/a/img/del/',ImageDelHandler),
                                         ('/a/img/updatedes/',ImageUpdateDesHandler),
                                         ('/a/settings/',SystemSettingsHandler),

File themes/admin/upload-web.html

+{% extends "base.html" %}
+{%block title %}Web地址上传图片 {% endblock %}
+{% block content %}
+<form method="get" action="/a/g/" class="f">
+<fieldset>
+    <p>
+        <input  name="u" type="text" style="width:400px;" maxlength="100" value="">
+        <label for="name">地址</label>
+    </p>
+    <p>
+        <input type="submit" value="保存">
+    </p>
+</fieldset>
+</form>
+{% endblock %}

File themes/admin/upload-web2.html

+{% extends "base.html" %}
+{%block title %}Web地址上传图片 {% endblock %}
+{% block content %}
+<form method="post" action="/a/g/" class="f">
+<fieldset>
+	<p>
+		{{error}}
+	</p>
+    <p>
+    <select name="album" id="album-select">
+        {% for album in albums %}
+        <option value="{{album.slug}}" {% ifequal album.slug album-select%} selected="selected" {% endifequal %}>{{album.name}}({{album.count}})</option>
+        {% endfor %}
+    </select>
+	 <label for="album">选择相册</label>
+    </p>
+	<p>
+		<input  name="u" type="text" style="width:400px;" maxlength="100" value="{{u}}">
+    <p>
+        <p><textarea id="des" name="des" style="width:400px"></textarea></p>
+    </p>
+    <p>
+        <input type="submit" value="保存">
+    </p>
+</fieldset>
+</form>
+{% endblock %}

File themes/admin/upload.html

     </select>
     <a href="/a/album/add/">新建相册</a>
 	<a href="/a/upload5/">尝试html5上传</a>
+	<a href="/a/g/">URL上传</a>
 <p>
 	<input id="fileinput" name="fileinput" type="file" />
     <input id="skey" name="skey" value="{{settings.skey}}" type="hidden">

File themes/gallery/album.html

     <ul class="thumbs noscript">
     	{% for img in imgs %}
         <li>
-            <a class="thumb" name="leaf" href="{{img.f}}" title="{{img.des}}" >
-                <img src="{{img.s}}" alt="{{img.des}}" />
+            <a class="thumb" name="leaf" href="{{img.f}}?w=500" title="{{img.des}}" >
+                <img src="{{img.f}}?w=75&h=75" alt="{{img.des}}" />
             </a>
             <div class="caption">
                 <div class="download">