forked from Quasimo/FotoRatan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
methods.py
61 lines (52 loc) · 1.67 KB
/
methods.py
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
#coding:utf-8
from models import Images
from google.appengine.api import memcache
from google.appengine.api import images
from getimageinfo import getImageInfo
def addImage(mime,description,bf,name):
'Add Image'
image=Images(mime=mime,description=description,bf=bf,name=name)
image.size=len(image.bf)
image.filetype,image.width,image.height=getImageInfo(bf)
image.put()
return image
def addImage2(bf):
image=Images(bf=bf)
image.size=len(bf)
image.filetype,image.width,image.height=getImageInfo(bf)
if not image.filetype:return None
image.mime=image.filetype
image.put()
return image
def getImage(id):
id=int(id)
return Images.get_by_id(id)
def resizeImage(id,size="image"):
image=getImage(id)
if not image:return None
if size=="image":return image
img=images.Image(image.bf)
img.resize(width=125, height=125)
img.im_feeling_lucky()
image.bf=img.execute_transforms(output_encoding=images.JPEG)
return image
def downImage(id,size="image"):
key=id+size
image=memcache.get(key)
if not image:
image=resizeImage(id, size)
memcache.set(key,image,3600*10)
return image
def delImage(key):
image=Images.get(key)
if image:image.delete()
def getAllImages(index=0):
return Images.all().order('-created_at').fetch(11,index*10)
def getPageing(index,page=0):
s="/%s/"
if page==0:
if index==11:return (None,"/1/")
else:return (None,None)
if index==11:
return ("/",s%(page+1)) if page==1 else (s %(page-1),s%(page+1))
return ("/",None) if page==1 else (s %(page-1),None)