本文整理汇总了Python中models.Image.user方法的典型用法代码示例。如果您正苦于以下问题:Python Image.user方法的具体用法?Python Image.user怎么用?Python Image.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Image
的用法示例。
在下文中一共展示了Image.user方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handleImagePopAdd
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import user [as 别名]
def handleImagePopAdd(request, addForm, field, template="form/popmediaadd.html"):
if not request.method == "POST":
f = UploadForm()
ctx = {'form': f, 'field': field}
return render(request, template, ctx)
f = UploadForm(request.POST, request.FILES)
if not f.is_valid() and not request.FILES['file'].name.endswith('.svg'):
ctx = {'form': f, 'field': field}
return render(request, template, ctx)
file = request.FILES['file']
store_in_s3(file.name, file.read())
p = Image(url="http://%s.s3.amazonaws.com/%s" % (bucket, file.name))
if isinstance(request.user, AnonymousUser):
p.user = User.objects.get(username="Anonymous")
else:
p.user = User.objects.get(username=request.user)
if request.POST['artist']:
p.artist = User.objects.get(pk=request.POST['artist'])
p.save()
newObject = p
# Self destruction:
if newObject:
return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script>' %\
(escape(newObject._get_pk_val()), escape(newObject)))
示例2: receive
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import user [as 别名]
def receive():
data = request.data
data = xmltodict.parse(data)['xml']
if data['MsgType'] == 'text':
return send_text(data['FromUserName'], 'hi')
if data['MsgType'] == 'image':
token = current_access_token()
file_url = 'https://api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s' % (token, data['MediaId'])
file = requests.get(file_url, stream=True).raw
i = Image()
i.image = file
uuid = shortuuid.ShortUUID().random(length=6)
while Image.objects(iid=uuid):
uuid = shortuuid.ShortUUID().random(length=6)
i.iid = uuid
i.title = data['MediaId']
i.user = system_user
i.description = ''
i.tags = []
i.save()
return send_text(
data['FromUserName'], '업로드 성공, 사진주소:%s%s' % (
request.url_root[:-1], url_for('light-cms.image', iid=i.iid)
)
)
示例3: post
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import user [as 别名]
def post(self):
"Upload via a multitype POST message"
img = self.request.get("img")
# if we don't have image data we'll quit now
if not img:
self.redirect("/")
return
try:
width = int(self.request.get("width"))
hight = int(self.request.get("height"))
except ValueError:
image_content = img
else:
image_content = images.resize(img, width, height)
original_content = img
thumb_content = images.resize(img, 100, 100)
image = Image()
image.image = db.Blob(image_content)
image.original = db.Blob(original_content)
image.thumb = db.Blob(thumb_content)
image.user = users.get_current_user()
image.put()
self.redirect("/")
示例4: drop
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import user [as 别名]
def drop():
file = request.files['file']
i = Image()
i.title = file.filename
i.image = file
uuid = shortuuid.ShortUUID().random(length=6)
while Image.objects(iid=uuid):
uuid = shortuuid.ShortUUID().random(length=6)
i.iid = uuid
if login.current_user.is_active():
i.user = login.current_user._get_current_object()
else:
i.user = system_user
i.description = ''
i.tags = []
i.save()
return jsonify(id=uuid)
示例5: post
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import user [as 别名]
def post(self):
"Upload via a multitype POST message"
if self.request.get('img'):
try:
# check we have numerical width and height values
width = int(self.request.get("width"))
height = int(self.request.get("height"))
except ValueError:
# if we don't have valid width and height values
# then just use the original image
image_content = google.appengine.api.images.resize(self.request.get("img"),
IMAGE_WIDTH, IMAGE_HEIGHT)
thumb_content = google.appengine.api.images.resize(self.request.get("img"), 100, 100)
else:
# if we have valid width and height values
# then resize according to those values
image_content = google.appengine.api.images.resize(self.request.get("img"), width, height)
# always generate a thumbnail for use on the admin page
thumb_content = google.appengine.api.images.resize(self.request.get("img"), 100, 100)
else:
image_content = None
if not self.request.get('key'):
logging.critical('No key and no image! Cannot save image.')
return self.redirect('/admin')
# check if image is being edited
if self.request.get('key'):
image = db.get(self.request.get("key"))
if self.request.get('position'):
import datetime
position = int(self.request.get('position'))
images = imageQuery().fetch(100)
offset_image = images.pop(position- 1)
if position == 1:
time_offset = -datetime.timedelta(milliseconds=10)
else:
time_offset = datetime.timedelta(milliseconds=10)
if not offset_image.key() == image.key():
image.date = offset_image.date + time_offset
else:
# create the image object
image = Image()
image.user = users.get_current_user()
image.title = self.request.get('title')
if image_content:
# and set the properties to the relevant values
image.image = db.Blob(image_content)
# we always store the original here in case of errors
# although it's currently not exposed via the frontend
image.thumb = db.Blob(thumb_content)
# store the image in the datasore
image.put()
# and redirect back to the admin page
self.redirect('/admin')
示例6: index
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import user [as 别名]
def index(request, template='./gallery/index.html'):
entry = get("Gallery")
if 'gallery' in request.POST and request.POST['gallery']:
artist = User.objects.get(pk=request.POST['gallery'])
photos = Image.objects.filter(artist=artist).order_by('-uploaded')
else:
photos = Image.objects.all().order_by('-uploaded')
if not request.method == "POST" or ('gallery' in request.POST):
f = UploadForm()
af = ArtistForm(request.POST)
ctx = {'entry': entry, 'form': f, 'photos': photos, 'artist': af}
return render(request, template, ctx)
f = UploadForm(request.POST, request.FILES)
af = ArtistForm(request.POST)
if not f.is_valid() and not request.FILES['file'].name.endswith('.svg'):
ctx = {'entry': entry, 'form': f, 'photos': photos, 'artist': af}
return render(request, template, ctx)
file = request.FILES['file']
#print type(file)
#print dir(file)
#for k,v in file.items(): print k, v
#filename = file._get_name() #['filename']
#content = file['content']
store_in_s3(file.name, file.read())
p = Image(url="http://%s.s3.amazonaws.com/%s" % (bucket, file.name))
if isinstance(request.user, AnonymousUser):
p.user = User.objects.get(username="Anonymous")
else:
p.user = User.objects.get(username=request.user)
if request.POST['artist']:
p.artist = User.objects.get(pk=request.POST['artist'])
p.save()
photos = Image.objects.all().order_by('-uploaded')
ctx = {'entry': entry, 'form': f, 'photos': photos, 'artist': af}
return render(request, template, ctx)
示例7: post
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import user [as 别名]
def post(self):
"Upload via a multitype POST message"
try:
# check we have numerical width and height values
width = int(self.request.get("width"))
height = int(self.request.get("height"))
except ValueError:
# if we don't have valid width and height values
# then just use the original image
image_content = self.request.get("img")
else:
# if we have valid width and height values
# then resize according to those values
image_content = images.resize(self.request.get("img"), width, height)
# get the image data from the form
original_content = self.request.get("img")
# always generate a thumbnail for use on the admin page
thumb_content = images.resize(self.request.get("img"), 100, 100)
# create the image object
image = Image()
# Try and create an s3 connection
if len(awskeys.AWS_ACCESS_KEY_ID) > 0 and len(awskeys.AWS_SECRET_ACCESS_KEY) > 0:
s3 = GoogleS3.AWSAuthConnection(awskeys.AWS_ACCESS_KEY_ID, awskeys.AWS_SECRET_ACCESS_KEY)
else:
s3 = None
# and set the properties to the relevant values
image.image = db.Blob(image_content)
image.user = users.get_current_user()
if s3 is None:
# we always store the original here in case of errors
# although it's currently not exposed via the frontend
image.original = db.Blob(original_content)
image.thumb = db.Blob(thumb_content)
# store the image in the datasore
image.put()
else:
# we want to store in S3, so store the data and use the key
image.put()
# Put the 3 different images
s3.put(awskeys.BUCKET_NAME,str(image.key()) + "_original",original_content)
s3.put(awskeys.BUCKET_NAME,str(image.key()) + "_thumb",thumb_content)
s3.put(awskeys.BUCKET_NAME,str(image.key()) + "_image",image_content)
# and redirect back to the admin page
self.redirect('/')
示例8: post
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import user [as 别名]
def post(self):
"Upload via a multitype POST message"
img = self.request.get("img")
# if we don't have image data we'll quit now
if not img:
self.redirect('/')
return
# we have image data
try:
# check we have numerical width and height values
width = int(self.request.get("width"))
height = int(self.request.get("height"))
except ValueError:
# if we don't have valid width and height values
# then just use the original image
image_content = img
else:
# if we have valid width and height values
# then resize according to those values
image_content = images.resize(img, width, height)
# get the image data from the form
original_content = img
# always generate a thumbnail for use on the admin page
thumb_content = images.resize(img, 100, 100)
# create the image object
image = Image()
# and set the properties to the relevant values
image.image = db.Blob(image_content)
# we always store the original here in case of errors
# although it's currently not exposed via the frontend
image.original = db.Blob(original_content)
image.thumb = db.Blob(thumb_content)
image.user = users.get_current_user()
# store the image in the datasore
image.put()
# and redirect back to the admin page
self.redirect('/')
示例9: gallery_drop
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import user [as 别名]
def gallery_drop(gid):
if not login.current_user.is_active():
flash('앨범기능엔 로그인이 필요합니다')
return redirect(url_for('light-cms.user_login'))
g = Gallery.objects.get_or_404(gid=gid)
file = request.files['file']
i = Image()
i.gallery.append(g)
i.title = file.filename
i.image = file
uuid = shortuuid.ShortUUID().random(length=6)
while Image.objects(iid=uuid):
uuid = shortuuid.ShortUUID().random(length=6)
i.iid = uuid
i.user = login.current_user._get_current_object()
i.description = ''
i.tags = []
i.save()
return jsonify(id=uuid)
示例10: post
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import user [as 别名]
def post(self, key):
checkkey = UploadRequestKeys.get(key)
if not checkkey:
self.error(404)
if checkkey.expire_date < datetime.now():
self.error(404)
img = self.request.get("img")
# if we don't have image data we'll quit now
if not img:
return None
try:
width = int(self.request.get("width"))
hight = int(self.request.get("height"))
except ValueError:
image_content = img
else:
image_content = images.resize(img, width, height)
original_content = img
thumb_content = images.resize(img, 100, 100)
image = Image()
image.image = db.Blob(image_content)
image.original = db.Blob(original_content)
image.thumb = db.Blob(thumb_content)
image.user = users.get_current_user()
image.realm = RealmKeys.get(checkkey.realm_key)
image.put()
checkkey.delete()
# self.response.out.write(simplejson.dumps({'img_url'::}))
context = {
"image": True,
"img_url": "http://org-images.appspot.com/i/img?id=%s" % image.key(),
"thumb_url": "http://org-images.appspot.com/i/thumb?id=%s" % image.key(),
}
path = os.path.join(os.path.dirname(__file__), "templates", "show_links.html")
# render the template with the provided context
self.response.out.write(template.render(path, context))
示例11: upload_image
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import user [as 别名]
def upload_image(request):
"""
Handles image uploads and assigns them to the correct user. Resizes the image before uploading.
The uploaded image's URL is in the HTTP header (Location)
"""
if request.method == 'POST':
form = ImageUploadForm(request.POST, request.FILES)
if form.is_valid():
img = Image()
img.user = request.user
img.note_id = form.cleaned_data['note']
img.image = form.cleaned_data['image']
img.save()
# Build a response
response = HttpResponse(status=201)
response['Location'] = img.image.url.replace(settings.AWS_MEDIA_URL,settings.MEDIA_URL,1)
return response
else:
return HttpResponse(status=400)
return HttpResponseForbidden()